src/cmd/compile/internal/liveness/plive.go | 6 +++--- src/cmd/compile/internal/typebits/typebits.go | 15 ++++++++++++--- test/fixedbugs/issue54991.go | 29 +++++++++++++++++++++++++++++ diff --git a/src/cmd/compile/internal/liveness/plive.go b/src/cmd/compile/internal/liveness/plive.go index 93f49fad454cb0c8107c964a7f4823e3a80ddfff..4e5a52ee547607d2679f63cf3b62c5233630153f 100644 --- a/src/cmd/compile/internal/liveness/plive.go +++ b/src/cmd/compile/internal/liveness/plive.go @@ -434,7 +434,7 @@ if !node.IsOutputParamInRegisters() { if node.FrameOffset() < 0 { lv.f.Fatalf("Node %v has frameoffset %d\n", node.Sym().Name, node.FrameOffset()) } - typebits.Set(node.Type(), node.FrameOffset(), args) + typebits.SetNoCheck(node.Type(), node.FrameOffset(), args) break } fallthrough // PPARAMOUT in registers acts memory-allocates like an AUTO @@ -1507,7 +1507,7 @@ nptr := int(abiInfo.ArgWidth() / int64(types.PtrSize)) bv := bitvec.New(int32(nptr) * 2) for _, p := range abiInfo.InParams() { - typebits.Set(p.Type, p.FrameOffset(abiInfo), bv) + typebits.SetNoCheck(p.Type, p.FrameOffset(abiInfo), bv) } nbitmap := 1 @@ -1522,7 +1522,7 @@ if fn.Type().NumResults() > 0 { for _, p := range abiInfo.OutParams() { if len(p.Registers) == 0 { - typebits.Set(p.Type, p.FrameOffset(abiInfo), bv) + typebits.SetNoCheck(p.Type, p.FrameOffset(abiInfo), bv) } } off = objw.BitVec(lsym, off, bv) diff --git a/src/cmd/compile/internal/typebits/typebits.go b/src/cmd/compile/internal/typebits/typebits.go index fddad6e7e84b8176fd3d2865433d53d0b95236b2..cd52830a49d03d7a1dca562c4f4143c3062fe8fa 100644 --- a/src/cmd/compile/internal/typebits/typebits.go +++ b/src/cmd/compile/internal/typebits/typebits.go @@ -14,7 +14,16 @@ // NOTE: The bitmap for a specific type t could be cached in t after // the first run and then simply copied into bv at the correct offset // on future calls with the same type t. func Set(t *types.Type, off int64, bv bitvec.BitVec) { - if uint8(t.Alignment()) > 0 && off&int64(uint8(t.Alignment())-1) != 0 { + set(t, off, bv, false) +} + +// SetNoCheck is like Set, but do not check for alignment. +func SetNoCheck(t *types.Type, off int64, bv bitvec.BitVec) { + set(t, off, bv, true) +} + +func set(t *types.Type, off int64, bv bitvec.BitVec, skip bool) { + if !skip && uint8(t.Alignment()) > 0 && off&int64(uint8(t.Alignment())-1) != 0 { base.Fatalf("typebits.Set: invalid initial alignment: type %v has alignment %d, but offset is %v", t, uint8(t.Alignment()), off) } if !t.HasPointers() { @@ -72,13 +81,13 @@ // Short-circuit for #20739. break } for i := int64(0); i < t.NumElem(); i++ { - Set(elt, off, bv) + set(elt, off, bv, skip) off += elt.Size() } case types.TSTRUCT: for _, f := range t.Fields().Slice() { - Set(f.Type, off+f.Offset, bv) + set(f.Type, off+f.Offset, bv, skip) } default: diff --git a/test/fixedbugs/issue54991.go b/test/fixedbugs/issue54991.go new file mode 100644 index 0000000000000000000000000000000000000000..9ab0f5d06cf653408384592d29f5bf867d0dc043 --- /dev/null +++ b/test/fixedbugs/issue54991.go @@ -0,0 +1,29 @@ +// compile + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import ( + "sync/atomic" +) + +type I interface { + M() +} + +type S struct{} + +func (*S) M() {} + +type T struct { + I + x atomic.Int64 +} + +func F() { + t := &T{I: &S{}} + t.M() +}