[Issue 10966] Optimizer generates wrong code with try-catch

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jul 29 08:43:17 PDT 2014


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

yebblies <yebblies at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies at gmail.com
            Version|D2                          |D1 & D2
           Assignee|nobody at puremagic.com        |bugzilla at digitalmars.com
            Summary|Leaked destruction in       |Optimizer generates wrong
                   |static array postblit       |code with try-catch
           Severity|critical                    |blocker

--- Comment #3 from yebblies <yebblies at gmail.com> ---
Reduces to:

void bug10966(void* p)
{
    void* pstart = p;

    try
    {
        p = null;
        throw new Exception("dummy");
    }
    catch (Throwable o)
    {
        assert(p != pstart);
    }
}

void test10966()
{
    int s;
    int[4] ss;
    bug10966(ss.ptr);
}

The glue layer turns this into basic blocks, but with not connection between
the block containing the throw and the catch block.  The backend assumes that
it is not possible for the assert to be run after p has been reassigned, so it
propagates the old value of p.  This is very similar to issue 12503

I can easily fix this exact case by adding a relationship between the basic
blocks, but replacing the throw with a function that throws will cause the same
problem.  Maybe simply adding the dependency for all basic blocks inside the
try will do the trick, but it seems like something that should be better
supported in the backend.

dmc does the same thing with the equivalent code - it all looks horribly
broken.

Walter, is there a mechanism for this in the backend or is it completely
unsupported?

--


More information about the Digitalmars-d-bugs mailing list