Bug 10382 – Regression (2.059): ICE when catching illegal type
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-16T07:56:00Z
Last change time
2013-06-17T23:52:43Z
Keywords
ice, pull
Assigned to
nobody
Creator
doob
Comments
Comment #0 by doob — 2013-06-16T07:56:19Z
The following results in a segmentation fault:
void main ()
{
try
{
int b = 3;
}
catch (int a) { }
}
I think the problem is that the compiler doesn't perform semantic analyzes in all cases on catch statements.
https://github.com/D-Programming-Language/dmd/blob/master/src/statement.c#L4561
If the if-statement and return is removed from statement.c#L4561 everything works correctly. This guard for the semantic analyze was added for a reason, in this commit:
c28df7d72e72f6c0c3bb389538afb1871b7ad15c
DMD checks the "type" instance variable to determine if the semantic analyze has been run for a given statement. The problem in this case is this piece of code:
https://github.com/D-Programming-Language/dmd/blob/master/src/parse.c#L4641
This will set "type" on the Catch statement in the constructor. When the compiler then comes to run the semantic analyze on the Catch statement it thinks it's already been run. To me it seems it's not reliable to check "type" if the semantic analyze has been run. Perhaps add a new flag?
The ICE will only happen if there's some code in the try-statement. If I remove the code in the try-statement I can basically put whatever I want in the catch-statement, that is syntactically correct, without the compiler complaining. This compiles fine:
void main ()
{
try
{
}
catch (int sdf)
{
asd;
a * + 4;
a b;
}
}
I'm a bit surprised that this regression has been available for so long. I actually only found it by inspecting the source code of DMD. Then I was able to produce a test case. Seems people always write their catch-statements correctly :)