Bug 3246 – ICE(init.c) using indexed array initializer on local array

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Windows
Creation time
2009-08-12T05:27:00Z
Last change time
2014-04-18T09:12:03Z
Keywords
ice-on-invalid-code, patch
Assigned to
nobody
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2009-08-12T05:27:29Z
Reported by Ali Cehreli. void main() { int[4] static_1 = [ 3:212 ]; } PATCH against DMD2.031. We need to make sure the array literal is big enough to include the last mentioned element. We need to return ErrorExp, not NULL, otherwise it will still segfault on cases like int[4] x = [32: 1]; because VerDeclaration::semantic assumes a NULL result means that it should run semantic on the initializer. Index: init.c =================================================================== --- init.c (revision 194) +++ init.c (working copy) @@ -422,6 +422,13 @@ else edim = value.dim; + for (size_t i = 0, j = 0; i < value.dim; i++, j++) + { + if (index.data[i]) + j = ((Expression *)index.data[i])->toInteger(); + if (j >=edim) edim = j+1; + } + elements = new Expressions(); elements->setDim(edim); for (size_t i = 0, j = 0; i < value.dim; i++, j++) @@ -464,7 +471,7 @@ Lno: delete elements; error(loc, "array initializers as expressions are not allowed"); - return NULL; + return new ErrorExp(); }
Comment #1 by bugzilla — 2009-09-03T13:27:57Z
Fixed dmd 1.047 and 2.032