D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19661 - DMD 2.084.0 SIGSEGV in std.traits.isFunction
Summary: DMD 2.084.0 SIGSEGV in std.traits.isFunction
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: ice, pull
Depends on:
Blocks:
 
Reported: 2019-02-08 10:24 UTC by Adam Wilson
Modified: 2020-03-21 03:56 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Adam Wilson 2019-02-08 10:24:13 UTC
This code produces a SIGSEGV in DMD 2.084.0 when attempting to find all functions in the same module as the code itself is in.

module test;

public immutable bool testModule = testFunctionMembers!"test";

public void testFunctionMembers(string module_)() {
    import std.traits : isFunction;
    mixin(`import dmodule = ` ~ module_ ~ `;`);
    foreach(member; __traits(allMembers, dmodule)) {
        const bool isfunc = isFunction!(__traits(getMember, dmodule, member));
    }
}
Comment 1 Hiroki Noda 2019-04-18 13:38:59 UTC
I tried this in dmd 2.085.1, and got segv too.
`immutable bool testMod = ...` causes stack overflow, however I'm not sure why `immutable testMod = ...` works...

---
immutable bool testMod = test19661();  // SEGV
// immutable testMod = test19661(); // Can compile and works.
// enum testMod = test19661(); // Error: circular initialization

bool test19661()
{
    import std.traits : isFunction;
    return isFunction!testMod;
}
Comment 2 basile-z 2019-04-18 15:59:46 UTC
reg 2.084 + ICE
Comment 3 basile-z 2019-04-18 18:02:55 UTC
There's a recursive template instantiation in dmd.dmangle, in function 

  void mangleTemplateInstance(TemplateInstance ti) 

which is possible to detect with the ti.inuse variable. Then you ends up with an assert(0):

> dmd/todt.d:69 void dmd.todt.Initializer_toDt(dmd.init.Initializer, ref dmd.backend.dt.DtBuilder).visitError(dmd.init.ErrorInitializer) [0x6d3736]
> dmd/todt.d:204 _Z16Initializer_toDtP11InitializerR9DtBuilder [0x6d36a5]
> dmd/toobj.d:874 _ZN9toObjFile9ToObjFile15initializerToDtEP14VarDeclarationR9DtBuilder [0x6e13aa]
> dmd/toobj.d:608 _ZN9toObjFile9ToObjFile5visitEP14VarDeclaration [0x6e0a74]
> dmd/declaration.d:1642 _ZN14VarDeclaration6acceptEP7Visitor [0x58243d]
> dmd/toobj.d:1020 _Z9toObjFileP7Dsymbolb [0x6dffbe]
> dmd/glue.d:409 _Z10genObjFileP6Moduleb [0x6d0b13]
> dmd/mars.d:717 int dmd.mars.tryMain(ulong, const(char)**, ref dmd.globals.Param) [0x65d5ea]
> dmd/mars.d:925 _Dmain [0x65e339]

If you remove it finally a bad error message happens (the default one for ErrorExp). So that's not ideal.

> Error: unknown, please file report on issues.dlang.org
> ice19661.d(11,18): Error: template instance `std.traits.isFunction!(testModule)` recursive template instantiation : isFunction!(testModule)
> Error: invalid initializer

There should just be the error related to recursion.
Comment 4 Dlang Bot 2019-04-18 23:42:48 UTC
@Basile-z created dlang/dmd pull request #9648 "fix issue 19661 - SIGSEGV in std.traits.isFunction" fixing this issue:

- fix issue 19661 - SIGSEGV in std.traits.isFunction

https://github.com/dlang/dmd/pull/9648
Comment 5 Mike Franklin 2019-04-19 01:19:01 UTC
According to a digger bisection, this PR introduced the regression: https://github.com/dlang/dmd/pull/9069
Comment 6 Dlang Bot 2019-04-19 10:48:06 UTC
@RazvanN7 created dlang/dmd pull request #9652 "Fix Issue 19661 - DMD 2.084.0 SIGSEGV in std.traits.isFunction" fixing this issue:

- Fix Issue 19661 - DMD 2.084.0 SIGSEGV in std.traits.isFunction

https://github.com/dlang/dmd/pull/9652
Comment 7 Dlang Bot 2019-04-24 10:35:29 UTC
dlang/dmd pull request #9652 "Fix Issue 19661 - DMD 2.084.0 SIGSEGV in std.traits.isFunction" was merged into master:

- 7b91b3577641764a079e9af075fd51e9928f4998 by RazvanN7:
  Fix Issue 19661 - DMD 2.084.0 SIGSEGV in std.traits.isFunction

https://github.com/dlang/dmd/pull/9652