www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15233] New: TypeTuple causes segfault in dmd 2.68.2

https://issues.dlang.org/show_bug.cgi?id=15233

          Issue ID: 15233
           Summary: TypeTuple causes segfault in dmd 2.68.2
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: tomerfiliba gmail.com

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.

--
Oct 22 2015