aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2017-11-29 15:55:40 -0500
committerCherry Zhang <cherryyz@google.com>2017-11-30 13:45:18 +0000
commitdbb1d198ab883e9b617ba9cdfb2059fc212f4762 (patch)
treed5dc9be39e7e2f18eda53658ae2cdadf4a27a5bc /src
parent8064f82a158e4416e9f32ed7017642ace4280b4f (diff)
downloadgo-dbb1d198ab883e9b617ba9cdfb2059fc212f4762.tar.xz
cmd/compile: fix loop depth of range expression in escape analysis
ORANGE node's Right node is the expression it is ranging over, which is evaluated before the loop. In the escape analysis, we should walk this node without loop depth incremented. Fixes #21709. Change-Id: Idc1e4c76e39afb5a344d85f6b497930a488ce5cf Reviewed-on: https://go-review.googlesource.com/80740 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/gc/esc.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go
index 7ef07961de..03c0adafd5 100644
--- a/src/cmd/compile/internal/gc/esc.go
+++ b/src/cmd/compile/internal/gc/esc.go
@@ -680,7 +680,18 @@ func (e *EscState) esc(n *Node, parent *Node) {
}
e.esc(n.Left, n)
+
+ if n.Op == ORANGE {
+ // ORANGE node's Right is evaluated before the loop
+ e.loopdepth--
+ }
+
e.esc(n.Right, n)
+
+ if n.Op == ORANGE {
+ e.loopdepth++
+ }
+
e.esclist(n.Nbody, n)
e.esclist(n.List, n)
e.esclist(n.Rlist, n)