mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/compile: fix open defer of method call
Code generation for open defers failed to account for presence of method receiver and thus was OFF BY ONE. Fixes #45062. Updates #44816. Updates #40724. Change-Id: Ia90ea8fd0f7d823e1f757c406f9127136c2ffdd2 Reviewed-on: https://go-review.googlesource.com/c/go/+/302249 Trust: David Chase <drchase@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
0ec2c4abba
commit
d206ca5cac
@ -353,10 +353,12 @@ func (s *state) emitOpenDeferInfo() {
|
|||||||
numArgs++
|
numArgs++
|
||||||
}
|
}
|
||||||
off = dvarint(x, off, int64(numArgs))
|
off = dvarint(x, off, int64(numArgs))
|
||||||
|
argAdjust := 0 // presence of receiver offsets the parameter count.
|
||||||
if r.rcvrNode != nil {
|
if r.rcvrNode != nil {
|
||||||
off = dvarint(x, off, -okOffset(r.rcvrNode.FrameOffset()))
|
off = dvarint(x, off, -okOffset(r.rcvrNode.FrameOffset()))
|
||||||
off = dvarint(x, off, s.config.PtrSize)
|
off = dvarint(x, off, s.config.PtrSize)
|
||||||
off = dvarint(x, off, 0) // This is okay because defer records use ABI0 (for now)
|
off = dvarint(x, off, 0) // This is okay because defer records use ABI0 (for now)
|
||||||
|
argAdjust++
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(register args) assume abi0 for this?
|
// TODO(register args) assume abi0 for this?
|
||||||
@ -366,7 +368,7 @@ func (s *state) emitOpenDeferInfo() {
|
|||||||
f := getParam(r.n, j)
|
f := getParam(r.n, j)
|
||||||
off = dvarint(x, off, -okOffset(arg.FrameOffset()))
|
off = dvarint(x, off, -okOffset(arg.FrameOffset()))
|
||||||
off = dvarint(x, off, f.Type.Size())
|
off = dvarint(x, off, f.Type.Size())
|
||||||
off = dvarint(x, off, okOffset(pri.InParam(j).FrameOffset(pri))-ab.LocalsOffset()) // defer does not want the fixed frame adjustment
|
off = dvarint(x, off, okOffset(pri.InParam(j+argAdjust).FrameOffset(pri))-ab.LocalsOffset()) // defer does not want the fixed frame adjustment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4925,7 +4927,7 @@ func (s *state) call(n *ir.CallExpr, k callKind, returnResultAddr bool) *ssa.Val
|
|||||||
callABI = s.f.ABI0
|
callABI = s.f.ABI0
|
||||||
}
|
}
|
||||||
|
|
||||||
params := callABI.ABIAnalyze(n.X.Type(), false /* Do not set (register) nNames from caller side -- can cause races. */ )
|
params := callABI.ABIAnalyze(n.X.Type(), false /* Do not set (register) nNames from caller side -- can cause races. */)
|
||||||
types.CalcSize(fn.Type())
|
types.CalcSize(fn.Type())
|
||||||
stksize := params.ArgWidth() // includes receiver, args, and results
|
stksize := params.ArgWidth() // includes receiver, args, and results
|
||||||
|
|
||||||
|
36
test/abi/open_defer_1.go
Normal file
36
test/abi/open_defer_1.go
Normal file
@ -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.
|
||||||
|
|
||||||
|
// For #45062, miscompilation of open defer of method invocation
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var x, y, z int = -1, -2, -3
|
||||||
|
F(x, y, z)
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:noinline
|
||||||
|
func F(x, y, z int) {
|
||||||
|
defer i.M(x, y, z)
|
||||||
|
defer func() { recover() }()
|
||||||
|
panic("XXX")
|
||||||
|
}
|
||||||
|
|
||||||
|
type T int
|
||||||
|
|
||||||
|
func (t *T) M(x, y, z int) {
|
||||||
|
if x == -1 && y == -2 && z == -3 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println("FAIL: Expected -1, -2, -3, but x, y, z =", x, y, z)
|
||||||
|
}
|
||||||
|
|
||||||
|
var t T = 42
|
||||||
|
|
||||||
|
type I interface{ M(x, y, z int) }
|
||||||
|
|
||||||
|
var i I = &t
|
Loading…
x
Reference in New Issue
Block a user