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





NeedInterpret) ()





Array<Expression*>*) ()

Type**, Dsymbol**, bool) ()





Array<Expression*>*) ()





argv=0x7fffffffdd78, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fffffffdd68) at libc-start.c:287


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