]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: emit ODCL node for autotmp during RewriteNonNameCall
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 22 Dec 2022 20:37:43 +0000 (03:37 +0700)
committerGopher Robot <gobot@golang.org>
Fri, 31 Mar 2023 18:41:12 +0000 (18:41 +0000)
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>

src/cmd/compile/internal/typecheck/typecheck.go

index 29bc61db60b6c5994432da5ff5adf19992ac0543..e160265d494db2b82f403eb85d60c54116454305 100644 (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 {