From: Cuong Manh Le Date: Thu, 22 Dec 2022 20:37:43 +0000 (+0700) Subject: cmd/compile: emit ODCL node for autotmp during RewriteNonNameCall X-Git-Tag: go1.21rc1~1079 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e539461e34b1c5163220f9910b2c0360fb9f21e4;p=gostls13.git 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 Run-TryBot: Cuong Manh Le TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Auto-Submit: Cuong Manh Le --- diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index 29bc61db60..e160265d49 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -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 {