mirror of https://github.com/golang/go.git
cmd/compile: better documentation around checkwidth
Change-Id: I5c7ec9676b5573c883c196459acea85aa9ff8130 Reviewed-on: https://go-review.googlesource.com/c/146021 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
84b96c21bf
commit
fde4b9ed14
|
|
@ -208,7 +208,7 @@ func dowidth(t *types.Type) {
|
|||
}
|
||||
|
||||
t.Width = -2
|
||||
t.Align = 0
|
||||
t.Align = 0 // 0 means use t.Width, below
|
||||
|
||||
et := t.Etype
|
||||
switch et {
|
||||
|
|
@ -222,7 +222,7 @@ func dowidth(t *types.Type) {
|
|||
}
|
||||
}
|
||||
|
||||
w := int64(0)
|
||||
var w int64
|
||||
switch et {
|
||||
default:
|
||||
Fatalf("dowidth: unknown type: %v", t)
|
||||
|
|
@ -366,7 +366,7 @@ func dowidth(t *types.Type) {
|
|||
|
||||
t.Width = w
|
||||
if t.Align == 0 {
|
||||
if w > 8 || w&(w-1) != 0 || w == 0 {
|
||||
if w == 0 || w > 8 || w&(w-1) != 0 {
|
||||
Fatalf("invalid alignment for %v", t)
|
||||
}
|
||||
t.Align = uint8(w)
|
||||
|
|
@ -423,12 +423,11 @@ func checkwidth(t *types.Type) {
|
|||
return
|
||||
}
|
||||
|
||||
if t.Deferwidth() {
|
||||
return
|
||||
// if type has not yet been pushed on deferredTypeStack yet, do it now
|
||||
if !t.Deferwidth() {
|
||||
t.SetDeferwidth(true)
|
||||
deferredTypeStack = append(deferredTypeStack, t)
|
||||
}
|
||||
t.SetDeferwidth(true)
|
||||
|
||||
deferredTypeStack = append(deferredTypeStack, t)
|
||||
}
|
||||
|
||||
func defercheckwidth() {
|
||||
|
|
@ -443,6 +442,7 @@ func resumecheckwidth() {
|
|||
if defercalc == 0 {
|
||||
Fatalf("resumecheckwidth")
|
||||
}
|
||||
|
||||
for len(deferredTypeStack) > 0 {
|
||||
t := deferredTypeStack[len(deferredTypeStack)-1]
|
||||
deferredTypeStack = deferredTypeStack[:len(deferredTypeStack)-1]
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ type Type struct {
|
|||
Extra interface{}
|
||||
|
||||
// Width is the width of this Type in bytes.
|
||||
Width int64
|
||||
Width int64 // valid if Align > 0
|
||||
|
||||
methods Fields
|
||||
allMethods Fields
|
||||
|
|
@ -156,16 +156,16 @@ type Type struct {
|
|||
Vargen int32 // unique name for OTYPE/ONAME
|
||||
|
||||
Etype EType // kind of type
|
||||
Align uint8 // the required alignment of this type, in bytes
|
||||
Align uint8 // the required alignment of this type, in bytes (0 means Width and Align have not yet been computed)
|
||||
|
||||
flags bitset8
|
||||
}
|
||||
|
||||
const (
|
||||
typeNotInHeap = 1 << iota // type cannot be heap allocated
|
||||
typeBroke // broken type definition
|
||||
typeNoalg // suppress hash and eq algorithm generation
|
||||
typeDeferwidth
|
||||
typeNotInHeap = 1 << iota // type cannot be heap allocated
|
||||
typeBroke // broken type definition
|
||||
typeNoalg // suppress hash and eq algorithm generation
|
||||
typeDeferwidth // width computation has been deferred and type is on deferredTypeStack
|
||||
typeRecur
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue