mirror of https://github.com/golang/go.git
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
This commit is contained in:
parent
eae9fee3bf
commit
5b63ce4e19
|
|
@ -943,7 +943,7 @@ cgen_hmul(Node *nl, Node *nr, Node *res)
|
||||||
if(t->width == 1) {
|
if(t->width == 1) {
|
||||||
// byte multiply behaves differently.
|
// byte multiply behaves differently.
|
||||||
nodreg(&ax, t, D_AH);
|
nodreg(&ax, t, D_AH);
|
||||||
nodreg(&dx, t, D_DL);
|
nodreg(&dx, t, D_DX);
|
||||||
gmove(&ax, &dx);
|
gmove(&ax, &dx);
|
||||||
}
|
}
|
||||||
nodreg(&dx, t, D_DX);
|
nodreg(&dx, t, D_DX);
|
||||||
|
|
|
||||||
|
|
@ -838,6 +838,11 @@ copyu(Prog *p, Adr *v, Adr *s)
|
||||||
static int
|
static int
|
||||||
copyas(Adr *a, Adr *v)
|
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)
|
if(a->type != v->type)
|
||||||
return 0;
|
return 0;
|
||||||
if(regtyp(v))
|
if(regtyp(v))
|
||||||
|
|
|
||||||
|
|
@ -991,7 +991,7 @@ cgen_hmul(Node *nl, Node *nr, Node *res)
|
||||||
if(t->width == 1) {
|
if(t->width == 1) {
|
||||||
// byte multiply behaves differently.
|
// byte multiply behaves differently.
|
||||||
nodreg(&ax, t, D_AH);
|
nodreg(&ax, t, D_AH);
|
||||||
nodreg(&dx, t, D_DL);
|
nodreg(&dx, t, D_DX);
|
||||||
gmove(&ax, &dx);
|
gmove(&ax, &dx);
|
||||||
}
|
}
|
||||||
nodreg(&dx, t, D_DX);
|
nodreg(&dx, t, D_DX);
|
||||||
|
|
|
||||||
|
|
@ -636,6 +636,11 @@ copyu(Prog *p, Adr *v, Adr *s)
|
||||||
static int
|
static int
|
||||||
copyas(Adr *a, Adr *v)
|
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)
|
if(a->type != v->type)
|
||||||
return 0;
|
return 0;
|
||||||
if(regtyp(v))
|
if(regtyp(v))
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue