www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11553] New: dmd segfault with recursive template

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

           Summary: dmd segfault with recursive template
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: john.loughran.colvin gmail.com


--- Comment #0 from John Colvin <john.loughran.colvin gmail.com> 2013-11-19
12:39:23 GMT ---
An example that is clearly wrong code, but segfaults the compiler on
Scope::push

template A(alias T)
{
    template A()
    {
    alias A = T!();
    }
}
alias B() = A!(.B);

static if(A!B){}


I have similar but correct code that triggers the same fault, I'll add it when
I've minimised it properly.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 19 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11553



--- Comment #1 from John Colvin <john.loughran.colvin gmail.com> 2013-11-19
13:45:55 GMT ---
Ok this is proving near impossible to reduce. Changing the slightest things
moves the segfault to different parts of the compiler and it's very hard to
find examples that are correct and fail. I've seen 

Scope::Scope(Scope*),

functionResolve(Match*, Dsymbol*, Loc, Scope*, Array<RootObject>*, Type*,
Array<Expression>*)::ParamDeduce::fp(TemplateDeclaration*),

TemplateInstance::findBestMatch(Scope*, Array<Expression>*) (), 

TemplateTupleParameter::matchArg(Loc, Scope*, Array<RootObject>*, unsigned
long, Array<TemplateParameter>*, Array<RootObject>*, Declaration**) (),

Dsymbol::Dsymbol()

so far, if that's of any help at all.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11553


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com


--- Comment #2 from yebblies <yebblies gmail.com> 2013-11-20 01:07:34 EST ---
(In reply to comment #1)
 Ok this is proving near impossible to reduce. Changing the slightest things
 moves the segfault to different parts of the compiler and it's very hard to
 find examples that are correct and fail. I've seen 
 
 Scope::Scope(Scope*),
 
 functionResolve(Match*, Dsymbol*, Loc, Scope*, Array<RootObject>*, Type*,
 Array<Expression>*)::ParamDeduce::fp(TemplateDeclaration*),
 
 TemplateInstance::findBestMatch(Scope*, Array<Expression>*) (), 
 
 TemplateTupleParameter::matchArg(Loc, Scope*, Array<RootObject>*, unsigned
 long, Array<TemplateParameter>*, Array<RootObject>*, Declaration**) (),
 
 Dsymbol::Dsymbol()
 
 so far, if that's of any help at all.

It's jumping around because the segfault is a stack overflow. Chances are any segfault you see will be the same thing underneath. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11553



--- Comment #3 from John Colvin <john.loughran.colvin gmail.com> 2013-11-19
14:42:42 GMT ---
Finally, a correct (should compile) example that causes a segfault. It's still
a little large, sorry:

struct Pack(T ...)
{
    alias Unpack = T;
    enum length = T.length;
}

template isPack(TList ...)
{
    static if(TList.length == 1 &&
          is(Pack!(TList[0].Unpack) == TList[0]))
    {
    enum isPack = true;
    }
    else
    {
    enum isPack = false;
    }
}

template PartialApply(alias T, uint argLoc, Arg ...)
    if(Arg.length == 1)
{
    template PartialApply(L ...)
    {
    alias PartialApply = T!(L[0 .. argLoc], Arg, L[argLoc .. $]);
    }
}

template _hasLength(size_t len, T)
{
    static if(T.length == len)
    {
    enum _hasLength = true;
    }
    else
    {   
    enum _hasLength = false;
    }
}

alias _hasLength(size_t len) = PartialApply!(._hasLength, 0, len);


alias hl1 = _hasLength!1;

//this segfaults
static if(!isPack!hl1){ pragma(msg, "All good 1"); }

//these are fine
static if(hl1!(Pack!(5))) { pragma(msg, "All good 2"); }

static if(!hl1!(Pack!())) { pragma(msg, "All good 3"); }


The result:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000434a45 in Dsymbol::Dsymbol(Identifier*) ()

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11553


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice, pull


--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2013-11-19 07:48:46 PST ---
https://github.com/D-Programming-Language/dmd/pull/2826

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11553



--- Comment #5 from John Colvin <john.loughran.colvin gmail.com> 2013-11-19
16:24:25 GMT ---
Thanks Kenji, that fixes the problem in my full code-base too.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11553



--- Comment #6 from github-bugzilla puremagic.com 2014-01-05 12:27:15 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/fcd656147f10ec53f68df473883ddc68aaee546e
fix Issue 11553 - dmd segfault with recursive template

https://github.com/D-Programming-Language/dmd/commit/a78295a1c99299880c8c8adb475688d1e1ae8484
Merge pull request #2826 from 9rnsr/fix11553

Issue 11553 - dmd segfault with recursive template

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 05 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11553


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: -------
Jan 05 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11553


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |regression


--- Comment #7 from Kenji Hara <k.hara.pg gmail.com> 2014-01-07 02:31:10 PST ---
(In reply to comment #0)
 An example that is clearly wrong code, but segfaults the compiler on
 Scope::push
 
 template A(alias T)
 {
     template A()
     {
     alias A = T!();
     }
 }
 alias B() = A!(.B);
 
 static if(A!B){}

With 2.063, following equivalent code did not cause segfault. template A(alias T) { template A() { alias A = T!(); } } template B() { alias B = A!(.B); } static if (A!B) {} // Line 9 Output: test.d(9): Error: expression template A() of type void does not have a boolean value -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 07 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11553



--- Comment #8 from github-bugzilla puremagic.com 2014-01-07 02:33:10 PST ---
Commit pushed to 2.065 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/e1866902b88e36537197da16b098afd2df304425
Merge pull request #2826 from 9rnsr/fix11553

Issue 11553 - dmd segfault with recursive template

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