aboutsummaryrefslogtreecommitdiff
path: root/test/escape2.go
diff options
context:
space:
mode:
authorDaniel Morsing <daniel.morsing@gmail.com>2014-02-13 19:04:43 +0000
committerDaniel Morsing <daniel.morsing@gmail.com>2014-02-13 19:04:43 +0000
commite0a55a6c9826f3b0548a2d78be82931ad73ac218 (patch)
tree84883e7571cce48cdd45dd97d5e3488a2f0e8cde /test/escape2.go
parent7861cd6082993becfedeaab75567eaba0c9a03f8 (diff)
downloadgo-e0a55a6c9826f3b0548a2d78be82931ad73ac218.tar.gz
go-e0a55a6c9826f3b0548a2d78be82931ad73ac218.zip
cmd/gc: for loop init statement misanalyzed by escape analysis
Logically, the init statement is in the enclosing scopes loopdepth, not inside the for loop. Fixes #7313. LGTM=rsc R=golang-codereviews, gobot, rsc CC=golang-codereviews https://golang.org/cl/62430043
Diffstat (limited to 'test/escape2.go')
-rw-r--r--test/escape2.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/escape2.go b/test/escape2.go
index be89c2d840..73342fd2bc 100644
--- a/test/escape2.go
+++ b/test/escape2.go
@@ -1357,3 +1357,35 @@ func foo144() {
//go:noescape
func foo144b(*int)
+
+// issue 7313: for loop init should not be treated as "in loop"
+
+type List struct {
+ Next *List
+}
+
+func foo145(l List) { // ERROR "l does not escape"
+ var p *List
+ for p = &l; p.Next != nil; p = p.Next { // ERROR "&l does not escape"
+ }
+}
+
+func foo146(l List) { // ERROR "l does not escape"
+ var p *List
+ p = &l // ERROR "&l does not escape"
+ for ; p.Next != nil; p = p.Next {
+ }
+}
+
+func foo147(l List) { // ERROR "l does not escape"
+ var p *List
+ p = &l // ERROR "&l does not escape"
+ for p.Next != nil {
+ p = p.Next
+ }
+}
+
+func foo148(l List) { // ERROR " l does not escape"
+ for p := &l; p.Next != nil; p = p.Next { // ERROR "&l does not escape"
+ }
+}