Bug 3026 – Segfault with incomplete static array initializer

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2009-05-26T14:34:00Z
Last change time
2015-06-09T01:27:57Z
Keywords
ice-on-valid-code, patch, rejects-valid
Assigned to
bugzilla
Creator
rsinfu

Attachments

IDFilenameSummaryContent-TypeSize
382bug_arrayinit_toexpr.patchFix the problem (dmd 2.030)text/plain1426
390fix_arrayinit_fwdref.patchAdditional patch: fix segfault on fwdreftext/plain623

Comments

Comment #0 by rsinfu — 2009-05-26T14:34:44Z
Created attachment 382 Fix the problem (dmd 2.030) DMD dies without any error message compiling this valid code: -------------------- immutable int[2] array = [ 42 ]; enum e = array[1]; -------------------- The array initializer in this code contains one element. In this case ArrayInitializer::toExpression() wrongly generates an ArrayLiteralExp of one element, not two elements (notice the int[2]). Then DMD references missing second element, and dies. The patch fixes this problem. And DMD rejects this valid code: -------------------- immutable int[1] array = [ 0: 42 ]; enum e = array[0]; -------------------- test.d(1): Error: array initializers as expressions are not allowed test.d(1): Error: array initializers as expressions are not allowed test.d(1): Error: array initializers as expressions are not allowed test.d(1): Error: array initializers as expressions are not allowed -------------------- ArrayInitializer::toExpression() does not implement support for array index in static array initializers. The patch also implements it.
Comment #1 by rsinfu — 2009-06-04T10:06:13Z
Created attachment 390 Additional patch: fix segfault on fwdref ArrayInitializer will cause a segfault when it's forward referenced. Please apply this patch in addition to the first patch.
Comment #2 by bugzilla — 2009-07-09T02:51:01Z
Fixed dmd 1.046 and 2.031