]> Cypherpunks repositories - gostls13.git/commitdiff
gc: handle iface == nil in back end
authorRuss Cox <rsc@golang.org>
Mon, 24 Aug 2009 22:20:37 +0000 (15:20 -0700)
committerRuss Cox <rsc@golang.org>
Mon, 24 Aug 2009 22:20:37 +0000 (15:20 -0700)
R=ken
OCL=33778
CL=33781

src/cmd/5g/cgen.c
src/cmd/6g/cgen.c
src/cmd/8g/cgen.c
src/cmd/gc/typecheck.c

index b58d491ac9ece5c583c73a76a2ff3cd21d11963e..b99350c31c183fa70fbdb01aa82a9bd9ad7c214b 100644 (file)
@@ -790,6 +790,25 @@ bgen(Node *n, int true, Prog *to)
                        regfree(&n1);
                        break;
                }
+               
+               if(isinter(nl->type)) {
+                       // front end shold only leave cmp to literal nil
+                       if((a != OEQ && a != ONE) || nr->op != OLITERAL) {
+                               yyerror("illegal interface comparison");
+                               break;
+                       }
+                       a = optoas(a, types[tptr]);
+                       regalloc(&n1, types[tptr], N);
+                       agen(nl, &n1);
+                       n2 = n1;
+                       n2.op = OINDREG;
+                       n2.xoffset = 0;
+                       nodconst(&tmp, types[tptr], 0);
+                       gins(optoas(OCMP, types[tptr]), &n2, &tmp);
+                       patch(gbranch(a, types[tptr]), to);
+                       regfree(&n1);
+                       break;
+               }
 
                a = optoas(a, nr->type);
 
index d36c0e15da2f8aec8d31b3f4ee876209e5a06615..fcdf7ead9af7ed248bda601d76cf36930c4cbeed 100644 (file)
@@ -743,6 +743,7 @@ bgen(Node *n, int true, Prog *to)
                nl = n->left;
                if(nl == N || nl->type == T)
                        goto ret;
+               break;
        }
 
        switch(n->op) {
@@ -787,6 +788,25 @@ bgen(Node *n, int true, Prog *to)
                        regfree(&n1);
                        break;
                }
+               
+               if(isinter(nl->type)) {
+                       // front end shold only leave cmp to literal nil
+                       if((a != OEQ && a != ONE) || nr->op != OLITERAL) {
+                               yyerror("illegal interface comparison");
+                               break;
+                       }
+                       a = optoas(a, types[tptr]);
+                       regalloc(&n1, types[tptr], N);
+                       agen(nl, &n1);
+                       n2 = n1;
+                       n2.op = OINDREG;
+                       n2.xoffset = 0;
+                       nodconst(&tmp, types[tptr], 0);
+                       gins(optoas(OCMP, types[tptr]), &n2, &tmp);
+                       patch(gbranch(a, types[tptr]), to);
+                       regfree(&n1);
+                       break;
+               }
 
                a = optoas(a, nr->type);
 
index db1986df9850a0e976ac0b19e2bbe514d0f89ea0..94627f50be47ee5c6c60975b75f0e863f657078d 100644 (file)
@@ -838,6 +838,25 @@ bgen(Node *n, int true, Prog *to)
                        regfree(&n1);
                        break;
                }
+               
+               if(isinter(nl->type)) {
+                       // front end shold only leave cmp to literal nil
+                       if((a != OEQ && a != ONE) || nr->op != OLITERAL) {
+                               yyerror("illegal interface comparison");
+                               break;
+                       }
+                       a = optoas(a, types[tptr]);
+                       regalloc(&n1, types[tptr], N);
+                       agen(nl, &n1);
+                       n2 = n1;
+                       n2.op = OINDREG;
+                       n2.xoffset = 0;
+                       nodconst(&tmp, types[tptr], 0);
+                       gins(optoas(OCMP, types[tptr]), &n2, &tmp);
+                       patch(gbranch(a, types[tptr]), to);
+                       regfree(&n1);
+                       break;
+               }
 
                if(isfloat[nr->type->etype]) {
                        nodreg(&tmp, nr->type, D_F0);
index 43351796b7b2eee0876a661b23d6731693e3cb55..9f0beb559f1e100fe6264aae2d6c0e1b77b06dc7 100644 (file)
@@ -323,8 +323,16 @@ reswitch:
                                n->op = OADDSTR;
                }
                if(et == TINTER) {
-                       n->etype = n->op;
-                       n->op = OCMPIFACE;
+                       if(l->op == OLITERAL && l->val.ctype == CTNIL) {
+                               // swap for back end
+                               n->left = r;
+                               n->right = l;
+                       } else if(r->op == OLITERAL && r->val.ctype == CTNIL) {
+                               // leave alone for back end
+                       } else {
+                               n->etype = n->op;
+                               n->op = OCMPIFACE;
+                       }
                }
                n->type = t;
                goto ret;