1
0
mirror of https://github.com/golang/go synced 2024-09-29 04:14:27 -06:00

cmd/compile: emit ODCL node for autotmp during RewriteNonNameCall

For f()() call, the compiler rewrite it roughly to:

	autotmp := f()
	autotmp()

However, if f() were inlined, escape analysis will confuse about the
lifetime of autotmp, leading to bad escaping decision.

This CL fixes this issue by rewriting f()() to:

	var autotmp
	autotmp = f()
	autotmp()

This problem also happens with Unified IR, until CL 421821 land.

Fixes #57434

Change-Id: I159a7e4c93bbc172f0eae60e7d40fc64ba70b236
Reviewed-on: https://go-review.googlesource.com/c/go/+/459295
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Cuong Manh Le 2022-12-23 03:37:43 +07:00 committed by Gopher Robot
parent a7fd2fab0e
commit e539461e34

View File

@ -889,7 +889,7 @@ func RewriteNonNameCall(n *ir.CallExpr) {
tmp := Temp((*np).Type())
as := ir.NewAssignStmt(base.Pos, tmp, *np)
as.Def = true
as.PtrInit().Append(Stmt(ir.NewDecl(n.Pos(), ir.ODCL, tmp)))
*np = tmp
if static {