Thread overview
[Issue 10966] Optimizer generates wrong code with try-catch
Jul 29, 2014
yebblies
Mar 25, 2016
yebblies
Aug 09, 2020
Walter Bright
Aug 10, 2020
Dlang Bot
Aug 10, 2020
Dlang Bot
July 29, 2014
https://issues.dlang.org/show_bug.cgi?id=10966

yebblies <yebblies@gmail.com> changed:

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

--- Comment #3 from yebblies <yebblies@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?

--
June 09, 2015
https://issues.dlang.org/show_bug.cgi?id=10966

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|D1 & D2                     |D2

--
March 25, 2016
https://issues.dlang.org/show_bug.cgi?id=10966

yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org

--- Comment #4 from yebblies <yebblies@gmail.com> ---
*** Issue 15302 has been marked as a duplicate of this issue. ***

--
August 09, 2020
https://issues.dlang.org/show_bug.cgi?id=10966

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
Yes, it looks like a bug with the data flow analysis and catch blocks.

--
August 10, 2020
https://issues.dlang.org/show_bug.cgi?id=10966

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #11541 "fix Issue 10966 - Optimizer generates wrong code with try-catch" fixing this issue:

- fix Issue 10966 - Optimizer generates wrong code with try-catch

https://github.com/dlang/dmd/pull/11541

--
August 10, 2020
https://issues.dlang.org/show_bug.cgi?id=10966

Dlang Bot <dlang-bot@dlang.rocks> changed:

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

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #11541 "fix Issue 10966 - Optimizer generates wrong code with try-catch" was merged into master:

- 921fe0d1065e9b656e7472b9cbb9c6748fbd5ba4 by Walter Bright:
  fix Issue 10966 - Optimizer generates wrong code with try-catch

https://github.com/dlang/dmd/pull/11541

--