]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.power64] cmd/9c: fix switch bug
authorShenghou Ma <minux@golang.org>
Thu, 7 Aug 2014 22:34:25 +0000 (18:34 -0400)
committerShenghou Ma <minux@golang.org>
Thu, 7 Aug 2014 22:34:25 +0000 (18:34 -0400)
The cmd/cc bundled with 9c has additional code compared to our cmd/cc, and
without those code, 9c couldn't handle switch statement where the expression
is not just a simple int32 or int64 variable (e.g. g->status or int8 variable).

All credit goes to rsc.

LGTM=rsc
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/125840043

src/cmd/9c/swt.c

index c912cd5ed88136b3d58406147c8e120f8d89df98..83058e7ab9b7b82dd1aab206a6935908983d2b37 100644 (file)
 void
 swit1(C1 *q, int nc, int32 def, Node *n)
 {
-       Node tn;
-       
+       Node tn, nod;
+
+       regalloc(&nod, n, Z);
+       /* always signed */
+       if(typev[n->type->etype])
+               nod.type = types[TVLONG];
+       else
+               nod.type = types[TLONG];
+       cgen(n, &nod);
        regalloc(&tn, &regnode, Z);
-       swit2(q, nc, def, n, &tn);
+       swit2(q, nc, def, &nod, &tn);
        regfree(&tn);
+       regfree(&nod);
 }
 
 void