aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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'}")
+ }
+}