]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: set correct Defn for inlined vars
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 22 Apr 2021 10:14:10 +0000 (17:14 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 23 Apr 2021 05:10:41 +0000 (05:10 +0000)
commitd310b2a6b8a66eeb5953b1e682cf27669c8a08c2
tree6556c0a96372c32b7a6d25fab3b1705412fe74f2
parent1b0a0316802b8048d69da49dc23c5a5ab08e8ae8
cmd/compile: set correct Defn for inlined vars

Currently, when copying definition node of an inlined var, we do not
update var Defn field to point to new copied node. That causes all
inlined vars point to the same Defn, and ir.StaticValue can not find
inlined var in the lhs of its definition.

clovar creates new ONAME node for local variables or params of closure
inside inlined function, by copying most of the old node fields. So the
new Node.Defn is not modified, its lhs still refer to old node
instead of new one.

To fix this, we need to do two things:

 - In subst.clovar, set a dummy Defn node for inlvar
 - During subst.node, when seeing OAS/OAS2 nodes, after substituting, we
   check if any node in lhs has the dummy Defn, then set it to the current
   OAS/OAS2 node.

Fixes #45606

Change-Id: Ib517b753a7643756dcd61d36deae60f1a0fc53c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/312630
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/inline/inl.go
test/fixedbugs/issue45606.go [new file with mode: 0644]