8000 [release-branch.go1.3] cmd/6g, cmd/8g: fix, test byte-sized magic mul… · golang/go@3fa4a78 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3fa4a78

Browse files
committed
[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
1 parent fa02130 commit 3fa4a78

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

src/cmd/6g/ggen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ cgen_hmul(Node *nl, Node *nr, Node *res)
943943
if(t->width == 1) {
944944
// byte multiply behaves differently.
945945
nodreg(&ax, t, D_AH);
946-
nodreg(&dx, t, D_DL);
946+
nodreg(&dx, t, D_DX);
947947
gmove(&ax, &dx);
948948
}
949949
nodreg(&dx, t, D_DX);

src/cmd/6g/peep.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,11 @@ copyu(Prog *p, Adr *v, Adr *s)
838838
static int
839839
copyas(Adr *a, Adr *v)
840840
{
841+
if(D_AL <= a->type && a->type <= D_R15B)
842+
fatal("use of byte register");
843+
if(D_AL <= v->type && v->type <= D_R15B)
844+
fatal("use of byte register");
845+
841846
if(a->type != v->type)
842847
return 0;
843848
if(regtyp(v))

src/cmd/8g/ggen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ cgen_hmul(Node *nl, Node *nr, Node *res)
991991
if(t->width == 1) {
992992
// byte multiply behaves differently.
993993
nodreg(&ax, t, D_AH);
994-
nodreg(&dx, t, D_DL);
994+
nodreg(&dx, t, D_DX);
995995
gmove(&ax, &dx);
996996
}
997997
nodreg(&dx, t, D_DX);

src/cmd/8g/peep.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,11 @@ copyu(Prog *p, Adr *v, Adr *s)
634634
static int
635635
copyas(Adr *a, Adr *v)
636636
{
637+
if(D_AL <= a->type && a->type <= D_R15B)
638+
fatal("use of byte register");
639+
if(D_AL <= v->type && v->type <= D_R15B)
640+
fatal("use of byte register");
641+
637642
if(a->type != v->type)
638643
return 0;
639644
if(regtyp(v))

test/fixedbugs/issue8325.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// run
2+
3+
// Copyright 2014 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 8325: corrupted byte operations during optimization
8+
// pass.
9+
10+
package main
11+
12+
const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
13+
14+
func main() {
15+
var bytes = []byte{10, 20, 30, 40, 50}
16+
17+
for i, b := range bytes {
18+
bytes[i] = alphanum[b%byte(len(alphanum))]
19+
}
20+
21+
for _, b := range bytes {
22+
switch {
23+
case '0' <= b && b <= '9',
24+
'A' <= b && b <= 'Z':
25+
default:
26+
println("found a bad character", string(b))
27+
panic("BUG")
28+
}
29+
30+
}
31+
}

0 commit comments

Comments
 (0)
0