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

Changeset 823

Show
Ignore:
Timestamp:
12/27/10 23:23:34 (14 years ago)
Author:
walter
Message:

bugzilla 5090 ICE(todt.c) struct literal initializing zero length array

Files:

Legend:

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

    r745 r823  
    126126                    if (k == dts.dim)           // didn't find any overlap 
    127127                    { 
    128128                        v->type->toDt(&d); 
    129129                        break; 
    130130                    } 
    131131                    VarDeclaration *v2 = (VarDeclaration *)ad->fields.data[k]; 
    132132 
    133133                    if (v2->offset < offset2 && dts.data[k]) 
    134134                        break;                  // overlap 
    135135                } 
    136136            } 
    137137        } 
    138138        if (d) 
    139139        { 
    140140            if (v->offset < offset) 
    141141                error(loc, "duplicate union initialization for %s", v->toChars()); 
    142142            else 
    143143            {   unsigned sz = dt_size(d); 
    144144                unsigned vsz = v->type->size(); 
    145145                unsigned voffset = v->offset; 
     146 
     147                if (sz > vsz) 
     148                {   assert(v->type->ty == Tsarray && vsz == 0); 
     149                    error(loc, "zero length array %s has non-zero length initializer", v->toChars()); 
     150                } 
    146151 
    147152                unsigned dim = 1; 
    148153                for (Type *vt = v->type->toBasetype(); 
    149154                     vt->ty == Tsarray; 
    150155                     vt = vt->next->toBasetype()) 
    151156                {   TypeSArray *tsa = (TypeSArray *)vt; 
    152157                    dim *= tsa->dim->toInteger(); 
    153158                } 
    154159                //printf("sz = %d, dim = %d, vsz = %d\n", sz, dim, vsz); 
    155160                assert(sz == vsz || sz * dim <= vsz); 
    156161 
    157162                for (size_t i = 0; i < dim; i++) 
    158163                { 
    159164                    if (offset < voffset) 
    160165                        pdtend = dtnzeros(pdtend, voffset - offset); 
    161166                    if (!d) 
    162167                    { 
    163168                        if (v->init) 
    164169                            d = v->init->toDt(); 
    165170                        else 
     
    672677                    if (k == dts.dim)           // didn't find any overlap 
    673678                    { 
    674679                        v->type->toDt(&d); 
    675680                        break; 
    676681                    } 
    677682                    VarDeclaration *v2 = (VarDeclaration *)sd->fields.data[k]; 
    678683 
    679684                    if (v2->offset < offset2 && dts.data[k]) 
    680685                        break;                  // overlap 
    681686                } 
    682687            } 
    683688        } 
    684689        if (d) 
    685690        { 
    686691            if (v->offset < offset) 
    687692                error("duplicate union initialization for %s", v->toChars()); 
    688693            else 
    689694            {   unsigned sz = dt_size(d); 
    690695                unsigned vsz = v->type->size(); 
    691696                unsigned voffset = v->offset; 
    692                 assert(sz <= vsz); 
     697 
     698                if (sz > vsz) 
     699                {   assert(v->type->ty == Tsarray && vsz == 0); 
     700                    error("zero length array %s has non-zero length initializer", v->toChars()); 
     701                } 
    693702 
    694703                unsigned dim = 1; 
    695704                Type *vt; 
    696705                for (vt = v->type->toBasetype(); 
    697706                     vt->ty == Tsarray; 
    698707                     vt = vt->next->toBasetype()) 
    699708                {   TypeSArray *tsa = (TypeSArray *)vt; 
    700709                    dim *= tsa->dim->toInteger(); 
    701710                } 
     711 
     712                //printf("sz = %d, dim = %d, vsz = %d\n", sz, dim, vsz); 
     713                assert(sz == vsz || sz * dim <= vsz); 
    702714 
    703715                for (size_t i = 0; i < dim; i++) 
    704716                { 
    705717                    if (offset < voffset) 
    706718                        pdt = dtnzeros(pdt, voffset - offset); 
    707719                    if (!d) 
    708720                    { 
    709721                        if (v->init) 
    710722                            d = v->init->toDt(); 
    711723                        else 
    712724                            vt->toDt(&d); 
    713725                    } 
    714726                    pdt = dtcat(pdt, d); 
    715727                    d = NULL; 
    716728                    offset = voffset + sz; 
    717729                    voffset += vsz / dim; 
    718730                    if (sz == vsz) 
    719731                        break; 
    720732                } 
    721733            } 
  • trunk/src/todt.c

    r745 r823  
    126126                    if (k == dts.dim)           // didn't find any overlap 
    127127                    { 
    128128                        v->type->toDt(&d); 
    129129                        break; 
    130130                    } 
    131131                    VarDeclaration *v2 = (VarDeclaration *)ad->fields.data[k]; 
    132132 
    133133                    if (v2->offset < offset2 && dts.data[k]) 
    134134                        break;                  // overlap 
    135135                } 
    136136            } 
    137137        } 
    138138        if (d) 
    139139        { 
    140140            if (v->offset < offset) 
    141141                error(loc, "duplicate union initialization for %s", v->toChars()); 
    142142            else 
    143143            {   unsigned sz = dt_size(d); 
    144144                unsigned vsz = v->type->size(); 
    145145                unsigned voffset = v->offset; 
     146 
     147                if (sz > vsz) 
     148                {   assert(v->type->ty == Tsarray && vsz == 0); 
     149                    error(loc, "zero length array %s has non-zero length initializer", v->toChars()); 
     150                } 
    146151 
    147152                unsigned dim = 1; 
    148153                for (Type *vt = v->type->toBasetype(); 
    149154                     vt->ty == Tsarray; 
    150155                     vt = vt->nextOf()->toBasetype()) 
    151156                {   TypeSArray *tsa = (TypeSArray *)vt; 
    152157                    dim *= tsa->dim->toInteger(); 
    153158                } 
    154159                //printf("sz = %d, dim = %d, vsz = %d\n", sz, dim, vsz); 
    155160                assert(sz == vsz || sz * dim <= vsz); 
    156161 
    157162                for (size_t i = 0; i < dim; i++) 
    158163                { 
    159164                    if (offset < voffset) 
    160165                        pdtend = dtnzeros(pdtend, voffset - offset); 
    161166                    if (!d) 
    162167                    { 
    163168                        if (v->init) 
    164169                            d = v->init->toDt(); 
    165170                        else 
     
    669674                    if (k == dts.dim)           // didn't find any overlap 
    670675                    { 
    671676                        v->type->toDt(&d); 
    672677                        break; 
    673678                    } 
    674679                    VarDeclaration *v2 = (VarDeclaration *)sd->fields.data[k]; 
    675680 
    676681                    if (v2->offset < offset2 && dts.data[k]) 
    677682                        break;                  // overlap 
    678683                } 
    679684            } 
    680685        } 
    681686        if (d) 
    682687        { 
    683688            if (v->offset < offset) 
    684689                error("duplicate union initialization for %s", v->toChars()); 
    685690            else 
    686691            {   unsigned sz = dt_size(d); 
    687692                unsigned vsz = v->type->size(); 
    688693                unsigned voffset = v->offset; 
    689                 assert(sz <= vsz); 
     694 
     695                if (sz > vsz) 
     696                {   assert(v->type->ty == Tsarray && vsz == 0); 
     697                    error("zero length array %s has non-zero length initializer", v->toChars()); 
     698                } 
    690699 
    691700                unsigned dim = 1; 
    692701                Type *vt; 
    693702                for (vt = v->type->toBasetype(); 
    694703                     vt->ty == Tsarray; 
    695704                     vt = vt->nextOf()->toBasetype()) 
    696705                {   TypeSArray *tsa = (TypeSArray *)vt; 
    697706                    dim *= tsa->dim->toInteger(); 
    698707                } 
     708                //printf("sz = %d, dim = %d, vsz = %d\n", sz, dim, vsz); 
     709                assert(sz == vsz || sz * dim <= vsz); 
    699710 
    700711                for (size_t i = 0; i < dim; i++) 
    701712                { 
    702713                    if (offset < voffset) 
    703714                        pdt = dtnzeros(pdt, voffset - offset); 
    704715                    if (!d) 
    705716                    { 
    706717                        if (v->init) 
    707718                            d = v->init->toDt(); 
    708719                        else 
    709720                            vt->toDt(&d); 
    710721                    } 
    711722                    pdt = dtcat(pdt, d); 
    712723                    d = NULL; 
    713724                    offset = voffset + sz; 
    714725                    voffset += vsz / dim; 
    715726                    if (sz == vsz) 
    716727                        break; 
    717728                } 
    718729            }