[PATCH] D113620: Skip exception cleanups when the innermost scope is EHTerminateScope.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 6 15:35:30 PST 2021


rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

I think it's generally better to not run cleanups on the way to a `terminate` call, not only for code size but also for debuggability. This change seems like an improvement to me.



================
Comment at: clang/lib/CodeGen/CGCleanup.cpp:189
+  if (find(InnermostEHScope)->getKind() == EHScope::Terminate)
+    IsEHCleanup = false;
+
----------------
Does the situation where both `IsEHCleanup` and `IsNormalCleanup` end up set to `false` work well? (Eg, do we avoid generating cleanup code entirely, even for things like conditional cleanups where we might otherwise generate a condition variable?) Eg, in a case like this:

```
struct A { A(); ~A() noexcept(false); };
void f(bool b) noexcept { (b ? (void)A() : void()), (b ? (void)A() : void()); }
```
... we currently inject some `i1`s to track whether each `A` is alive, and could presumably omit them here.

If this patch isn't enough to handle that, maybe this isn't worth worrying about at this level and we can just let the optimizer remove them again?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113620/new/

https://reviews.llvm.org/D113620



More information about the cfe-commits mailing list