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 :)
Comment #1 by doob — 2013-06-16T08:00:18Z
Comment #2 by k.hara.pg — 2013-06-16T18:36:36Z
(In reply to comment #1) > Link to the commit introducing the guard: > > https://github.com/D-Programming-Language/dmd/commit/c28df7d72e72f6c0c3bb389538afb1871b7ad15c My past bug fix for bug 7814 was essentially incorrect, because it was caused by bug 10049. https://github.com/D-Programming-Language/dmd/pull/2190
Comment #3 by github-bugzilla — 2013-06-17T14:25:57Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a80d2893f693f9dbe87fb2528d79287c1ef52bf4 fix Issue 10382 - ICE when catching illegal type https://github.com/D-Programming-Language/dmd/commit/1f0af1f141caa1bc8e67116821e6cca84dae8b88 Merge pull request #2190 from 9rnsr/fix10382 [REG2.059] Issue 10382 - ICE when catching illegal type
Comment #4 by github-bugzilla — 2013-06-17T14:27:13Z
Commit pushed to 2.063 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/60e5b0a5b1196a71bfe5cef4f67a05ac22d9975f Merge pull request #2190 from 9rnsr/fix10382 [REG2.059] Issue 10382 - ICE when catching illegal type
Comment #5 by doob — 2013-06-17T23:52:43Z
Thanks.