Bug 19661 – DMD 2.084.0 SIGSEGV in std.traits.isFunction
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-02-08T10:24:13Z
Last change time
2020-03-21T03:56:34Z
Keywords
ice, pull
Assigned to
No Owner
Creator
Adam Wilson
Comments
Comment #0 by flyboynw — 2019-02-08T10:24:13Z
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 by kubo39 — 2019-04-18T13:38:59Z
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 by b2.temp — 2019-04-18T15:59:46Z
reg 2.084 + ICE
Comment #3 by b2.temp — 2019-04-18T18:02:55Z
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 by dlang-bot — 2019-04-18T23:42:48Z
@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