www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11540] New: [ICE] Unknown segfault during CTFE

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11540

           Summary: [ICE] Unknown segfault during CTFE
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dmitry.olsh gmail.com



07:49:27 PST ---
Credit goes to Vladimir and his dustmite tool.

The following is auto-reduced test case:

enum IR:uint 
{
Trie  
}

struct Bytecode
{
uint raw;
 property data() { return raw ; }

 property code() { return cast()raw>>24; }

}

template BasicElementOf(Range)
{
alias typeof(Range.init) BasicElementOf;
}

struct Parser(R)
{
Bytecode[] ir;       
CodepointSet[] charsets;  
this(S)(R , S )
{
try
        parseRegex;
catch(Exception e)
error(e.msg);
}

void put(Bytecode code)
{
ir ~= code;
}

 trusted parseRegex()
{
parseAtom;
}

void parseAtom()
{
parseEscape;
}

 trusted charsetToIr(CodepointSet set)
{
put(Bytecode());
charsets ~= set;
}

 trusted parseEscape()
{

charsetToIr(unicode.Nd);
}

 trusted error(string )
{
}

alias BasicElementOf!R Char;
Regex!Char program()
{
return Regex!Char(this);
}
}


struct Regex(Char)
{
CodepointSet[] charsets; 
Bytecode[] ir;      

 trusted lightPostprocess()
{
Kickstart!Char(this, new uint[](256));
}

this(S)(Parser!(S) p)
{
ir = p.ir;
charsets = p.charsets;
lightPostprocess;
}
}

struct ShiftOr(Char)
{
struct ShiftThread
    {
uint pc;
}

this(Regex!Char re, uint[] )
{
ShiftThread t = ShiftThread();
switch(re.ir[t.pc].code)
{
case IR.Trie:
                    auto set = re.charsets[re.ir[t.pc].data];
goto L_OutOfLoop;
L_OutOfLoop:
                            ;
}
}

}

alias ShiftOr Kickstart;

auto regex(S)(S pattern, const(char)[] flags="")
{
regexImpl(pattern);
}

auto regexImpl(S)(S pattern, const(char)[] flags="")
{
auto parser = Parser!(typeof(pattern))(pattern, flags);
parser.program;
}


template ctRegexImpl(alias pattern, string flags=[])
{
enum r = regex(pattern);
}

template ctRegex(alias pattern, alias flags=[])
{
enum ctRegex = ctRegexImpl!pattern;
}

struct GcPolicy
{
}


alias InversionList!GcPolicy CodepointSet;

struct InversionList(SP=GcPolicy)
{
alias size_t Marker;

Marker addInterval()
in
    {
}
body
    {
}

Uint24Array!SP data;
}struct Uint24Array(SP=GcPolicy)
{
~this()
{
}

}

struct unicode
{
static opDispatch(string name)()
{
return loadAny(name);
}

static loadAny(Set=CodepointSet, C)(C)
{
Set set;
return set;
}

}

void foo()
{
ctRegex!`(?P<Quot>\d+)`;
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 18 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11540




07:50:08 PST ---
Backtrace in dmd's core file:


    ()


    ()

Array<Expression>*, Expression*) ()

    ()


    ()

    ()

    ()

Array<Expression>*, Expression*) ()

    ()

    ()

    ()

Array<Expression>*, Expression*) ()

    ()


    ()
---Type <return> to continue, or q <return> to quit---

    ()

Array<Expression>*, Expression*) ()

    ()


    ()

Array<Expression>*, Expression*) ()

    ()


NeedInterpret) ()



Array<Expression>*) ()




    ()


Array<Expression>*) ()

---Type <return> to continue, or q <return> to quit---






    argc=3, ubp_av=0x7fffe3227798, init=<optimized out>, 
    fini=<optimized out>, rtld_fini=<optimized out>, 
    stack_end=0x7fffe3227788) at libc-start.c:226


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11540




08:25:33 PST ---
Reduced by hand to this 20-liner:

int fun()
{
    CodepointSet[] charsets = new CodepointSet[1];  
    uint pc;
    switch(pc)
    {
    case 0:
        auto set = charsets[0];
    goto L_OutOfLoop;
    L_OutOfLoop:
        ;
    default:
    }
    return 0;
}

struct CodepointSet
{
    ~this(){}
}

enum x = fun();

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11540


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |CTFE, pull
                 CC|                            |yebblies gmail.com
            Summary|[ICE] Unknown segfault      |[ICE] CTFE segfault with
                   |during CTFE                 |try-catch-finally and goto



Reduced - the destructor generates a try-finally which is not searched properly
for the goto'd label.


static assert(()
{
    try
    {
        goto label;
        label: ;
    }
    finally
    {
    }
    return 1;
}());

static assert(()
{
    try
    {
        goto label;
        label: ;
    }
    catch
    {
    }
    return 1;
}());

https://github.com/D-Programming-Language/dmd/pull/2820

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11540




And with:

static assert(()
{
    with(Object.init)
    {
        goto label;
        label: ;
    }
    return 1;
}());

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11540




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/0afa3dead96f207157608f1bf72651967e7915a7
fix Issue 11540 - [ICE] CTFE segfault with try-catch-finally and goto

https://github.com/D-Programming-Language/dmd/commit/9c4a1cf7e711a6cd8b6490258144329622f8441d


Issue 11540 - [ICE] CTFE segfault with try-catch-finally and goto

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 28 2013
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11540


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 28 2013