Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 778

Show
Ignore:
Timestamp:
12/05/10 06:56:52 (14 years ago)
Author:
walter
Message:

bugzilla 4864 ICE(statement.c) Crash on invalid 'if statement' body inside mixin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/parse.c

    r717 r778  
    31593159                if (t->value == TOKcomma || t->value == TOKsemicolon) 
    31603160                { 
    31613161                    arg = new Parameter(STCin, NULL, token.ident, NULL); 
    31623162                    nextToken(); 
    31633163                    nextToken(); 
    31643164                    if (1 || !global.params.useDeprecated) 
    31653165                        error("if (v; e) is deprecated, use if (auto v = e)"); 
    31663166                } 
    31673167            } 
    31683168 
    31693169            condition = parseExpression(); 
    31703170            check(TOKrparen); 
    31713171            ifbody = parseStatement(PSscope); 
    31723172            if (token.value == TOKelse) 
    31733173            { 
    31743174                nextToken(); 
    31753175                elsebody = parseStatement(PSscope); 
    31763176            } 
    31773177            else 
    31783178                elsebody = NULL; 
    3179             s = new IfStatement(loc, arg, condition, ifbody, elsebody); 
     3179            if (condition && ifbody) 
     3180                s = new IfStatement(loc, arg, condition, ifbody, elsebody); 
     3181            else 
     3182                s = NULL;               // don't propagate parsing errors 
    31803183            break; 
    31813184        } 
    31823185 
    31833186        case TOKscope: 
    31843187            if (peek(&token)->value != TOKlparen) 
    31853188                goto Ldeclaration;              // scope used as storage class 
    31863189            nextToken(); 
    31873190            check(TOKlparen, "scope"); 
    31883191            if (token.value != TOKidentifier) 
    31893192            {   error("scope (identifier) expected"); 
    31903193                goto Lerror; 
    31913194            } 
    31923195            else 
    31933196            {   TOK t = TOKon_scope_exit; 
    31943197                Identifier *id = token.ident; 
    31953198 
    31963199                if (id == Id::exit) 
    31973200                    t = TOKon_scope_exit; 
    31983201                else if (id == Id::failure) 
    31993202                    t = TOKon_scope_failure; 
  • branches/dmd-1.x/src/statement.c

    r731 r778  
    301301Statements *CompileStatement::flatten(Scope *sc) 
    302302{ 
    303303    //printf("CompileStatement::flatten() %s\n", exp->toChars()); 
    304304    exp = exp->semantic(sc); 
    305305    exp = resolveProperties(sc, exp); 
    306306    exp = exp->optimize(WANTvalue | WANTinterpret); 
    307307    if (exp->op != TOKstring) 
    308308    {   error("argument to mixin must be a string, not (%s)", exp->toChars()); 
    309309        return NULL; 
    310310    } 
    311311    StringExp *se = (StringExp *)exp; 
    312312    se = se->toUTF8(sc); 
    313313    Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 
    314314    p.loc = loc; 
    315315    p.nextToken(); 
    316316 
    317317    Statements *a = new Statements(); 
    318318    while (p.token.value != TOKeof) 
    319319    { 
    320320        Statement *s = p.parseStatement(PSsemi | PScurlyscope); 
    321         a->push(s); 
     321        if (s)                  // if no parsing errors 
     322            a->push(s); 
    322323    } 
    323324    return a; 
    324325} 
    325326 
    326327Statement *CompileStatement::semantic(Scope *sc) 
    327328{ 
    328329    //printf("CompileStatement::semantic() %s\n", exp->toChars()); 
    329330    Statements *a = flatten(sc); 
    330331    if (!a) 
    331332        return NULL; 
    332333    Statement *s = new CompoundStatement(loc, a); 
    333334    return s->semantic(sc); 
    334335} 
    335336 
    336337 
    337338/******************************** DeclarationStatement ***************************/ 
    338339 
    339340DeclarationStatement::DeclarationStatement(Loc loc, Dsymbol *declaration) 
    340341    : ExpStatement(loc, new DeclarationExp(loc, declaration)) 
    341342{ 
  • trunk/src/parse.c

    r769 r778  
    37653765                if (t->value == TOKcomma || t->value == TOKsemicolon) 
    37663766                { 
    37673767                    arg = new Parameter(0, NULL, token.ident, NULL); 
    37683768                    nextToken(); 
    37693769                    nextToken(); 
    37703770                    if (1 || !global.params.useDeprecated) 
    37713771                        error("if (v; e) is deprecated, use if (auto v = e)"); 
    37723772                } 
    37733773            } 
    37743774 
    37753775            condition = parseExpression(); 
    37763776            check(TOKrparen); 
    37773777            ifbody = parseStatement(PSscope); 
    37783778            if (token.value == TOKelse) 
    37793779            { 
    37803780                nextToken(); 
    37813781                elsebody = parseStatement(PSscope); 
    37823782            } 
    37833783            else 
    37843784                elsebody = NULL; 
    3785             s = new IfStatement(loc, arg, condition, ifbody, elsebody); 
     3785            if (condition && ifbody) 
     3786                s = new IfStatement(loc, arg, condition, ifbody, elsebody); 
     3787            else 
     3788                s = NULL;               // don't propagate parsing errors 
    37863789            break; 
    37873790        } 
    37883791 
    37893792        case TOKscope: 
    37903793            if (peek(&token)->value != TOKlparen) 
    37913794                goto Ldeclaration;              // scope used as storage class 
    37923795            nextToken(); 
    37933796            check(TOKlparen); 
    37943797            if (token.value != TOKidentifier) 
    37953798            {   error("scope identifier expected"); 
    37963799                goto Lerror; 
    37973800            } 
    37983801            else 
    37993802            {   TOK t = TOKon_scope_exit; 
    38003803                Identifier *id = token.ident; 
    38013804 
    38023805                if (id == Id::exit) 
    38033806                    t = TOKon_scope_exit; 
    38043807                else if (id == Id::failure) 
    38053808                    t = TOKon_scope_failure; 
  • trunk/src/statement.c

    r737 r778  
    318318Statements *CompileStatement::flatten(Scope *sc) 
    319319{ 
    320320    //printf("CompileStatement::flatten() %s\n", exp->toChars()); 
    321321    exp = exp->semantic(sc); 
    322322    exp = resolveProperties(sc, exp); 
    323323    exp = exp->optimize(WANTvalue | WANTinterpret); 
    324324    if (exp->op != TOKstring) 
    325325    {   error("argument to mixin must be a string, not (%s)", exp->toChars()); 
    326326        return NULL; 
    327327    } 
    328328    StringExp *se = (StringExp *)exp; 
    329329    se = se->toUTF8(sc); 
    330330    Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 
    331331    p.loc = loc; 
    332332    p.nextToken(); 
    333333 
    334334    Statements *a = new Statements(); 
    335335    while (p.token.value != TOKeof) 
    336336    { 
    337337        Statement *s = p.parseStatement(PSsemi | PScurlyscope); 
    338         a->push(s); 
     338        if (s)                  // if no parsing errors 
     339            a->push(s); 
    339340    } 
    340341    return a; 
    341342} 
    342343 
    343344Statement *CompileStatement::semantic(Scope *sc) 
    344345{ 
    345346    //printf("CompileStatement::semantic() %s\n", exp->toChars()); 
    346347    Statements *a = flatten(sc); 
    347348    if (!a) 
    348349        return NULL; 
    349350    Statement *s = new CompoundStatement(loc, a); 
    350351    return s->semantic(sc); 
    351352} 
    352353 
    353354 
    354355/******************************** DeclarationStatement ***************************/ 
    355356 
    356357DeclarationStatement::DeclarationStatement(Loc loc, Dsymbol *declaration) 
    357358    : ExpStatement(loc, new DeclarationExp(loc, declaration)) 
    358359{