www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5064] New: Crash related to std.algorithm.map, delegates, and casts

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064

           Summary: Crash related to std.algorithm.map, delegates, and
                    casts
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: code klickverbot.at


--- Comment #0 from klickverbot <code klickverbot.at> 2010-10-16 13:29:55 PDT
---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 16 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064


klickverbot <code klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code


--- Comment #1 from klickverbot <code klickverbot.at> 2010-10-16 13:44:03 PDT
---
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?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064



--- Comment #2 from klickverbot <code klickverbot.at> 2010-10-16 13:58:43 PDT
---
The crash does not occur if the executable is compiled with -inline.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064



--- Comment #3 from Don <clugdbug yahoo.com.au> 2010-11-08 00:05:17 PST ---
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 ] );
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064



--- Comment #4 from Don <clugdbug yahoo.com.au> 2010-11-23 01:25:27 PST ---
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();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 23 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|andrei metalanguage.com     |bugzilla digitalmars.com


--- Comment #5 from Andrei Alexandrescu <andrei metalanguage.com> 2011-01-16
14:30:09 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 16 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|x86_64                      |x86


--- Comment #6 from Brad Roberts <braddr puremagic.com> 2011-02-06 15:41:02 PST
---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com


--- Comment #7 from SomeDude <lovelydear mailmetrash.com> 2012-04-21 15:58:29
PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW
         AssignedTo|bugzilla digitalmars.com    |nobody puremagic.com
            Summary|std.algorithm.map,          |runtime crash using closure
                   |delegates and cast(dchar) = |as alias parameter
                   |runtime crash               |
         OS/Version|Linux                       |All


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg gmail.com


--- Comment #8 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2012-06-17
15:45:23 MSD ---
Looks close to Issue 7965 (especially a requirement of explicit field
initialization)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5064


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |maxim maxim-fomin.ru
         Resolution|                            |FIXED


--- Comment #9 from Maxim Fomin <maxim maxim-fomin.ru> 2012-12-27 08:05:32 PST
---
Fixed in issue 8774

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 27 2012