Commit 6f83b75b authored by Alessandro Arzilli's avatar Alessandro Arzilli Committed by Matthew Dempsky

cmd/compile: fix lexical scope of escaped variables

When a local variable is moved to the heap the declaration position
should be preserved so that later on we can assign it to the correct
DW_TAG_lexical_block.

Fixes #20959

Change-Id: I3700ef53c68ccd506d0633f11374ad88a52b2898
Reviewed-on: https://go-review.googlesource.com/47852
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarDavid Chase <drchase@google.com>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent 123fd464
......@@ -2100,6 +2100,7 @@ func moveToHeap(n *Node) {
heapaddr := temp(types.NewPtr(n.Type))
heapaddr.Sym = lookup("&" + n.Sym.Name)
heapaddr.Orig.Sym = heapaddr.Sym
heapaddr.Pos = n.Pos
// Unset AutoTemp to persist the &foo variable name through SSA to
// liveness analysis.
......
......@@ -49,6 +49,7 @@ var testfile = []testline{
{line: "func f4(x int) { }"},
{line: "func f5(x int) { }"},
{line: "func f6(x int) { }"},
{line: "func fi(x interface{}) { if a, ok := x.(error); ok { a.Error() } }"},
{line: "func gret1() int { return 2 }"},
{line: "func gretbool() bool { return true }"},
{line: "func gret3() (int, int, int) { return 0, 1, 2 }"},
......@@ -163,6 +164,15 @@ var testfile = []testline{
{line: " }"},
{line: " f(3); f1(b)"},
{line: "}"},
{line: "func TestEscape() {"},
{line: " a := 1", vars: []string{"var a int"}},
{line: " {"},
{line: " b := 2", scopes: []int{1}, vars: []string{"var &b *int", "var p *int"}},
{line: " p := &b", scopes: []int{1}},
{line: " f1(a)", scopes: []int{1}},
{line: " fi(p)", scopes: []int{1}},
{line: " }"},
{line: "}"},
{line: "func main() {"},
{line: " TestNestedFor()"},
{line: " TestOas2()"},
......@@ -173,6 +183,7 @@ var testfile = []testline{
{line: " TestBlock()"},
{line: " TestDiscontiguousRanges()"},
{line: " TestClosureScope()"},
{line: " TestEscape()"},
{line: "}"},
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment