mirror of
https://github.com/golang/go.git
synced 2025-11-01 09:10:57 +00:00
cmd/compile: be sure to wrap defer/go calls with arguments
CL 298669 implemented wrapping for defer/go calls so the function being called with defer or go statement has no arguments. This simplifies the compiler and the runtime, especially with the new ABI. If the called function does not have any argument, we don't need to wrap. But the code missed the cases of method receiver, as well as some apparent argumentless builtin calls which may later be rewritten to having arguments (e.g. recover). This CL makes sure to wrap those cases. Also add a check to ensure that go and defer calls are indeed argumentless. Handle "defer recover()" specially, as recover() is lowered to runtime.gorecover(FP) where FP is the frame's FP. FP needs to be evaluated before wrapping. Updates #40724. Change-Id: I2758b6c69ab6aa02dd588441a457fe28ddd0d5a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/304771 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
bd6628e62d
commit
e27f3966bb
4 changed files with 40 additions and 15 deletions
|
|
@ -157,15 +157,7 @@ func walkExpr1(n ir.Node, init *ir.Nodes) ir.Node {
|
|||
return mkcall("gopanic", nil, init, n.X)
|
||||
|
||||
case ir.ORECOVER:
|
||||
n := n.(*ir.CallExpr)
|
||||
// Call gorecover with the FP of this frame.
|
||||
// FP is equal to caller's SP plus FixedFrameSize().
|
||||
var fp ir.Node = mkcall("getcallersp", types.Types[types.TUINTPTR], init)
|
||||
if off := base.Ctxt.FixedFrameSize(); off != 0 {
|
||||
fp = ir.NewBinaryExpr(fp.Pos(), ir.OADD, fp, ir.NewInt(off))
|
||||
}
|
||||
fp = ir.NewConvExpr(fp.Pos(), ir.OCONVNOP, types.NewPtr(types.Types[types.TINT32]), fp)
|
||||
return mkcall("gorecover", n.Type(), init, fp)
|
||||
return walkRecover(n.(*ir.CallExpr), init)
|
||||
|
||||
case ir.OCFUNC:
|
||||
return n
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue