Thread overview
[Issue 20897] -betterC generates `try`/`catch` in the AST when using struct destructors
Jun 05, 2020
Roxanne
Jun 05, 2020
kinke
Jun 28, 2020
kinke
[Issue 20897] AST contains try/finally statements in -betterC mode
Jun 28, 2020
kinke
Jun 28, 2020
kinke
June 05, 2020
https://issues.dlang.org/show_bug.cgi?id=20897

--- Comment #1 from Roxanne <assemblyislaw@gmail.com> ---
I meant LDC 1.21.0 with LLVM 10.0.0, not LDC 10.0.0, sorry for the inconvenience

--
June 05, 2020
https://issues.dlang.org/show_bug.cgi?id=20897

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke@gmx.net

--- Comment #2 from kinke <kinke@gmx.net> ---
Unfortunately, you'll need another test case - some try/finally in the -vcg-ast
output aren't actual TryFinallyStatements (compiler internals...). The testcase
should fail to link (at least with LDC) when adding an `extern(C) int main() {
return 0; }` and compiling with `-betterC`.

--
June 28, 2020
https://issues.dlang.org/show_bug.cgi?id=20897

--- Comment #3 from kinke <kinke@gmx.net> ---
A similar example (from https://github.com/ldc-developers/ldc/issues/3479),
this time for scope(exit):

void create(uint a, uint b, string c) {}
extern(C) int main()
{
    int a = 5;
    scope(exit) a = 6;
    create(0, 1, "2");
    return 0;
}

Currently lowered to:

extern(C) int main()
{
    int a = 5;
    try
    {
        create(0u, 1u, "2");
        return 0;
    }
    finally
        a = 6;
}

Instead of having each compiler backend translate TryFinallyStatements in betterC mode to 2 consecutive block statements, the frontend should do this.

--
June 28, 2020
https://issues.dlang.org/show_bug.cgi?id=20897

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|-betterC generates          |AST contains try/finally
                   |`try`/`catch` in the AST    |statements in -betterC mode
                   |when using struct           |
                   |destructors                 |

--
June 28, 2020
https://issues.dlang.org/show_bug.cgi?id=20897

kinke <kinke@gmx.net> changed:

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

--- Comment #4 from kinke <kinke@gmx.net> ---
Sorry, my bad - I've overlooked the return-statement and similar control-flow stuff requiring to represent a cleanup via a TryFinallyStatement for -betterC too. Will be fixed in LDC's glue layer instead.

--