]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/8c: better fix for 64-bit register smash
authorRuss Cox <rsc@golang.org>
Fri, 25 May 2012 03:36:26 +0000 (23:36 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 25 May 2012 03:36:26 +0000 (23:36 -0400)
Ken pointed out that CL 5998043 was ugly code.
This should be better.

Fixes #3501.

R=ken2
CC=golang-dev
https://golang.org/cl/6258049

src/cmd/8c/cgen.c
src/cmd/8c/cgen64.c

index 869d31ace49a4a305b29c78a591fa442ee7c06a9..7a49b671ca3a7729f3b69497086fb479d169b838 100644 (file)
@@ -1703,6 +1703,7 @@ copy:
                }
        }
 
+       v = w == 8;
        if(n->complex >= FNX && nn != nil && nn->complex >= FNX) {
                t = nn->type;
                nn->type = types[TLONG];
@@ -1728,8 +1729,28 @@ copy:
        }
 
        x = 0;
-       v = w == 8;
        if(v) {
+               if(nn != nil && nn->complex >= FNX) {
+                       t = nn->type;
+                       nn->type = types[TLONG];
+                       regialloc(&nod2, nn, Z);
+                       lcgen(nn, &nod2);
+                       nn->type = t;
+                       
+                       nod2.type = typ(TIND, t);
+       
+                       nod1 = nod2;
+                       nod1.op = OIND;
+                       nod1.left = &nod2;
+                       nod1.right = Z;
+                       nod1.complex = 1;
+                       nod1.type = t;
+       
+                       sugen(n, &nod1, w);
+                       regfree(&nod2);
+                       return;
+               }
+                       
                c = cursafe;
                if(n->left != Z && n->left->complex >= FNX
                && n->right != Z && n->right->complex >= FNX) {
index 21619b89306a73c3c8ff5cc2c7f3e784110a8ab5..3424f762c53a817e964e3a3db073bc5088d858b9 100644 (file)
@@ -1601,33 +1601,6 @@ cgen64(Node *n, Node *nn)
                prtree(n, "cgen64");
                print("AX = %d\n", reg[D_AX]);
        }
-
-       if(nn != Z && nn->complex >= FNX) {
-               // Evaluate nn address to register
-               // before we use registers for n.
-               // Otherwise the call during computation of nn
-               // will smash the registers.  See
-               // http://golang.org/issue/3501.
-
-               // If both n and nn want calls, refuse to compile.
-               if(n != Z && n->complex >= FNX)
-                       diag(n, "cgen64 miscompile");
-
-               reglcgen(&nod1, nn, Z);
-               m = cgen64(n, &nod1);
-               regfree(&nod1);
-               
-               if(m == 0) {
-                       // Now what?  We computed &nn, which involved a
-                       // function call, and didn't use it.  The caller will recompute nn,
-                       // calling the function a second time.
-                       // We can figure out what to do later, if this actually happens.
-                       diag(n, "cgen64 miscompile");
-               }
-
-               return m;
-       }
-
        cmp = 0;
        sh = 0;