Bug 5064 – runtime crash using closure as alias parameter

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2010-10-16T13:29:00Z
Last change time
2012-12-27T08:05:32Z
Keywords
wrong-code
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2010-10-16T13:29:55Z
The following program crashes using DMD 2.049 on Linux x86_64 and DMD 2.048 on OS X x86_64: --- import std.algorithm; void main() { foreach ( offset; 0 .. 26 ) { map!( ( c ){ return cast( dchar )offset; } )( "asdf" ); } } --- If you remove the cast to dchar, the segmentation fault does no longer occur.
Comment #1 by code — 2010-10-16T13:44:03Z
The foreach loop is not needed, another temporary »works« as well: --- import std.algorithm; void main() { auto a = 1; auto dg = ( uint c ){ return cast( dchar )a; }; // This works: dg( 1 ); // This crashes: map!( ( c ){ return dg( c ); } )( [ 1 ] ); } --- GDB prints the innermost frame like this: 0x08049846 in ave.main.__dgliteral2!(int).__dgliteral2 (this=0x0, c=1) at ave.d:11 Note that this is null – could this be an issue, or is this relative to the current frame?
Comment #2 by code — 2010-10-16T13:58:43Z
The crash does not occur if the executable is compiled with -inline.
Comment #3 by clugdbug — 2010-11-08T00:05:17Z
Reduced test case. Possibly related to bug 1350. struct Map(alias fun) { dchar xxx; this(int[] input) { fun(input[0]); } } void main() { auto dg = ( int c ){ return cast(dchar)'x'; }; Map!( ( c ){ return dg( c ); } )( [ 1 ] ); }
Comment #4 by clugdbug — 2010-11-23T01:25:27Z
Further reduced. Shows it is caused by an closure passed as an alias parameter, + a struct with initialized members. If you remove the '=7', it won't crash. ---- struct Map5064(alias fun) { int xxx = 7; void crash() { fun(); } } void bug5064() { void delegate() dg = (){ }; Map5064!( dg ) q; q.crash(); } void main() { bug5064(); }
Comment #5 by andrei — 2011-01-16T14:30:09Z
Reassigning to Walter (Don, of course you're kindly invited to look into it); I thought this is a Phobos issue, but it's a dmd issue.
Comment #6 by braddr — 2011-02-06T15:41:02Z
Mass migration of bugs marked as x86-64 to just x86. The platform run on isn't what's relevant, it's if the app is a 32 or 64 bit app.
Comment #7 by lovelydear — 2012-04-21T15:58:29Z
I've noted that the issue is on x86_64, but FYI, on 2.059 Win32 the cases in description and comment 1 run fine (even without -inline), while Don's test cases produce an access violation.
Comment #8 by verylonglogin.reg — 2012-06-17T04:45:23Z
Looks close to Issue 7965 (especially a requirement of explicit field initialization)
Comment #9 by maxim — 2012-12-27T08:05:32Z
Fixed in issue 8774