D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3344 - ICE(e2ir.c) returning an invalid function from main()
Summary: ICE(e2ir.c) returning an invalid function from main()
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2009-09-25 05:31 UTC by Haruki Shigemori
Modified: 2014-02-15 13:13 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Haruki Shigemori 2009-09-25 05:31:50 UTC
>type main.d
void f(T)(){}
void main()
{
        return f;
}

>dmd main
f(T)
Internal error: e2ir.c 644
Comment 1 Don 2009-09-25 05:38:45 UTC
Not a D2 bug. Fails even in DMD 0.165.
Comment 2 Don 2009-09-29 01:24:49 UTC
This is clearly invalid code.
Comment 3 Don 2009-09-29 01:24:55 UTC
This is happening because when return exp; is changed into exp; return;, the 
semantic pass never gets run on the expression.

-------
PATCH: iin statement.c, around line 3464, in Statement 
*ReturnStatement::semantic(Scope *sc)

=====
    /* Replace:
     *    return exp;
     * with:
     *    exp; return;
     */
    Statement *s = new ExpStatement(loc, exp);
+    s->semantic(sc); 
==========

CAUTION:
This patch also disallows code like " void foo() { return 7; }"
This shows up several bugs in Phobos and in the DMD test suite.
If there's a reason why such bug-prone code should continue to be accepted, a 
more complicated patch will be required.
Comment 4 Walter Bright 2009-10-13 13:48:24 UTC
Fixed dmd 1.049 and 2.034