sizes.go (go1.19.src) | : | sizes.go (go1.19.1.src) | ||
---|---|---|---|---|
skipping to change at line 56 | skipping to change at line 56 | |||
func (s *StdSizes) Alignof(T Type) int64 { | func (s *StdSizes) Alignof(T 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 := under(T).(type) { | switch t := under(T).(type) { | |||
case *Array: | case *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 *Struct: | case *Struct: | |||
if len(t.fields) == 0 && isSyncAtomicAlign64(T) { | if len(t.fields) == 0 && IsSyncAtomicAlign64(T) { | |||
// Special case: sync/atomic.align64 is an | // Special case: sync/atomic.align64 is an | |||
// empty struct we recognize as a signal that | // empty struct we recognize as a signal that | |||
// the struct it contains must be | // the struct it contains must be | |||
// 64-bit-aligned. | // 64-bit-aligned. | |||
// | // | |||
// This logic is equivalent to the logic in | // This logic is equivalent to the logic in | |||
// cmd/compile/internal/types/size.go:calcStructOffset | // cmd/compile/internal/types/size.go:calcStructOffset | |||
return 8 | return 8 | |||
} | } | |||
skipping to change at line 107 | skipping to change at line 107 | |||
// complex{64,128} are aligned like [2]float{32,64}. | // complex{64,128} are aligned like [2]float{32,64}. | |||
if isComplex(T) { | if isComplex(T) { | |||
a /= 2 | a /= 2 | |||
} | } | |||
if a > s.MaxAlign { | if a > s.MaxAlign { | |||
return s.MaxAlign | return s.MaxAlign | |||
} | } | |||
return a | return a | |||
} | } | |||
func isSyncAtomicAlign64(T Type) bool { | func IsSyncAtomicAlign64(T Type) bool { | |||
named, ok := T.(*Named) | named, ok := T.(*Named) | |||
if !ok { | if !ok { | |||
return false | return false | |||
} | } | |||
obj := named.Obj() | obj := named.Obj() | |||
return obj.Name() == "align64" && | return obj.Name() == "align64" && | |||
obj.Pkg() != nil && | obj.Pkg() != nil && | |||
(obj.Pkg().Path() == "sync/atomic" || | (obj.Pkg().Path() == "sync/atomic" || | |||
obj.Pkg().Path() == "runtime/internal/atomic") | obj.Pkg().Path() == "runtime/internal/atomic") | |||
} | } | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 2 lines changed or added |