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

Changeset 814

Show
Ignore:
Timestamp:
12/23/10 07:38:11 (14 years ago)
Author:
walter
Message:

Bugzilla 5242 self referencing template constraint crashes compiler

Files:

Legend:

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

    r810 r814  
    16951695 
    16961696  if (op1 != OPcond && op1 != OPandand && op1 != OPoror && 
    16971697      op1 != OPnot && op1 != OPbool && 
    16981698      e21->Eoper == OPconst && 
    16991699      sz1 <= REGSIZE && 
    17001700      *pretregs & (mBP | ALLREGS) && 
    17011701      tysize(e21->Ety) <= REGSIZE && !tyfloating(e21->Ety)) 
    17021702  {     // Recognize (e ? c : f) 
    17031703        unsigned reg; 
    17041704        regm_t retregs; 
    17051705 
    17061706        cnop1 = gennop(CNIL); 
    17071707        retregs = mPSW; 
    17081708        jop = jmpopcode(e1);            // get jmp condition 
    17091709        c = codelem(e1,&retregs,FALSE); 
    17101710 
    17111711        // Set the register with e21 without affecting the flags 
    17121712        retregs = *pretregs & (ALLREGS | mBP); 
    17131713        if (retregs & ~regcon.mvar) 
    17141714            retregs &= ~regcon.mvar;    // don't disturb register variables 
    1715         c = regwithvalue(c,retregs,e21->EV.Vint,&reg,sz1 == 8 ? 64|8 : 8); 
     1715        // NOTE: see my email (sign extension bug? possible fix, some questions 
     1716        c = regwithvalue(c,retregs,e21->EV.Vint,&reg,tysize(e21->Ety) == 8 ? 64|8 : 8); 
    17161717        retregs = mask[reg]; 
    17171718 
    17181719        c = cat(c,cse_flush(1));                // flush CSE's to memory 
    17191720        c = genjmp(c,jop,FLcode,(block *)cnop1); 
    17201721        freenode(e21); 
    17211722 
    17221723        regconsave = regcon; 
    17231724        stackpushsave = stackpush; 
    17241725 
    17251726        c2 = codelem(e22,&retregs,FALSE); 
    17261727 
    17271728        andregcon(&regconsave); 
    17281729        assert(stackpushsave == stackpush); 
    17291730 
    17301731        freenode(e2); 
    17311732        c = cat6(cc,c,c2,cnop1,fixresult(e,retregs,pretregs),NULL); 
    17321733        goto Lret; 
    17331734  } 
    17341735 
    17351736  cnop1 = gennop(CNIL); 
  • branches/dmd-1.x/src/backend/cod4.c

    r807 r814  
    32163216 
    32173217/************************************* 
    32183218 * Generate code for OPbsf and OPbsr. 
    32193219 */ 
    32203220 
    32213221code *cdbscan(elem *e, regm_t *pretregs) 
    32223222{ 
    32233223    regm_t retregs; 
    32243224    unsigned reg; 
    32253225    int sz; 
    32263226    tym_t tyml; 
    32273227    code *cl,*cg; 
    32283228    code cs; 
    32293229 
    32303230    //printf("cdbscan()\n"); 
    32313231    //elem_print(e); 
    32323232    if (*pretregs == 0) 
    32333233        return codelem(e->E1,pretregs,FALSE); 
    32343234    tyml = tybasic(e->E1->Ety); 
    32353235    sz = tysize[tyml]; 
    3236     assert(sz == 2 || sz == 4); 
     3236    assert(sz == 2 || sz == 4 || sz == 8); 
    32373237 
    32383238    if ((e->E1->Eoper == OPind && !e->E1->Ecount) || e->E1->Eoper == OPvar) 
    32393239    { 
    32403240        cl = getlvalue(&cs, e->E1, RMload);     // get addressing mode 
    32413241    } 
    32423242    else 
    32433243    { 
    32443244        retregs = allregs; 
    32453245        cl = codelem(e->E1, &retregs, FALSE); 
    32463246        reg = findreg(retregs); 
    32473247        cs.Irm = modregrm(3,0,reg & 7); 
    32483248        cs.Iflags = 0; 
    32493249        cs.Irex = 0; 
    32503250        if (reg & 8) 
    32513251            cs.Irex |= REX_B; 
    32523252    } 
    32533253 
    32543254    retregs = *pretregs & allregs; 
    32553255    if  (!retregs) 
    32563256        retregs = allregs; 
    32573257    cg = allocreg(&retregs, &reg, e->Ety); 
    32583258 
    32593259    cs.Iop = (e->Eoper == OPbsf) ? 0x0FBC : 0x0FBD;        // BSF/BSR reg,EA 
    32603260    code_newreg(&cs, reg); 
    32613261    if (!I16 && sz == SHORTSIZE) 
    32623262        cs.Iflags |= CFopsize; 
    32633263    cg = gen(cg,&cs); 
     3264    if (sz == 8) 
     3265        code_orrex(cg, REX_W); 
    32643266 
    32653267    return cat3(cl,cg,fixresult(e,retregs,pretregs)); 
    32663268} 
    32673269 
    32683270/******************************************* 
    32693271 * Generate code for OPpair, OPrpair. 
    32703272 */ 
    32713273 
    32723274code *cdpair(elem *e, regm_t *pretregs) 
    32733275{ 
    32743276    regm_t retregs; 
    32753277    regm_t regs1; 
    32763278    regm_t regs2; 
    32773279    unsigned reg; 
    32783280    code *cg; 
    32793281    code *c1; 
    32803282    code *c2; 
    32813283 
    32823284    if (*pretregs == 0)                         // if don't want result 
    32833285    {   c1 = codelem(e->E1,pretregs,FALSE);     // eval left leaf 
  • branches/dmd-1.x/src/imphint.c

    r767 r814  
    2929{ 
    3030#if DMDV1 
    3131    static const char *modules[] = 
    3232    {   "std.c.stdio", 
    3333        "std.stdio", 
    3434        "std.math", 
    3535        "std.c.stdarg", 
    3636    }; 
    3737    static const char *names[] = 
    3838    { 
    3939        "printf", NULL, 
    4040        "writefln", NULL, 
    4141        "sin", "cos", "sqrt", "fabs", NULL, 
    4242        "__va_argsave_t", NULL, 
    4343    }; 
    4444#else 
    4545    static const char *modules[] = 
    4646    {   "core.stdc.stdio", 
    4747        "std.stdio", 
    4848        "std.math", 
    49         "std.c.stdarg", 
     49        "core.vararg", 
    5050    }; 
    5151    static const char *names[] = 
    5252    { 
    5353        "printf", NULL, 
    5454        "writeln", NULL, 
    5555        "sin", "cos", "sqrt", "fabs", NULL, 
    5656        "__va_argsave_t", NULL, 
    5757    }; 
    5858#endif 
    5959    int m = 0; 
    6060    for (int n = 0; n < sizeof(names)/sizeof(names[0]); n++) 
    6161    { 
    6262        const char *p = names[n]; 
    6363        if (p == NULL) 
    6464        {   m++; 
    6565            continue; 
    6666        } 
    6767        assert(m < sizeof(modules)/sizeof(modules[0])); 
    6868        if (strcmp(s, p) == 0) 
    6969            return modules[m]; 
  • branches/dmd-1.x/src/template.c

    r801 r814  
    22562256 * This is complicated, because there may be more than one base class which 
    22572257 * matches. In such cases, one or more parameters remain ambiguous. 
    22582258 * For example, 
    22592259 * 
    22602260 *   interface I(X, Y) {} 
    22612261 *   class C : I(uint, double), I(char, double) {} 
    22622262 *   C x; 
    22632263 *   foo(T, U)( I!(T, U) x) 
    22642264 * 
    22652265 *   deduces that U is double, but T remains ambiguous (could be char or uint). 
    22662266 * 
    22672267 * Given a baseclass b, and initial deduced types 'dedtypes', this function 
    22682268 * tries to match tparam with b, and also tries all base interfaces of b. 
    22692269 * If a match occurs, numBaseClassMatches is incremented, and the new deduced 
    22702270 * types are ANDed with the current 'best' estimate for dedtypes. 
    22712271 */ 
    22722272void deduceBaseClassParameters(BaseClass *b, 
    22732273    Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes, 
    22742274    Objects *best, int &numBaseClassMatches) 
    22752275{ 
    2276     TemplateInstance *parti = b->base->parent->isTemplateInstance()
     2276    TemplateInstance *parti = b->base ? b->base->parent->isTemplateInstance() : NULL
    22772277    if (parti) 
    22782278    { 
    22792279        // Make a temporary copy of dedtypes so we don't destroy it 
    22802280        Objects *tmpdedtypes = new Objects(); 
    22812281        tmpdedtypes->setDim(dedtypes->dim); 
    22822282        memcpy(tmpdedtypes->data, dedtypes->data, dedtypes->dim * sizeof(void *)); 
    22832283 
    22842284        TypeInstance *t = new TypeInstance(0, parti); 
    22852285        MATCH m = t->deduceType(sc, tparam, parameters, tmpdedtypes); 
    22862286        if (m != MATCHnomatch) 
    22872287        { 
    22882288            // If this is the first ever match, it becomes our best estimate 
    22892289            if (numBaseClassMatches==0) 
    22902290                memcpy(best->data, tmpdedtypes->data, tmpdedtypes->dim * sizeof(void *)); 
    22912291            else for (size_t k = 0; k < tmpdedtypes->dim; ++k) 
    22922292            { 
    22932293                // If we've found more than one possible type for a parameter, 
    22942294                // mark it as unknown. 
    22952295                if (tmpdedtypes->data[k] != best->data[k]) 
    22962296                    best->data[k] = dedtypes->data[k]; 
  • trunk/src/template.c

    r811 r814  
    25162516 * This is complicated, because there may be more than one base class which 
    25172517 * matches. In such cases, one or more parameters remain ambiguous. 
    25182518 * For example, 
    25192519 * 
    25202520 *   interface I(X, Y) {} 
    25212521 *   class C : I(uint, double), I(char, double) {} 
    25222522 *   C x; 
    25232523 *   foo(T, U)( I!(T, U) x) 
    25242524 * 
    25252525 *   deduces that U is double, but T remains ambiguous (could be char or uint). 
    25262526 * 
    25272527 * Given a baseclass b, and initial deduced types 'dedtypes', this function 
    25282528 * tries to match tparam with b, and also tries all base interfaces of b. 
    25292529 * If a match occurs, numBaseClassMatches is incremented, and the new deduced 
    25302530 * types are ANDed with the current 'best' estimate for dedtypes. 
    25312531 */ 
    25322532void deduceBaseClassParameters(BaseClass *b, 
    25332533    Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes, 
    25342534    Objects *best, int &numBaseClassMatches) 
    25352535{ 
    2536     TemplateInstance *parti = b->base->parent->isTemplateInstance()
     2536    TemplateInstance *parti = b->base ? b->base->parent->isTemplateInstance() : NULL
    25372537    if (parti) 
    25382538    { 
    25392539        // Make a temporary copy of dedtypes so we don't destroy it 
    25402540        Objects *tmpdedtypes = new Objects(); 
    25412541        tmpdedtypes->setDim(dedtypes->dim); 
    25422542        memcpy(tmpdedtypes->data, dedtypes->data, dedtypes->dim * sizeof(void *)); 
    25432543 
    25442544        TypeInstance *t = new TypeInstance(0, parti); 
    25452545        MATCH m = t->deduceType(sc, tparam, parameters, tmpdedtypes); 
    25462546        if (m != MATCHnomatch) 
    25472547        { 
    25482548            // If this is the first ever match, it becomes our best estimate 
    25492549            if (numBaseClassMatches==0) 
    25502550                memcpy(best->data, tmpdedtypes->data, tmpdedtypes->dim * sizeof(void *)); 
    25512551            else for (size_t k = 0; k < tmpdedtypes->dim; ++k) 
    25522552            { 
    25532553                // If we've found more than one possible type for a parameter, 
    25542554                // mark it as unknown. 
    25552555                if (tmpdedtypes->data[k] != best->data[k]) 
    25562556                    best->data[k] = dedtypes->data[k];