aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2013-07-23 08:00:01 +1000
committerAndrew Gerrand <adg@golang.org>2013-07-23 08:00:01 +1000
commit9db29c27845bdd6b21e77a3f910163b2cea6fb7a (patch)
treee993b45ba430884a889fa5eff04196a6ca18ba27
parentb82120bd3e383b02d907b8b78d7b65020c65e702 (diff)
downloadgo-9db29c27845bdd6b21e77a3f910163b2cea6fb7a.tar.gz
go-9db29c27845bdd6b21e77a3f910163b2cea6fb7a.zip
[release-branch.go1.1] cmd/6g, cmd/8g: prevent constant propagation of non-constant LEA.
««« CL 10785043 / cf792c00f410 cmd/6g, cmd/8g: prevent constant propagation of non-constant LEA. Fixes #5809. R=golang-dev, dave, rsc, nigeltao CC=golang-dev https://golang.org/cl/10785043 »»» Update #5928 R=golang-dev, dave CC=golang-dev https://golang.org/cl/11515045
-rw-r--r--src/cmd/6g/peep.c1
-rw-r--r--src/cmd/8g/peep.c1
-rw-r--r--test/fixedbugs/issue5809.go27
3 files changed, 29 insertions, 0 deletions
diff --git a/src/cmd/6g/peep.c b/src/cmd/6g/peep.c
index bb24d41449..cd2881ec40 100644
--- a/src/cmd/6g/peep.c
+++ b/src/cmd/6g/peep.c
@@ -152,6 +152,7 @@ peep(void)
case ALEAQ:
if(regtyp(&p->to))
if(p->from.sym != S)
+ if(p->from.index == D_NONE || p->from.index == D_CONST)
conprop(r);
break;
diff --git a/src/cmd/8g/peep.c b/src/cmd/8g/peep.c
index e5a3149cf1..b8a1eaa08d 100644
--- a/src/cmd/8g/peep.c
+++ b/src/cmd/8g/peep.c
@@ -145,6 +145,7 @@ peep(void)
case ALEAL:
if(regtyp(&p->to))
if(p->from.sym != S)
+ if(p->from.index == D_NONE || p->from.index == D_CONST)
conprop(r);
break;
diff --git a/test/fixedbugs/issue5809.go b/test/fixedbugs/issue5809.go
new file mode 100644
index 0000000000..ca060b55de
--- /dev/null
+++ b/test/fixedbugs/issue5809.go
@@ -0,0 +1,27 @@
+// run
+
+// 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 5809: 6g and 8g attempted to constant propagate indexed LEA
+
+package main
+
+import "fmt"
+
+func main() {
+ const d16 = "0123456789ABCDEF"
+ k := 0x1234
+ var x [4]byte
+
+ x[0] = d16[k>>12&0xf]
+ x[1] = d16[k>>8&0xf]
+ x[2] = d16[k>>4&0xf]
+ x[3] = d16[k&0xf]
+
+ if x != [4]byte{'1','2','3','4'} {
+ fmt.Println(x)
+ panic("x != [4]byte{'1','2','3','4'}")
+ }
+}