diff --git a/src/cmd/compile/internal/ssa/expand_calls.go b/src/cmd/compile/internal/ssa/expand_calls.go index a5fe6f4d29..b6683d076d 100644 --- a/src/cmd/compile/internal/ssa/expand_calls.go +++ b/src/cmd/compile/internal/ssa/expand_calls.go @@ -941,6 +941,11 @@ func (x *expandState) storeArgOrLoad(pos src.XPos, b *Block, source, mem *Value, // stores (or later, register movement). Extra args for interface and closure calls are ignored, // but removed. func (x *expandState) rewriteArgs(v *Value, firstArg int) (*Value, []*Value) { + if x.debug { + x.indent(3) + defer x.indent(-3) + x.Printf("rewriteArgs(%s; %d)\n", v.LongString(), firstArg) + } // Thread the stores on the memory arg aux := v.Aux.(*AuxCall) pos := v.Pos.WithNotStmt() @@ -969,7 +974,7 @@ func (x *expandState) rewriteArgs(v *Value, firstArg int) (*Value, []*Value) { aOffset = aux.OffsetOfArg(auxI) } if x.debug { - x.Printf("storeArg %s, %v, %d\n", a.LongString(), aType, aOffset) + x.Printf("...storeArg %s, %v, %d\n", a.LongString(), aType, aOffset) } rc.init(aRegs, aux.abiInfo, result, x.sp) mem = x.storeArgOrLoad(pos, v.Block, a, mem, aType, aOffset, 0, rc) @@ -1056,6 +1061,7 @@ func expandCalls(f *Func) { } } if isBlockMultiValueExit(b) { + x.indent(3) // Very similar to code in rewriteArgs, but results instead of args. v := b.Controls[0] m0 := v.MemoryArg() @@ -1063,7 +1069,12 @@ func expandCalls(f *Func) { aux := f.OwnAux pos := v.Pos.WithNotStmt() allResults := []*Value{} + if x.debug { + x.Printf("multiValueExit rewriting %s\n", v.LongString()) + } + var oldArgs []*Value for j, a := range v.Args[:len(v.Args)-1] { + oldArgs = append(oldArgs, a) i := int64(j) auxType := aux.TypeOfResult(i) auxBase := b.NewValue2A(v.Pos, OpLocalAddr, types.NewPtr(auxType), aux.NameOfResult(i), x.sp, mem) @@ -1101,6 +1112,18 @@ func expandCalls(f *Func) { v.AddArg(mem) v.Type = types.NewResults(append(abi.RegisterTypes(aux.abiInfo.OutParams()), types.TypeMem)) b.SetControl(v) + for _, a := range oldArgs { + if a.Uses == 0 { + if x.debug { + x.Printf("...marking %v unused\n", a.LongString()) + } + a.reset(OpInvalid) + } + } + if x.debug { + x.Printf("...multiValueExit new result %s\n", v.LongString()) + } + x.indent(-3) } } diff --git a/test/abi/zombie_struct_select.go b/test/abi/zombie_struct_select.go new file mode 100644 index 0000000000..d0cab98182 --- /dev/null +++ b/test/abi/zombie_struct_select.go @@ -0,0 +1,36 @@ +// run + +// Copyright 2021 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 main + +type patchlist struct { + head, tail uint32 +} + +type frag struct { + i uint32 + out patchlist +} + +//go:noinline +//go:registerparams +func patch(l patchlist, i uint32) { +} + +//go:noinline +//go:registerparams +func badbad(f1, f2 frag) frag { + // concat of failure is failure + if f1.i == 0 || f2.i == 0 { // internal compiler error: 'badbad': incompatible OpArgIntReg [4]: v42 and v26 + return frag{} + } + patch(f1.out, f2.i) + return frag{f1.i, f2.out} +} + +func main() { + badbad(frag{i: 2}, frag{i: 3}) +}