D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3246 - ICE(init.c) using indexed array initializer on local array
Summary: ICE(init.c) using indexed array initializer on local array
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2009-08-12 05:27 UTC by Don
Modified: 2014-04-18 09:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2009-08-12 05:27:29 UTC
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 Walter Bright 2009-09-03 13:27:57 UTC
Fixed dmd 1.047 and 2.032