mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
gc: fix order of operations for f() < g().
Also, 6g was passing uninitialized Node &n2 to regalloc, causing non-deterministic register collisions (but only when both left and right hand side of comparison had function calls). Fixes #1728. R=ken2 CC=golang-dev https://golang.org/cl/4425070
This commit is contained in:
parent
f813702f6d
commit
bac8f18035
@ -962,7 +962,7 @@ bgen(Node *n, int true, Prog *to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make simplest on right
|
// make simplest on right
|
||||||
if(nl->op == OLITERAL || nl->ullman < nr->ullman) {
|
if(nl->op == OLITERAL || (nl->ullman < UINF && nl->ullman < nr->ullman)) {
|
||||||
a = brrev(a);
|
a = brrev(a);
|
||||||
r = nl;
|
r = nl;
|
||||||
nl = nr;
|
nl = nr;
|
||||||
@ -1073,18 +1073,18 @@ bgen(Node *n, int true, Prog *to)
|
|||||||
a = optoas(a, nr->type);
|
a = optoas(a, nr->type);
|
||||||
|
|
||||||
if(nr->ullman >= UINF) {
|
if(nr->ullman >= UINF) {
|
||||||
regalloc(&n1, nr->type, N);
|
|
||||||
cgen(nr, &n1);
|
|
||||||
|
|
||||||
tempname(&tmp, nr->type);
|
|
||||||
gmove(&n1, &tmp);
|
|
||||||
regfree(&n1);
|
|
||||||
|
|
||||||
regalloc(&n1, nl->type, N);
|
regalloc(&n1, nl->type, N);
|
||||||
cgen(nl, &n1);
|
cgen(nl, &n1);
|
||||||
|
|
||||||
|
tempname(&tmp, nl->type);
|
||||||
|
gmove(&n1, &tmp);
|
||||||
|
regfree(&n1);
|
||||||
|
|
||||||
regalloc(&n2, nr->type, N);
|
regalloc(&n2, nr->type, N);
|
||||||
cgen(&tmp, &n2);
|
cgen(nr, &n2);
|
||||||
|
|
||||||
|
regalloc(&n1, nl->type, N);
|
||||||
|
cgen(&tmp, &n1);
|
||||||
|
|
||||||
gcmp(optoas(OCMP, nr->type), &n1, &n2);
|
gcmp(optoas(OCMP, nr->type), &n1, &n2);
|
||||||
patch(gbranch(a, nr->type), to);
|
patch(gbranch(a, nr->type), to);
|
||||||
|
@ -829,7 +829,7 @@ bgen(Node *n, int true, Prog *to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make simplest on right
|
// make simplest on right
|
||||||
if(nl->op == OLITERAL || nl->ullman < nr->ullman) {
|
if(nl->op == OLITERAL || (nl->ullman < nr->ullman && nl->ullman < UINF)) {
|
||||||
a = brrev(a);
|
a = brrev(a);
|
||||||
r = nl;
|
r = nl;
|
||||||
nl = nr;
|
nl = nr;
|
||||||
@ -879,18 +879,18 @@ bgen(Node *n, int true, Prog *to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(nr->ullman >= UINF) {
|
if(nr->ullman >= UINF) {
|
||||||
regalloc(&n1, nr->type, N);
|
|
||||||
cgen(nr, &n1);
|
|
||||||
|
|
||||||
tempname(&tmp, nr->type);
|
|
||||||
gmove(&n1, &tmp);
|
|
||||||
regfree(&n1);
|
|
||||||
|
|
||||||
regalloc(&n1, nl->type, N);
|
regalloc(&n1, nl->type, N);
|
||||||
cgen(nl, &n1);
|
cgen(nl, &n1);
|
||||||
|
|
||||||
regalloc(&n2, nr->type, &n2);
|
tempname(&tmp, nl->type);
|
||||||
cgen(&tmp, &n2);
|
gmove(&n1, &tmp);
|
||||||
|
regfree(&n1);
|
||||||
|
|
||||||
|
regalloc(&n2, nr->type, N);
|
||||||
|
cgen(nr, &n2);
|
||||||
|
|
||||||
|
regalloc(&n1, nl->type, N);
|
||||||
|
cgen(&tmp, &n1);
|
||||||
|
|
||||||
goto cmp;
|
goto cmp;
|
||||||
}
|
}
|
||||||
|
@ -900,7 +900,7 @@ bgen(Node *n, int true, Prog *to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make simplest on right
|
// make simplest on right
|
||||||
if(nl->op == OLITERAL || nl->ullman < nr->ullman) {
|
if(nl->op == OLITERAL || (nl->ullman < nr->ullman && nl->ullman < UINF)) {
|
||||||
a = brrev(a);
|
a = brrev(a);
|
||||||
r = nl;
|
r = nl;
|
||||||
nl = nr;
|
nl = nr;
|
||||||
@ -1025,8 +1025,8 @@ bgen(Node *n, int true, Prog *to)
|
|||||||
if(nr->ullman >= UINF) {
|
if(nr->ullman >= UINF) {
|
||||||
tempname(&n1, nl->type);
|
tempname(&n1, nl->type);
|
||||||
tempname(&tmp, nr->type);
|
tempname(&tmp, nr->type);
|
||||||
cgen(nr, &tmp);
|
|
||||||
cgen(nl, &n1);
|
cgen(nl, &n1);
|
||||||
|
cgen(nr, &tmp);
|
||||||
regalloc(&n2, nr->type, N);
|
regalloc(&n2, nr->type, N);
|
||||||
cgen(&tmp, &n2);
|
cgen(&tmp, &n2);
|
||||||
goto cmp;
|
goto cmp;
|
||||||
|
29
test/func7.go
Normal file
29
test/func7.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// $G $D/$F.go && $L $F.$A && ./$A.out
|
||||||
|
|
||||||
|
// Copyright 2011 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.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
var calledf = false
|
||||||
|
|
||||||
|
func f() int {
|
||||||
|
calledf = true
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func g() int {
|
||||||
|
if !calledf {
|
||||||
|
println("BUG: func7 - called g before f")
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// 6g, 8g, 5g all used to evaluate g() before f().
|
||||||
|
if f() < g() {
|
||||||
|
panic("wrong answer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user