aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2014-08-12 10:05:20 +1000
committerAndrew Gerrand <adg@golang.org>2014-08-12 10:05:20 +1000
commit3fa4a7849c51eaad5a5c67f80489e0e12ff10005 (patch)
tree4af7f2b6c68f3e7b73400a5051eb74c9714da821
parentfa02130477db46f6b9f816eb95f0056f52d71ab8 (diff)
downloadgo-3fa4a7849c51eaad5a5c67f80489e0e12ff10005.tar.gz
go-3fa4a7849c51eaad5a5c67f80489e0e12ff10005.zip
[release-branch.go1.3] cmd/6g, cmd/8g: fix, test byte-sized magic multiply
««« CL 124950043 / 8e5ec6948793 cmd/6g, cmd/8g: fix, test byte-sized magic multiply Credit to Rémy for finding and writing test case. Fixes #8325. LGTM=r R=golang-codereviews, r CC=dave, golang-codereviews, iant, remyoudompheng https://golang.org/cl/124950043 »»» TBR=rsc CC=golang-codereviews https://golang.org/cl/126000043
-rw-r--r--src/cmd/6g/ggen.c2
-rw-r--r--src/cmd/6g/peep.c5
-rw-r--r--src/cmd/8g/ggen.c2
-rw-r--r--src/cmd/8g/peep.c5
-rw-r--r--test/fixedbugs/issue8325.go31
5 files changed, 43 insertions, 2 deletions
diff --git a/src/cmd/6g/ggen.c b/src/cmd/6g/ggen.c
index c385798f2e..9665d831b3 100644
--- a/src/cmd/6g/ggen.c
+++ b/src/cmd/6g/ggen.c
@@ -943,7 +943,7 @@ cgen_hmul(Node *nl, Node *nr, Node *res)
if(t->width == 1) {
// byte multiply behaves differently.
nodreg(&ax, t, D_AH);
- nodreg(&dx, t, D_DL);
+ nodreg(&dx, t, D_DX);
gmove(&ax, &dx);
}
nodreg(&dx, t, D_DX);
diff --git a/src/cmd/6g/peep.c b/src/cmd/6g/peep.c
index 0f27204434..24617836fe 100644
--- a/src/cmd/6g/peep.c
+++ b/src/cmd/6g/peep.c
@@ -838,6 +838,11 @@ copyu(Prog *p, Adr *v, Adr *s)
static int
copyas(Adr *a, Adr *v)
{
+ if(D_AL <= a->type && a->type <= D_R15B)
+ fatal("use of byte register");
+ if(D_AL <= v->type && v->type <= D_R15B)
+ fatal("use of byte register");
+
if(a->type != v->type)
return 0;
if(regtyp(v))
diff --git a/src/cmd/8g/ggen.c b/src/cmd/8g/ggen.c
index 2285a04e61..5e31404806 100644
--- a/src/cmd/8g/ggen.c
+++ b/src/cmd/8g/ggen.c
@@ -991,7 +991,7 @@ cgen_hmul(Node *nl, Node *nr, Node *res)
if(t->width == 1) {
// byte multiply behaves differently.
nodreg(&ax, t, D_AH);
- nodreg(&dx, t, D_DL);
+ nodreg(&dx, t, D_DX);
gmove(&ax, &dx);
}
nodreg(&dx, t, D_DX);
diff --git a/src/cmd/8g/peep.c b/src/cmd/8g/peep.c
index a4e516dd34..f902674eca 100644
--- a/src/cmd/8g/peep.c
+++ b/src/cmd/8g/peep.c
@@ -634,6 +634,11 @@ copyu(Prog *p, Adr *v, Adr *s)
static int
copyas(Adr *a, Adr *v)
{
+ if(D_AL <= a->type && a->type <= D_R15B)
+ fatal("use of byte register");
+ if(D_AL <= v->type && v->type <= D_R15B)
+ fatal("use of byte register");
+
if(a->type != v->type)
return 0;
if(regtyp(v))
diff --git a/test/fixedbugs/issue8325.go b/test/fixedbugs/issue8325.go
new file mode 100644
index 0000000000..e22fd319db
--- /dev/null
+++ b/test/fixedbugs/issue8325.go
@@ -0,0 +1,31 @@
+// run
+
+// Copyright 2014 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 8325: corrupted byte operations during optimization
+// pass.
+
+package main
+
+const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+
+func main() {
+ var bytes = []byte{10, 20, 30, 40, 50}
+
+ for i, b := range bytes {
+ bytes[i] = alphanum[b%byte(len(alphanum))]
+ }
+
+ for _, b := range bytes {
+ switch {
+ case '0' <= b && b <= '9',
+ 'A' <= b && b <= 'Z':
+ default:
+ println("found a bad character", string(b))
+ panic("BUG")
+ }
+
+ }
+}