aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2018-12-17 12:01:56 -0500
committerDavid Chase <drchase@google.com>2018-12-17 22:49:21 +0000
commitd924c3336c39a256c832512ecd24fcdeed0ca266 (patch)
tree432d7f926fbba49b577a881e3b8b03e52f526038
parent213845f7b932c72c5e49445224166d0ae14dfac9 (diff)
downloadgo-d924c3336c39a256c832512ecd24fcdeed0ca266.tar.gz
go-d924c3336c39a256c832512ecd24fcdeed0ca266.zip
cmd/compile: prevent double-walk of switch for OPRINT/OPRINTN
When a println arg contains a call to an inlineable function that itself contains a switch, that switch statement will be walked twice, once by the walkexprlist formerly in the OPRINT/OPRINTN case, then by walkexprlistcheap in walkprint. Remove the first walkexprlist, it is not necessary. walkexprlist = s[i] = walkexpr(s[i], init) walkexprlistcheap = { s[i] = cheapexpr(n, init) s[i] = walkexpr(s[i], init) } Seems like this might be possible in other places, i.e., calls to inlineable switch-containing functions. See also #25776. Fixes #29220. Change-Id: I3781e86aad6688711597b8bee9bc7ebd3af93601 Reviewed-on: https://go-review.googlesource.com/c/154497 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
-rw-r--r--src/cmd/compile/internal/gc/walk.go1
-rw-r--r--test/fixedbugs/issue29220.go26
2 files changed, 26 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go
index b84bc26e04..f23a591647 100644
--- a/src/cmd/compile/internal/gc/walk.go
+++ b/src/cmd/compile/internal/gc/walk.go
@@ -563,7 +563,6 @@ opswitch:
n = walkinrange(n, init)
case OPRINT, OPRINTN:
- walkexprlist(n.List.Slice(), init)
n = walkprint(n, init)
case OPANIC:
diff --git a/test/fixedbugs/issue29220.go b/test/fixedbugs/issue29220.go
new file mode 100644
index 0000000000..bbfe930786
--- /dev/null
+++ b/test/fixedbugs/issue29220.go
@@ -0,0 +1,26 @@
+// compile
+
+// Copyright 2018 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.
+
+package main
+
+func ascii(r rune) rune {
+ switch {
+ case 97 <= r && r <= 122:
+ return r - 32
+ case 65 <= r && r <= 90:
+ return r + 32
+ default:
+ return r
+ }
+}
+
+func main() {
+ nomeObjeto := "ABE1FK21"
+ println(string(nomeObjeto[1:4]))
+ println(ascii(rune(nomeObjeto[4])) >= 48 && ascii(rune(nomeObjeto[4])) <= 57)
+ println(string(nomeObjeto[5]))
+ println(string(nomeObjeto[6:10]))
+}