summaryrefslogtreecommitdiff
path: root/test/live.go
diff options
context:
space:
mode:
authorMichael Munday <mike.munday@ibm.com>2017-03-29 14:01:41 -0400
committerMichael Munday <mike.munday@ibm.com>2017-08-24 16:53:56 +0000
commit744ebfde0460e1d8fff10672e4d1e8d9ece52556 (patch)
tree30f9eca8178f7ce2b7534ab394e0e1dac4e42e60 /test/live.go
parent18b48afec9be0a1da4b23bebace0dc9f081dcee1 (diff)
downloadgo-git-744ebfde0460e1d8fff10672e4d1e8d9ece52556.tar.gz
cmd/compile: eliminate stores to unread auto variables
This is a crude compiler pass to eliminate stores to auto variables that are only ever written to. Eliminates an unnecessary store to x from the following code: func f() int { var x := 1 return *(&x) } Fixes #19765. Change-Id: If2c63a8ae67b8c590b6e0cc98a9610939a3eeffa Reviewed-on: https://go-review.googlesource.com/38746 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/live.go')
-rw-r--r--test/live.go21
1 files changed, 7 insertions, 14 deletions
diff --git a/test/live.go b/test/live.go
index ef988a05e5..2eb442cd2f 100644
--- a/test/live.go
+++ b/test/live.go
@@ -239,15 +239,6 @@ func f14() {
func g14() string
-func f15() {
- var x string
- _ = &x
- x = g15() // ERROR "live at call to g15: x$"
- printstring(x) // ERROR "live at call to printstring: x$"
-}
-
-func g15() string
-
// Checking that various temporaries do not persist or cause
// ambiguously live values that must be zeroed.
// The exact temporary names are inconsequential but we are
@@ -384,10 +375,9 @@ func f25(b bool) {
return
}
var x string
- _ = &x
- x = g15() // ERROR "live at call to g15: x$"
- printstring(x) // ERROR "live at call to printstring: x$"
-} // ERROR "live at call to deferreturn: x$"
+ x = g14()
+ printstring(x)
+}
func g25()
@@ -641,6 +631,9 @@ type T40 struct {
m map[int]int
}
+//go:noescape
+func useT40(*T40)
+
func newT40() *T40 {
ret := T40{}
ret.m = make(map[int]int) // ERROR "live at call to makemap: &ret$"
@@ -658,7 +651,7 @@ func good40() {
ret.m = make(map[int]int) // ERROR "live at call to makemap: .autotmp_[0-9]+ ret$"
t := &ret
printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+ ret$"
- _ = t
+ useT40(t) // ERROR "live at call to useT40: .autotmp_[0-9]+ ret$"
}
func ddd1(x, y *int) { // ERROR "live at entry to ddd1: x y$"