1
0
mirror of https://github.com/golang/go synced 2024-11-23 13:50:06 -07:00

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: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Alessandro Arzilli 2017-07-09 17:03:45 +02:00 committed by Matthew Dempsky
parent 123fd4640a
commit 6f83b75be2
2 changed files with 12 additions and 0 deletions

View File

@ -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.

View File

@ -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: "}"},
}