Bug 15233 – TypeTuple causes segfault in dmd 2.68.2

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-10-22T09:40:00Z
Last change time
2016-01-03T14:02:11Z
Keywords
CTFE, ice, pull
Assigned to
nobody
Creator
tomer

Comments

Comment #0 by tomer — 2015-10-22T09:40:18Z
Consider the following snippet import std.string: indexOf; import std.typetuple: TypeTuple; struct Token {int offset; char fmt;} template splitFmt(string fmt) { template helper(int from, int j) { enum idx = fmt[from .. $].indexOf('%'); static if (idx < 0) { enum helper = TypeTuple!(fmt[from .. $]); } else { enum idx1 = idx + from; static if (fmt[idx1+1] == 'd') { enum helper = TypeTuple!(fmt[from .. idx1], Token(j, 'd'), helper!(idx1+2, j+1)); } else { static assert (false, "Invalid formatter '"~fmt[idx2+1]~"'"); } } } alias splitFmt = helper!(0, 0); } void main() { pragma(msg, splitFmt!"hello %d world"); } Compiling this crashes DMD (and LDC) with the following segault: Program received signal SIGSEGV, Segmentation fault. 0x000000000041dbb3 in TypeTuple::TypeTuple(Array<Expression*>*) () (gdb) p $_siginfo._sifields._sigfault.si_addr $1 = (void *) 0x18 (gdb) bt #0 0x000000000041dbb3 in TypeTuple::TypeTuple(Array<Expression*>*) () #1 0x000000000048635f in Interpreter::visit(TupleExp*) () #2 0x000000000047cbc2 in interpret(Expression*, InterState*, CtfeGoal) () #3 0x000000000047d051 in ctfeInterpret(Expression*) () #4 0x0000000000517311 in ExpInitializer::semantic(Scope*, Type*, NeedInterpret) () #5 0x00000000004cf506 in VarDeclaration::semantic2(Scope*) () #6 0x00000000004b5da8 in AttribDeclaration::semantic2(Scope*) () #7 0x00000000004b5da8 in AttribDeclaration::semantic2(Scope*) () #8 0x0000000000463734 in TemplateInstance::semantic2(Scope*) () #9 0x0000000000467c8c in TemplateInstance::semantic(Scope*, Array<Expression*>*) () #10 0x000000000041d0ac in TypeInstance::resolve(Loc, Scope*, Expression**, Type**, Dsymbol**, bool) () #11 0x000000000040ac5d in TypeInstance::toDsymbol(Scope*) () #12 0x00000000004d0cdb in AliasDeclaration::semantic(Scope*) () #13 0x000000000045ff08 in TemplateInstance::expandMembers(Scope*) () #14 0x000000000045ff3f in TemplateInstance::tryExpandMembers(Scope*) () #15 0x000000000046797d in TemplateInstance::semantic(Scope*, Array<Expression*>*) () #16 0x00000000004fbeff in ScopeExp::semantic(Scope*) () #17 0x00000000004b6b1f in PragmaDeclaration::semantic(Scope*) () #18 0x0000000000407c98 in Module::semantic() () #19 0x0000000000404d14 in tryMain(unsigned long, char const**) () #20 0x00007ffff6ff8ec5 in __libc_start_main (main=0x402820 <main>, argc=2, argv=0x7fffffffdd78, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdd68) at libc-start.c:287 #21 0x0000000000402d15 in _start () If I'm using a built-in type instead of ``Token(j, 'd')``, e.g., encoding the two numbers into an integer, it works fine.
Comment #1 by ag0aep6g — 2015-10-22T19:14:28Z
Reduced: ---- alias TypeTuple(stuff ...) = stuff; struct Token {} enum helper = TypeTuple!(Token(), "foo"); ---- Workaround: use alias instead of enum: ---- alias helper = TypeTuple!(fmt[from .. idx1], Token(j, 'd'), helper!(idx1+2, j+1)); ----
Comment #2 by tomer — 2015-10-22T19:39:44Z
thanks for the workaround
Comment #3 by k.hara.pg — 2015-10-23T10:52:10Z
Comment #4 by github-bugzilla — 2015-10-27T18:01:05Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/62fc013ee2614e8e68317ad8d2ba9a157e9302e9 fix Issue 15233 - TypeTuple causes segfault in dmd 2.68.2 https://github.com/D-Programming-Language/dmd/commit/af31c95f6d6024afea5db3d59ec08e5519427d72 Merge pull request #5226 from 9rnsr/fix15233 Issue 15233 - TypeTuple causes segfault in dmd 2.68.2
Comment #5 by github-bugzilla — 2016-01-03T14:02:11Z