]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: make qsort comparisons totally ordered
authorRuss Cox <rsc@golang.org>
Wed, 11 Feb 2015 03:22:50 +0000 (22:22 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 11 Feb 2015 21:44:46 +0000 (21:44 +0000)
Otherwise different qsort implementations might result
in different sort orders and therefore different compiled
object files.

Change-Id: Ie783ba55a55af06941307e150b0c406e0a8128b0
Reviewed-on: https://go-review.googlesource.com/4590
Reviewed-by: Austin Clements <austin@google.com>
src/cmd/gc/popt.c
src/cmd/gc/reg.c

index afe2b078b819476cf62d326e4340e3cb5c4a8d53..11ade8fd91ab10acb27f1416e47e652642125fb2 100644 (file)
@@ -532,6 +532,14 @@ startcmp(const void *va, const void *vb)
                return -1;
        if(a->start > b->start)
                return +1;
+       // Order what's left by id or symbol name,
+       // just so that sort is forced into a specific ordering,
+       // so that the result of the sort does not depend on
+       // the sort implementation.
+       if(a->def != b->def)
+               return a->def->id - b->def->id;
+       if(a->node != b->node)
+               return strcmp(a->node->sym->name, b->node->sym->name);
        return 0;
 }
 
index 939cf34cb51ad6fe585bc4a3e8971edb7d5c995d..a60e71cfb75796154930bb9c7e8b48f044704019 100644 (file)
@@ -50,15 +50,16 @@ static int
 rcmp(const void *a1, const void *a2)
 {
        Rgn *p1, *p2;
-       int c1, c2;
 
        p1 = (Rgn*)a1;
        p2 = (Rgn*)a2;
-       c1 = p2->cost;
-       c2 = p1->cost;
-       if(c1 -= c2)
-               return c1;
-       return p2->varno - p1->varno;
+       if(p1->cost != p2->cost)
+               return p2->cost - p1->cost;
+       if(p1->varno != p2->varno)
+               return p2->varno - p1->varno;
+       if(p1->enter != p2->enter)
+               return p2->enter->id - p1->enter->id;
+       return 0;
 }
 
 static void