Thread overview
[Issue 12044] New: Invalid code gen causes segfault
Jan 31, 2014
Vladimir Panteleev
Jan 31, 2014
Vladimir Panteleev
Feb 04, 2014
Vladimir Panteleev
Feb 04, 2014
Vladimir Panteleev
Feb 14, 2014
Walter Bright
Feb 15, 2014
Kenji Hara
January 30, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12044

           Summary: Invalid code gen causes segfault
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: jcrapuchettes@gmail.com


--- Comment #0 from Jonathan Crapuchettes <jcrapuchettes@gmail.com> 2014-01-30 13:40:00 PST ---
The following code example was tested with 2.063.2 and executes without error. If compiled with 2.064.2 or 2.065.0-b2, the example compiles, but segfaults when run.

In the example, commenting or changing most of the lines will allow 2.064.2+ to produce code that does not segfault.

Backtrace output from gdb at point of segfault:
----------------
(gdb) bt
#0  0x000000000042d9eb in _d_arrayliteralTX ()
#1  0x0000000000429dcd in valid_sparse.main() (this=0x0) at valid_sparse.d:32
#2  0x000000000042a57f in valid_sparse.Test.__T8opBinaryVAyaa2_696eZ.opBinary()
(this=0x7fffffffdad8, fun=...) at valid_sparse.d:42
#3  0x0000000000429da2 in D main () at valid_sparse.d:26
#4  0x000000000042cf20 in rt.dmain2._d_run_main() ()
#5  0x000000000042ce7a in rt.dmain2._d_run_main() ()
#6  0x000000000042cee0 in rt.dmain2._d_run_main() ()
#7  0x000000000042ce7a in rt.dmain2._d_run_main() ()
#8  0x000000000042cdfb in _d_run_main ()
#9  0x000000000042ae25 in main ()

Example:
----------------
import std.array;
import std.traits;
import std.algorithm;

struct BasicNode(T) { T id; }
struct Hierarchy(Code)
{
    struct Node { Code id; }

    Node[] allNodes;

    bool opEquals(OtherH)(OtherH )
    {
        allNodes.map!("a.id").array;
    }
}

struct Test
{
    void opBinary(string op)(void delegate() fun)
    {
        fun();
    }
}

void main()
{
    Test() in
    {
        enum BlaEnum : ubyte { All }

        auto Blas = [EnumMembers!BlaEnum].map!(a => BasicNode!BlaEnum(a));

        Hierarchy!(BlaEnum) H_T;
    };
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 31, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12044


Vladimir Panteleev <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow@gmail.com


--- Comment #1 from Vladimir Panteleev <thecybershadow@gmail.com> 2014-01-31 04:45:14 EET ---
On Win32, it compiles and runs. On Win64 there is a linker error (duplicate
COMDAT).

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 31, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12044



--- Comment #2 from Vladimir Panteleev <thecybershadow@gmail.com> 2014-01-31 05:02:24 EET ---
The linker error starts appearing after this pull:

https://github.com/D-Programming-Language/phobos/pull/1305

However, that pull likely uncovered the problem rather than introduced a regression.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 04, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12044



--- Comment #3 from Vladimir Panteleev <thecybershadow@gmail.com> 2014-02-04 23:14:56 EET ---
I reran the bisection on Linux/64, where I could reproduce the original problem. But the bisection identified the same change as the regression: https://github.com/D-Programming-Language/phobos/pull/1305

I'll try to reduce away the Phobos dependency.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 04, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12044


Vladimir Panteleev <thecybershadow@gmail.com> changed:

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


--- Comment #4 from Vladimir Panteleev <thecybershadow@gmail.com> 2014-02-05 01:00:09 EET ---
Reduced test case:

//////////////////////////////////////////
struct S(T)
{
    void f()()
    {
        new T[1];
    }

    bool opEquals(O)(O)
    {
        f();
    }
}

void main()
{
    ()
    {
        enum E { e }
        auto arr = [E.e];
        S!E s;
    }
    ();
}
//////////////////////////////////////////

On Win64, this produces the error:
test.exe.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT
'_D45TypeInfo_AE4test4mainFZv9__lambda1FNaNbNfZv1E6__initZ'

As I suspected, the Phobos change only uncovered a compiler problem.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 14, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12044


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2014-02-14 01:52:49 PST ---
https://github.com/D-Programming-Language/dmd/pull/3257

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 15, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12044



--- Comment #6 from github-bugzilla@puremagic.com 2014-02-14 17:45:08 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/6a0618afd2c73dab691ed5d66366ec0529377abf fix Issue 12044 - Invalid code gen causes segfault

https://github.com/D-Programming-Language/dmd/commit/4529423afa9fdd437415652ebf5f7d436747910c Merge pull request #3257 from WalterBright/fix12044

fix Issue 12044 - Invalid code gen causes segfault

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 15, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12044


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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