mirror of
https://github.com/golang/go
synced 2024-11-13 18:40:22 -07:00
cmd/compile: make cmpstackvarlt properly asymmetric
Previously, given two Nodes n1 and n2 of different non-PAUTO classes (e.g., PPARAM and PPARAMOUT), cmpstackvarlt(n1, n2) and cmpstackvarlt(n2, n1) both returned true, which is nonsense. This doesn't seem to cause any visible miscompilation problems, but notably fixing it does cause toolstash/buildall to fail. Change-Id: I33b2c66e902c5eced875d8fbf18b7cfdc81e8aed Reviewed-on: https://go-review.googlesource.com/19778 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
8847a5913a
commit
5609a48931
@ -186,21 +186,12 @@ func emitptrargsmap() {
|
|||||||
// the top of the stack and increasing in size.
|
// the top of the stack and increasing in size.
|
||||||
// Non-autos sort on offset.
|
// Non-autos sort on offset.
|
||||||
func cmpstackvarlt(a, b *Node) bool {
|
func cmpstackvarlt(a, b *Node) bool {
|
||||||
if a.Class != b.Class {
|
if (a.Class == PAUTO) != (b.Class == PAUTO) {
|
||||||
if a.Class == PAUTO {
|
return b.Class == PAUTO
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.Class != PAUTO {
|
if a.Class != PAUTO {
|
||||||
if a.Xoffset < b.Xoffset {
|
return a.Xoffset < b.Xoffset
|
||||||
return true
|
|
||||||
}
|
|
||||||
if a.Xoffset > b.Xoffset {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.Used != b.Used {
|
if a.Used != b.Used {
|
||||||
@ -219,11 +210,8 @@ func cmpstackvarlt(a, b *Node) bool {
|
|||||||
return ap
|
return ap
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.Type.Width < b.Type.Width {
|
if a.Type.Width != b.Type.Width {
|
||||||
return false
|
return a.Type.Width > b.Type.Width
|
||||||
}
|
|
||||||
if a.Type.Width > b.Type.Width {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.Sym.Name < b.Sym.Name
|
return a.Sym.Name < b.Sym.Name
|
||||||
|
@ -40,6 +40,16 @@ func TestCmpstackvar(t *testing.T) {
|
|||||||
Node{Class: PFUNC, Xoffset: 10},
|
Node{Class: PFUNC, Xoffset: 10},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Node{Class: PPARAM, Xoffset: 10},
|
||||||
|
Node{Class: PPARAMOUT, Xoffset: 20},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Node{Class: PPARAMOUT, Xoffset: 10},
|
||||||
|
Node{Class: PPARAM, Xoffset: 20},
|
||||||
|
true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Node{Class: PAUTO, Used: true},
|
Node{Class: PAUTO, Used: true},
|
||||||
Node{Class: PAUTO, Used: false},
|
Node{Class: PAUTO, Used: false},
|
||||||
@ -101,6 +111,10 @@ func TestCmpstackvar(t *testing.T) {
|
|||||||
if got != d.lt {
|
if got != d.lt {
|
||||||
t.Errorf("want %#v < %#v", d.a, d.b)
|
t.Errorf("want %#v < %#v", d.a, d.b)
|
||||||
}
|
}
|
||||||
|
// If we expect a < b to be true, check that b < a is false.
|
||||||
|
if d.lt && cmpstackvarlt(&d.b, &d.a) {
|
||||||
|
t.Errorf("unexpected %#v < %#v", d.b, d.a)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user