aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2013-07-26 10:04:32 +1000
committerRuss Cox <rsc@golang.org>2013-07-26 10:04:32 +1000
commit89020aa72cbdff82ab35af759246c85c26462dfe (patch)
tree239d1ce754401f9ed54b12c6817dc6ce5d298363
parentb5245b9c77d5320afd4ab22194c577a8e02b5fc4 (diff)
downloadgo-89020aa72cbdff82ab35af759246c85c26462dfe.tar.gz
go-89020aa72cbdff82ab35af759246c85c26462dfe.zip
[release-branch.go1.1] cmd/gc: avoid passing unevaluated constant expressions to backends.
««« CL 11107044 / 5baf6060648e cmd/gc: avoid passing unevaluated constant expressions to backends. Backends do not exactly expect receiving binary operators with constant operands or use workarounds to move them to register/stack in order to handle them. Fixes #5841. R=golang-dev, daniel.morsing, rsc CC=golang-dev https://golang.org/cl/11107044 »»» Update #5928 R=golang-dev, dave CC=golang-dev https://golang.org/cl/11879044
-rw-r--r--src/cmd/gc/walk.c7
-rw-r--r--test/fixedbugs/issue5841.go16
2 files changed, 23 insertions, 0 deletions
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c
index d9c6341b43..e8ebd28924 100644
--- a/src/cmd/gc/walk.c
+++ b/src/cmd/gc/walk.c
@@ -1338,6 +1338,13 @@ walkexpr(Node **np, NodeList **init)
fatal("missing switch %O", n->op);
ret:
+ // Expressions that are constant at run time but not
+ // considered const by the language spec are not turned into
+ // constants until walk. For example, if n is y%1 == 0, the
+ // walk of y%1 may have replaced it by 0.
+ // Check whether n with its updated args is itself now a constant.
+ evconst(n);
+
ullmancalc(n);
if(debug['w'] && n != N)
diff --git a/test/fixedbugs/issue5841.go b/test/fixedbugs/issue5841.go
new file mode 100644
index 0000000000..cfc4a504c5
--- /dev/null
+++ b/test/fixedbugs/issue5841.go
@@ -0,0 +1,16 @@
+// build
+
+// Copyright 2013 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.
+
+// Issue 5841: 8g produces invalid CMPL $0, $0.
+// Similar to issue 5002, used to fail at link time.
+
+package main
+
+func main() {
+ var y int
+ if y%1 == 0 {
+ }
+}