summaryrefslogtreecommitdiff
path: root/test/escape2.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-02-13 19:59:09 -0500
committerRuss Cox <rsc@golang.org>2014-02-13 19:59:09 -0500
commite5d742fcadf9677a40336d6cecd3ff464a94730f (patch)
treee80d5a62d349f9a3d3ca6509dec8e45a260a4f7d /test/escape2.go
parente0bb5ba52cff479f70d4351d3fafa35e1655839b (diff)
downloadgo-git-e5d742fcadf9677a40336d6cecd3ff464a94730f.tar.gz
cmd/gc: relax address-of escape analysis
Make the loop nesting depth of &x depend on where x is declared, not on where the &x appears. The latter is only a conservative estimate of the former. Being more careful can avoid some variables escaping, and it is easier to reason about. It would have avoided issue 7313, although that was still a bug worth fixing. Not much effect in the tree: one variable in the whole tree is saved from a heap allocation (something in x509 parsing). LGTM=daniel.morsing R=daniel.morsing CC=golang-codereviews https://golang.org/cl/62380043
Diffstat (limited to 'test/escape2.go')
-rw-r--r--test/escape2.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/escape2.go b/test/escape2.go
index 73342fd2bc..047adf5149 100644
--- a/test/escape2.go
+++ b/test/escape2.go
@@ -1389,3 +1389,13 @@ func foo148(l List) { // ERROR " l does not escape"
for p := &l; p.Next != nil; p = p.Next { // ERROR "&l does not escape"
}
}
+
+// related: address of variable should have depth of variable, not of loop
+
+func foo149(l List) { // ERROR " l does not escape"
+ var p *List
+ for {
+ for p = &l; p.Next != nil; p = p.Next { // ERROR "&l does not escape"
+ }
+ }
+}