[clang] [clang-tools-extra] [codegen] Emit missing cleanups when an expression contains a branch (PR #80698)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 14 06:04:54 PST 2024


usx95 wrote:

> Is there a valid use for having "EHCleanup" that _doesn't_ handle branches across it? That is, do we _ever_ need a cleanup to be called only for an exception thrown, and not otherwise leaving the scope? I'm just wondering if we can simplify things conceptually here and remove an option.

@jyknight Previously, I had tried using all the `EHCleanup` in the EHStack for these purposes. I found the `CallCoroEnd` cleanup problematic because the suspension cleanup jump destination does not include `CallCoroEnd` cleanup in its scope. So we might emit it on jumping to this destination.
```cpp
CurCoro.Data->CleanupJD = getJumpDestInCurrentScope(RetBB);
...
    GroManager.EmitGroInit();
    EHStack.pushCleanup<CallCoroEnd>(EHCleanup);
```

I will try to juggle the `CallCoroEnd` cleanup and jump destination and make it work.

Another problem of relying on `EHCleanup` would be that many (and not all) EHOnly cleanups are added to the EHStack only when exceptions are enabled. We would need to restructure this to add them to EHStack "always" but only emit them with `-fexceptions`.

https://github.com/llvm/llvm-project/pull/80698


More information about the cfe-commits mailing list