]> Cypherpunks repositories - gostls13.git/commitdiff
fix a 6g crash after type errors.
authorRuss Cox <rsc@golang.org>
Tue, 23 Jun 2009 22:30:59 +0000 (15:30 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 23 Jun 2009 22:30:59 +0000 (15:30 -0700)
do not bother warning about marks left
on stack after syntax errors.

leave OCONV nodes in tree to avoid type errors
arising from multiple walks.

R=ken
OCL=30639
CL=30662

src/cmd/5g/cgen.c
src/cmd/6g/cgen.c
src/cmd/8g/cgen.c
src/cmd/gc/go.h
src/cmd/gc/go.y
src/cmd/gc/sinit.c
src/cmd/gc/subr.c
src/cmd/gc/walk.c

index 36dd8767cb3574a2270de97e35e4a79d7fdef22f..443c2ca3aa6f2664a6a0246f2f51b9f0987382b5 100644 (file)
@@ -28,6 +28,9 @@ cgen(Node *n, Node *res)
        if(res == N || res->type == T)
                fatal("cgen: res nil");
 
+       while(n->op == OCONVNOP)
+               n = n->left;
+
        // static initializations
        if(initflag && gen_as_init(n, res))
                goto ret;
@@ -197,10 +200,6 @@ cgen(Node *n, Node *res)
                goto abop;
 
        case OCONV:
-               if(eqtype(n->type, nl->type)) {
-                       cgen(nl, res);
-                       break;
-               }
                regalloc(&n1, nl->type, res);
                cgen(nl, &n1);
                gmove(&n1, res);
@@ -373,7 +372,10 @@ agen(Node *n, Node *res)
 
 //     if(!isptr[res->type->etype])
 //             fatal("agen: not tptr: %T", res->type);
-
+//
+//     while(n->op == OCONVNOP)
+//             n = n->left;
+//
 //     if(n->addable) {
 //             regalloc(&n1, types[tptr], res);
 //             gins(ALEAQ, n, &n1);
@@ -390,12 +392,6 @@ agen(Node *n, Node *res)
 //             fatal("agen: unknown op %N", n);
 //             break;
 
-//     case OCONV:
-//             if(!cvttype(n->type, nl->type))
-//                     fatal("agen: non-trivial OCONV");
-//             agen(nl, res);
-//             return;
-
 //     case OCALLMETH:
 //             cgen_callmeth(n, 0);
 //             cgen_aret(n, res);
index 1bc399c1706205848148e25e11cbc23df755d771..f14ba4f0b5d25a8d6bdd32165f7d445483f8c27f 100644 (file)
@@ -28,6 +28,9 @@ cgen(Node *n, Node *res)
        if(res == N || res->type == T)
                fatal("cgen: res nil");
 
+       while(n->op == OCONVNOP)
+               n = n->left;
+
        // static initializations
        if(initflag && gen_as_init(n, res))
                goto ret;
@@ -196,10 +199,6 @@ cgen(Node *n, Node *res)
                goto abop;
 
        case OCONV:
-               if(eqtype(n->type, nl->type)) {
-                       cgen(nl, res);
-                       break;
-               }
                regalloc(&n1, nl->type, res);
                regalloc(&n2, n->type, &n1);
                cgen(nl, &n1);
@@ -378,6 +377,9 @@ agen(Node *n, Node *res)
        if(!isptr[res->type->etype])
                fatal("agen: not tptr: %T", res->type);
 
+       while(n->op == OCONVNOP)
+               n = n->left;
+
        if(n->addable) {
                regalloc(&n1, types[tptr], res);
                gins(ALEAQ, n, &n1);
@@ -394,12 +396,6 @@ agen(Node *n, Node *res)
                fatal("agen: unknown op %N", n);
                break;
 
-       case OCONV:
-               if(!cvttype(n->type, nl->type))
-                       fatal("agen: non-trivial OCONV");
-               agen(nl, res);
-               return;
-
        case OCALLMETH:
                cgen_callmeth(n, 0);
                cgen_aret(n, res);
index 14797922f549f038a9abc14dba1f664fa708cd18..85cc9aca7defba086f4f93ad75aaf83687edbc29 100644 (file)
@@ -61,6 +61,9 @@ cgen(Node *n, Node *res)
        if(res == N || res->type == T)
                fatal("cgen: res nil");
 
+       while(n->op == OCONVNOP)
+               n = n->left;
+
        // static initializations
        if(initflag && gen_as_init(n, res))
                return;
@@ -403,6 +406,9 @@ agen(Node *n, Node *res)
        if(n == N || n->type == T || res == N || res->type == T)
                fatal("agen");
 
+       while(n->op == OCONVNOP)
+               n = n->left;
+
        // addressable var is easy
        if(n->addable) {
                if(n->op == OREGISTER)
@@ -422,12 +428,6 @@ agen(Node *n, Node *res)
        default:
                fatal("agen %O", n->op);
 
-       case OCONV:
-               if(!cvttype(n->type, nl->type))
-                       fatal("agen: non-trivial OCONV");
-               agen(nl, res);
-               break;
-
        case OCALLMETH:
                cgen_callmeth(n, 0);
                cgen_aret(n, res);
index 4d95316253a6b8cb855a58e83a9383eb269a0048..876a03a93a9dbb28b1a16b3a8e0d4dbf948788a6 100644 (file)
@@ -327,7 +327,7 @@ enum
        OREGISTER, OINDREG,
        OKEY, OPARAM,
        OCOMPOS, OCOMPSLICE, OCOMPMAP,
-       OCONV,
+       OCONV, OCONVNOP,
        ODOTTYPE, OTYPESW,
        OBAD,
 
@@ -530,6 +530,7 @@ EXTERN      char*   outfile;
 EXTERN char*   package;
 EXTERN Biobuf* bout;
 EXTERN int     nerrors;
+EXTERN int     nsyntaxerrors;
 EXTERN char    namebuf[NSYMB];
 EXTERN char    lexbuf[NSYMB];
 EXTERN char    debug[256];
index 0102b58e2257a9cd2ac8f86d34b8fd2855a7593a..ec5032e9ee6349a3d0ab590c8ce826ffca00ddd3 100644 (file)
@@ -129,7 +129,8 @@ file:
                if(debug['f'])
                        frame(1);
                fninit($4);
-               testdclstack();
+               if(nsyntaxerrors == 0)
+                       testdclstack();
        }
 
 package:
index 8fe3523918ec3cd10b4666ef6ddbb3a1f0165efd..021b0301467854b20d06b46b55d88862aacf592e 100644 (file)
@@ -144,6 +144,9 @@ slicerewrite(Node *n)
        int b;
        Node *a;
 
+       while(n->op == OCONVNOP)
+               n = n->left;
+
        // call to newarray - find nel argument
        nel = findarg(n, "nel", "newarray");
        if(nel == N || !isslice(n->type))
index 43cde4ac4f6549cc30e98d98d81e6e1ec6591103..b2b8e77d6e34119b7e7d95e59b32e494942514bd 100644 (file)
@@ -22,8 +22,10 @@ yyerror(char *fmt, ...)
        va_start(arg, fmt);
        vfprint(1, fmt, arg);
        va_end(arg);
-       if(strcmp(fmt, "syntax error") == 0)
+       if(strcmp(fmt, "syntax error") == 0) {
+               nsyntaxerrors++;
                print(" near %s", lexbuf);
+       }
        print("\n");
        if(debug['h'])
                *(int*)0 = 0;
@@ -670,6 +672,7 @@ opnames[] =
        [OCOM]          = "COM",
        [OCONTINUE]     = "CONTINUE",
        [OCONV]         = "CONV",
+       [OCONVNOP]              = "CONVNOP",
        [ODCLARG]       = "DCLARG",
        [ODCLFIELD]     = "DCLFIELD",
        [ODCLFUNC]      = "DCLFUNC",
index bcd139f4baa785e0bc55df17459008ac5f203fac..22711bc7d50fcfa77ee7972753b8b76b13e8b62f 100644 (file)
@@ -618,6 +618,9 @@ loop:
                        goto nottop;
                walkconv(n);
                goto ret;
+       
+       case OCONVNOP:
+               goto ret;
 
        case OCOMPMAP:
        case OCOMPSLICE:
@@ -1284,10 +1287,8 @@ walkconv(Node *n)
                if(!isinter(l->type))
                        yyerror("type assertion requires interface on left, have %T", l->type);
                et = ifaceas1(t, l->type, 1);
-               if(et == I2Isame || et == E2Esame) {
-                       n->op = OCONV;
+               if(et == I2Isame || et == E2Esame)
                        goto nop;
-               }
                if(et != Inone) {
                        indir(n, ifacecvt(t, l, et));
                        return;
@@ -1303,10 +1304,15 @@ walkconv(Node *n)
        // no-op conversion
        if(cvttype(t, l->type) == 1) {
        nop:
-               if(l->op != ONAME) {
+               if(l->op == OLITERAL) {
                        indir(n, l);
-                       n->type = t;
+                       l->type = t;
+                       return;
                }
+               // leave OCONV node in place
+               // in case tree gets walked again.
+               // back end will ignore.
+               n->op = OCONVNOP;
                return;
        }
 
@@ -3564,6 +3570,8 @@ colas(Node *nl, Node *nr)
                        // finish call - first half above
                        l = listfirst(&savel, &nl);
                        t = structfirst(&saver, getoutarg(t));
+                       if(t == T)
+                               return N;
                        while(l != N) {
                                a = mixedoldnew(l, t->type);
                                n = list(n, a);