Commit 5609a489 authored by Matthew Dempsky's avatar Matthew Dempsky

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: default avatarIan Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8847a591
......@@ -186,21 +186,12 @@ func emitptrargsmap() {
// the top of the stack and increasing in size.
// Non-autos sort on offset.
func cmpstackvarlt(a, b *Node) bool {
if a.Class != b.Class {
if a.Class == PAUTO {
return false
}
return true
if (a.Class == PAUTO) != (b.Class == PAUTO) {
return b.Class == PAUTO
}
if a.Class != PAUTO {
if a.Xoffset < b.Xoffset {
return true
}
if a.Xoffset > b.Xoffset {
return false
}
return false
return a.Xoffset < b.Xoffset
}
if a.Used != b.Used {
......@@ -219,11 +210,8 @@ func cmpstackvarlt(a, b *Node) bool {
return ap
}
if a.Type.Width < b.Type.Width {
return false
}
if a.Type.Width > b.Type.Width {
return true
if a.Type.Width != b.Type.Width {
return a.Type.Width > b.Type.Width
}
return a.Sym.Name < b.Sym.Name
......
......@@ -40,6 +40,16 @@ func TestCmpstackvar(t *testing.T) {
Node{Class: PFUNC, Xoffset: 10},
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: false},
......@@ -101,6 +111,10 @@ func TestCmpstackvar(t *testing.T) {
if got != d.lt {
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)
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment