summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Symonds <dsymonds@golang.org>2014-06-03 11:30:20 +1000
committerDavid Symonds <dsymonds@golang.org>2014-06-03 11:30:20 +1000
commit837dce6cd14b9bda0efad2dbb7d80764b02d1fc2 (patch)
treea4e0731268a629b26d4f4693194455de148c2017
parent1d6c27231292f71231325557ab8d3dec71916c30 (diff)
downloadgo-837dce6cd14b9bda0efad2dbb7d80764b02d1fc2.tar.gz
[release-branch.go1.3] cmd/gc: fix liveness for address-taken variables in inlined functions
??? CL 96670046 / 1bec455e95f1 cmd/gc: fix liveness for address-taken variables in inlined functions The 'address taken' bit in a function variable was not propagating into the inlined copies, causing incorrect liveness information. LGTM=dsymonds, bradfitz R=golang-codereviews, bradfitz CC=dsymonds, golang-codereviews, iant, khr, r https://codereview.appspot.com/96670046 ??? TBR=adg R=adg CC=golang-codereviews https://codereview.appspot.com/103810046
-rw-r--r--src/cmd/gc/inl.c1
-rw-r--r--test/live.go32
-rw-r--r--test/live2.go39
3 files changed, 72 insertions, 0 deletions
diff --git a/src/cmd/gc/inl.c b/src/cmd/gc/inl.c
index 298a4c0d7..cf89b0090 100644
--- a/src/cmd/gc/inl.c
+++ b/src/cmd/gc/inl.c
@@ -802,6 +802,7 @@ inlvar(Node *var)
n->class = PAUTO;
n->used = 1;
n->curfn = curfn; // the calling function, not the called one
+ n->addrtaken = var->addrtaken;
// esc pass wont run if we're inlining into a iface wrapper
// luckily, we can steal the results from the target func
diff --git a/test/live.go b/test/live.go
index 286fcc306..b4cced47e 100644
--- a/test/live.go
+++ b/test/live.go
@@ -4,6 +4,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// liveness tests with inlining disabled.
+// see also live2.go.
+
package main
func f1() {
@@ -590,3 +593,32 @@ func f39c() (x [10]*int) {
println() // ERROR "live at call to printnl: x"
return
}
+
+// issue 8142: lost 'addrtaken' bit on inlined variables.
+// no inlining in this test, so just checking that non-inlined works.
+
+type T40 struct {
+ m map[int]int
+}
+
+func newT40() *T40 {
+ ret := T40{ // ERROR "live at call to makemap: &ret"
+ make(map[int]int),
+ }
+ return &ret
+}
+
+func bad40() {
+ t := newT40()
+ println()
+ _ = t
+}
+
+func good40() {
+ ret := T40{ // ERROR "live at call to makemap: ret"
+ make(map[int]int),
+ }
+ t := &ret
+ println() // ERROR "live at call to printnl: ret"
+ _ = t
+}
diff --git a/test/live2.go b/test/live2.go
new file mode 100644
index 000000000..1e3279402
--- /dev/null
+++ b/test/live2.go
@@ -0,0 +1,39 @@
+// errorcheck -0 -live
+
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// liveness tests with inlining ENABLED
+// see also live.go.
+
+package main
+
+// issue 8142: lost 'addrtaken' bit on inlined variables.
+// no inlining in this test, so just checking that non-inlined works.
+
+type T40 struct {
+ m map[int]int
+}
+
+func newT40() *T40 {
+ ret := T40{ // ERROR "live at call to makemap: &ret"
+ make(map[int]int),
+ }
+ return &ret
+}
+
+func bad40() {
+ t := newT40() // ERROR "live at call to makemap: ret"
+ println() // ERROR "live at call to printnl: ret"
+ _ = t
+}
+
+func good40() {
+ ret := T40{ // ERROR "live at call to makemap: ret"
+ make(map[int]int),
+ }
+ t := &ret
+ println() // ERROR "live at call to printnl: ret"
+ _ = t
+}