Bug 2577 – DMD crashes on foreach of undefined identifier
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2009-01-10T19:11:00Z
Last change time
2015-06-09T01:21:02Z
Keywords
ice-on-invalid-code, patch
Assigned to
bugzilla
Creator
smjg
Comments
Comment #0 by smjg — 2009-01-10T19:11:33Z
----------
void main() {
foreach (element; undef) {
fn(element);
}
}
void fn(int i) {}
----------
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd foreach_undef.d
foreach_undef.d(2): Error: undefined identifier undef
foreach_undef.d(2): Error: foreach: int is not an aggregate type
----------
followed by a Windows application failure dialog, showing the details:
----------
Problem signature:
Problem Event Name: APPCRASH
Application Name: dmd.exe
Application Version: 0.0.0.0
Application Timestamp: 00000000
Fault Module Name: dmd.exe
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 00000000
Exception Code: c0000005
Exception Offset: 0001ccec
OS Version: 6.0.6001.2.1.0.768.3
Locale ID: 2057
Additional Information 1: 64bb
Additional Information 2: a42ac0f0b295811241a2caffb74a0ff1
Additional Information 3: b17c
Additional Information 4: af2368a443111b924ca617c6f294878c
Read our privacy statement:
http://go.microsoft.com/fwlink/?linkid=50163&clcid=0x0409
----------
Specifying the type of element makes no difference. If element is unused inside the for loop, the crash disappears.
Comment #1 by matti.niemenmaa+dbugzilla — 2009-01-13T10:16:28Z
*** Bug 2583 has been marked as a duplicate of this bug. ***
Comment #2 by smjg — 2009-03-05T19:55:40Z
*** Bug 2709 has been marked as a duplicate of this bug. ***
Comment #3 by clugdbug — 2009-04-02T15:42:36Z
in expression.c, in CallExp::canThrow(), around line 6660, type will be null if the expression was invalid. Adding a null check fixes the segfault.
/* If calling a function or delegate that is typed as nothrow,
* then this expression cannot throw.
* Note that pure functions can throw.
*/
if (!e1->type) return 0; // ---- add this line
Type *t = e1->type->toBasetype();
if (t->ty == Tfunction && ((TypeFunction *)t)->isnothrow)
return 0;