]> Cypherpunks repositories - gostls13.git/commitdiff
shift typechecking bugs
authorRuss Cox <rsc@golang.org>
Tue, 7 Jul 2009 06:33:17 +0000 (23:33 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 7 Jul 2009 06:33:17 +0000 (23:33 -0700)
x << "a"
1 << int(2)

R=ken
OCL=31244
CL=31244

src/cmd/gc/const.c
src/cmd/gc/walk.c

index d45e6136a1920903ff586ab856eb39312713e050..a0a08067912141838225d3880c09c611c63c69d5 100644 (file)
@@ -345,6 +345,8 @@ evconst(Node *n)
                // right must be unsigned.
                // left can be ideal.
                defaultlit(nr, types[TUINT]);
+               if(nr->type && (issigned[nr->type->etype] || !isint[nr->type->etype]))
+                       goto illegal;
                break;
        }
 
@@ -367,9 +369,11 @@ evconst(Node *n)
        switch(TUP(n->op, v.ctype)) {
        default:
        illegal:
-               yyerror("illegal constant expression %T %O %T",
-                       nl->type, n->op, nr->type);
-               n->diag = 1;
+               if(!n->diag) {
+                       yyerror("illegal constant expression: %T %O %T",
+                               nl->type, n->op, nr->type);
+                       n->diag = 1;
+               }
                return;
 
        case TUP(OADD, CTINT):
@@ -551,7 +555,10 @@ unary:
 
        switch(TUP(n->op, v.ctype)) {
        default:
-               yyerror("illegal constant expression %O %T", n->op, nl->type);
+               if(!n->diag) {
+                       yyerror("illegal constant expression %O %T", n->op, nl->type);
+                       n->diag = 1;
+               }
                return;
 
        case TUP(OPLUS, CTINT):
index 398d61ec69dca49885e0f1226576496fe7e31e05..e0617259f42248699b029cdefe4fcd966724eb2f 100644 (file)
@@ -704,7 +704,7 @@ loop:
                defaultlit(n->right, types[TUINT]);
                if(n->left->type == T || n->right->type == T)
                        goto ret;
-               if(issigned[n->right->type->etype])
+               if(issigned[n->right->type->etype] || !isint[n->right->type->etype])
                        goto badt;
                // check of n->left->type happens in second switch.
                break;