D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2829 - ICE(expression.c) static array block-initialized in struct literal
Summary: ICE(expression.c) static array block-initialized in struct literal
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: Walter Bright
URL:
Keywords: ice-on-invalid-code, patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2009-04-10 03:59 UTC by Christian Kamm
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 Christian Kamm 2009-04-10 03:59:18 UTC
struct S { int[3] i; }
const S s = S(5);
const int i = s.i[10];

generates

int[3u] 0x82ee4e0
dmd: expression.c:1352: virtual dinteger_t IntegerExp::toInteger(): Assertion `0' failed.
Aborted
Comment 1 Don 2009-06-02 16:25:14 UTC
Title was: ICE(expression.c) accessing out of bounds element in a static array constant initialized through struct literal
Changed since it is more general. Applies to D2 as well as D1.

-- ANALYSIS --
This is crashing in constfold.c, line 1218, crashing while doing e1->toChars() while printing the error message. But there are also rejects-valid bugs with the
same root cause: block assignment of arrays is buggy.
The root cause is expression.c, StructLiteralExp::getField().
In the line e->type=type is incorrect if e->type is of type K, and 'type' 
is a static array of type K.
PATCH: in such cases, create and populate an array literal.

--- expression.c	(revision 27)
+++ expression.c	(working copy)
@@ -3236,7 +3236,18 @@
 	if (e)
 	{
 	    e = e->copy();
+    if (e->type != type && type->ty == Tsarray)
+    {	TypeSArray *tsa = (TypeSArray *)type;
+			uinteger_t length = tsa->dim->toInteger();
+			Expressions * z = new Expressions;
+			z->setDim(length);
+			for (int q=0; q<length; ++q) z->data[q] = e->copy();
+			ArrayLiteralExp * ac = new ArrayLiteralExp(loc, z);
+			ac -> type = type;
+			e = ac;
+		} else {
 	    e->type = type;
+		}
 	}
     }
     return e;

== TEST CASE 2 -- ICE(expression.c) == For D2, change 'enum' to 'const' for D1.
struct S { int i[3]; }
enum S s = S(8);
int * p  = & s.i;

// Test case 3 -- rejects-valid
struct Q { double i[3]; }
enum Q q = Q(8.0*real.min);
const  x = q.i[2];
Comment 2 Walter Bright 2009-10-13 13:44:51 UTC
Fixed dmd 1.049 and 2.034