sizes.go (go1.19.src) | : | sizes.go (go1.19.1.src) | ||
---|---|---|---|---|
skipping to change at line 28 | skipping to change at line 28 | |||
func (s *gcSizes) Alignof(T types2.Type) int64 { | func (s *gcSizes) Alignof(T types2.Type) int64 { | |||
// For arrays and structs, alignment is defined in terms | // For arrays and structs, alignment is defined in terms | |||
// of alignment of the elements and fields, respectively. | // of alignment of the elements and fields, respectively. | |||
switch t := T.Underlying().(type) { | switch t := T.Underlying().(type) { | |||
case *types2.Array: | case *types2.Array: | |||
// spec: "For a variable x of array type: unsafe.Alignof(x) | // spec: "For a variable x of array type: unsafe.Alignof(x) | |||
// is the same as unsafe.Alignof(x[0]), but at least 1." | // is the same as unsafe.Alignof(x[0]), but at least 1." | |||
return s.Alignof(t.Elem()) | return s.Alignof(t.Elem()) | |||
case *types2.Struct: | case *types2.Struct: | |||
if t.NumFields() == 0 && types2.IsSyncAtomicAlign64(T) { | ||||
// Special case: sync/atomic.align64 is an | ||||
// empty struct we recognize as a signal that | ||||
// the struct it contains must be | ||||
// 64-bit-aligned. | ||||
// | ||||
// This logic is equivalent to the logic in | ||||
// cmd/compile/internal/types/size.go:calcStructOffset | ||||
return 8 | ||||
} | ||||
// spec: "For a variable x of struct type: unsafe.Alignof(x) | // spec: "For a variable x of struct type: unsafe.Alignof(x) | |||
// is the largest of the values unsafe.Alignof(x.f) for each | // is the largest of the values unsafe.Alignof(x.f) for each | |||
// field f of x, but at least 1." | // field f of x, but at least 1." | |||
max := int64(1) | max := int64(1) | |||
for i, nf := 0, t.NumFields(); i < nf; i++ { | for i, nf := 0, t.NumFields(); i < nf; i++ { | |||
if a := s.Alignof(t.Field(i).Type()); a > max { | if a := s.Alignof(t.Field(i).Type()); a > max { | |||
max = a | max = a | |||
} | } | |||
} | } | |||
return max | return max | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 11 lines changed or added |