[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 28 10:20:03 PST 2024


usx95 wrote:

I tried using the EHCleanups as the only source of cleanups for these branch-in-expr. https://github.com/llvm/llvm-project/pull/83224 is an attempt. I do not like it very much.

The first challenge is to add these cleanups to the stack even when exceptions are disabled. Some of these cleanups (like array cleanup) require auxiliary instructions, like storing pointers to the last constructed array element. In order to not blow up the number of unnecessary instructions when cleanup is not emitted (especially when exceptions are disabled), we need to somehow remember these auxiliary instructions and erase them if cleanup is not emitted. Tracking such auxiliary instructions and attributing these instructions to a cleanup becomes very complicated very quickly.

Secondly, we do not want to emit all EHCleanups in the current scope upon seeing a branch. `CallCoroEnd` is one such cleanup.

My proposal would be to not directly use the EHCleanups or forcefully add them to EHStack. Instead, maintain a separate stack for **deferred** cleanups. This is something we already do for lifetime-extended cleanups. It is much easier to reason about and keeps things simpler.



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


More information about the cfe-commits mailing list