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



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




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




 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




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



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




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




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


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




 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




Commit pushed to 2.065 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/e1866902b88e36537197da16b098afd2df304425


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