Bug 15002 – [REG2.064] ICE with invalid static variable initializer while CTFE
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-09-02T06:58:00Z
Last change time
2015-09-07T13:37:03Z
Keywords
ice, pull
Assigned to
nobody
Creator
dmitry.olsh
Comments
Comment #0 by dmitry.olsh — 2015-09-02T06:58:48Z
First fruit of porting CSmith to produce C-style D code.
/*
* This is a RANDOMLY GENERATED PROGRAM.
*
* Generator: csmith 2.3.0
* Git version: ce427da
* Options: (none)
* Seed: 2230835337
*/
int [][3]g_3 = [];
int *g_2 = &g_3[5][0];
Comment #1 by dlang-bugzilla — 2015-09-02T07:18:26Z
(In reply to Vladimir Panteleev from comment #1)
> This seems to be a regression.
>
> Introduced in https://github.com/D-Programming-Language/dmd/pull/2129
Regression? Regression from what? Wrong-code to ICE? Valid to ICE? ICE to another ICE?
Comment #3 by dlang-bugzilla — 2015-09-02T08:16:32Z
(In reply to Iain Buclaw from comment #2)
> Regression? Regression from what? Wrong-code to ICE? Valid to ICE? ICE
> to another ICE?
From expected error message, to expected error message + ICE:
C:\Temp\D\issues\15002> dver 2.063 dmd -o- test.d
test.d(11): Error: array index 5 is out of bounds g_3[0 .. 3]
test.d(11): Error: cannot use non-constant CTFE pointer in an initializer '&(__error)[0u]'
C:\Temp\D\issues\15002> dver 2.064 dmd -o- test.d
(auto-correcting D version 2.064 to 2.064.2)
test.d(11): Error: array index 5 is out of bounds g_3[0 .. 3]
test.d(11): Error: array index 5 is out of bounds g_3[0 .. 3]
CTFE: ErrorExp in test.d(11)
Assertion failure: '0' on line 310 in file 'interpret.c'
abnormal program termination
Comment #4 by ibuclaw — 2015-09-02T08:30:22Z
(In reply to Vladimir Panteleev from comment #3)
> (In reply to Iain Buclaw from comment #2)
> > Regression? Regression from what? Wrong-code to ICE? Valid to ICE? ICE
> > to another ICE?
>
> From expected error message, to expected error message + ICE:
>
It looks like CTFE still tries to have a go at interpreting the invalid code. All that change does is enforce that the front-end never passes to CTFE an invalid state, so don't shoot the messenger!
Something like the following stops the invalid code from reaching CTFE:
diff --git a/src/init.d b/src/init.d
index dd9db91..1e53e22 100644
--- a/src/init.d
+++ b/src/init.d
@@ -822,15 +822,15 @@ public:
Initializer semantic(Scope* sc, Type t, NeedInterpret needInterpret)
{
//printf("ExpInitializer::semantic(%s), type = %s\n", exp->toChars(), t->toChars());
+ uint olderrors = global.errors;
if (needInterpret)
sc = sc.startCTFE();
exp = exp.semantic(sc);
exp = resolveProperties(sc, exp);
if (needInterpret)
sc = sc.endCTFE();
- if (exp.op == TOKerror)
+ if (exp.op == TOKerror || olderrors != global.errors)
return new ErrorInitializer();
- uint olderrors = global.errors;
if (needInterpret)
{
// If the result will be implicitly cast, move the cast into CTFE
Though the semantic passes should *really* do more in propagating ErrorExp up rather than relying on checking 'global.errors' for checking for problems during compilation.