[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-11-01 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D108905#4655907 , @MaskRay wrote:

> In D108905#4655694 , @ChuanqiXu 
> wrote:
>
>> Oh, I am not saying the legacy and old comment. I mean you need to touch 
>> ReleaseNotes.rst and UserManual.rst since we add a new flag. Also we need 
>> either add a TODO/FIXME saying we need to emit an error in Sema if we find 
>> the the dtor of the exception we're throwing may throw or implement the 
>> semantics actually.
>
> Thanks for the reminder about `ReleaseNotes.rst` and `UsersManual.rst`!
>
> I think many changes don't update `UsersManual.rst` but this option is 
> probably quite useful and therefore deserves an entry. Added.
> The primary change is to `clang/lib/CodeGen/ItaniumCXXABI.cpp`, which does 
> not report warnings.
> If we want to implement a warning, we should probably do it in 
> clang/lib/Sema/SemaDeclCXX.cpp `Sema::BuildExceptionDeclaration`, which is 
> not touched in this file, so a TODO seems not appropriate...
>
> Is the warning to warn about `noexcept(false)` destructor in an 
> exception-declaration ? When?
> If at catch handlers, unfortunately we are cannot determine the exception 
> object for a `catch (...) { ... }` (used by coroutines).
> Technically, even if a destructor is `noexcept(false)`, the destructor may 
> not throw when `__cxa_end_catch` destroys the object.
>
> So we probably should warn about throw expressions, which can be done in 
> `Sema::CheckCXXThrowOperand` and I will investigate it.
> However, this warning appears orthogonal to `-fassume-nothrow-exception-dtor`.
> We can argue that even without `-fassume-nothrow-exception-dtor`, an thrown 
> object with a `noexcept(false)` destructor is probably not a good idea.
> However, I am on the fence whether the warning should be enabled-by-default.

The idea of diagnosing such cases is originally raised by @rjmccall  in 
https://github.com/llvm/llvm-project/issues/57375#issuecomment-1230590204. And 
in fact,  John is suggesting an error instead of a warning. To be honest, in 
our downstream implementation, we didn't implement that semantical check 
neither.

For the implementation, I think `Sema::CheckCXXThrowOperand` may be a good 
place and we can left a TODO there.

Technically, we're using a dialect after we enable 
`-fassume-nothrow-exception-dtor`.  In our dialect, we don't want to see an 
exception to throw exceptions. This is a rule for our dialect. And generally we 
have 2 strategies for implementing such language rules :

- Detect it and emit errors after we found users violating the rules.
- Don't detect it and claims it is the fault of the users.

No matter what the strategy we choose, it is not orthogonal to 
`-fassume-nothrow-exception-dtor` for sure. It is highly related. Then, I think 
the first strategy is always a better choice. Generally we only choose 2 when 
we can't diagnose such cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-11-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D108905#4655694 , @ChuanqiXu wrote:

> Oh, I am not saying the legacy and old comment. I mean you need to touch 
> ReleaseNotes.rst and UserManual.rst since we add a new flag. Also we need 
> either add a TODO/FIXME saying we need to emit an error in Sema if we find 
> the the dtor of the exception we're throwing may throw or implement the 
> semantics actually.

Thanks for the reminder about `ReleaseNotes.rst` and `UsersManual.rst`!

I think many changes don't update `UsersManual.rst` but this option is probably 
quite useful and therefore deserves an entry. Added.
The primary change is to `clang/lib/CodeGen/ItaniumCXXABI.cpp`, which does not 
report warnings.
If we want to implement a warning, we should probably do it in 
clang/lib/Sema/SemaDeclCXX.cpp `Sema::BuildExceptionDeclaration`, which is not 
touched in this file, so a TODO seems not appropriate...

Is the warning to warn about `noexcept(false)` destructor in an 
exception-declaration ? When?
If at catch handlers, unfortunately we are cannot determine the exception 
object for a `catch (...) { ... }` (used by coroutines).
Technically, even if a destructor is `noexcept(false)`, the destructor may not 
throw when `__cxa_end_catch` destroys the object.

So we probably should warn about throw expressions, which can be done in 
`Sema::CheckCXXThrowOperand` and I will investigate it.
However, this warning appears orthogonal to `-fassume-nothrow-exception-dtor`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-11-01 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/docs/UsersManual.rst:2145-2147
+   ``catch (...) { ... }``. This option tells Clang that an exception object's
+   destructor does not throw, even if the destructor is annotated as
+   ``noexcept(false)``.

I think it is better to treat the program as invalid if the compiler find the 
exception object's destructor is ``noexcept(false)``. The earlier error message 
is better than debugging and understanding what happened actually.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-11-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 557968.
MaskRay marked an inline comment as done.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Update clang/docs/UsersManual.rst and clang/docs/ReleaseNotes.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/Driver/clang-exception-flags.cpp

Index: clang/test/Driver/clang-exception-flags.cpp
===
--- clang/test/Driver/clang-exception-flags.cpp
+++ clang/test/Driver/clang-exception-flags.cpp
@@ -27,3 +27,6 @@
 // RUN: %clang -### -target x86_64-scei-ps4 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // RUN: %clang -### -target x86_64-sie-ps5 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // PS-OFF-NOT: "-cc1" {{.*}} "-f{{(cxx-)?}}exceptions"
+
+// RUN: %clang -### -fexceptions -fno-assume-nothrow-exception-dtor -fassume-nothrow-exception-dtor %s 2>&1 | FileCheck %s --check-prefix=NOTHROW-DTOR
+// NOTHROW-DTOR: "-cc1"{{.*}} "-fcxx-exceptions" "-fassume-nothrow-exception-dtor"
Index: clang/test/CodeGenCoroutines/coro-cleanup.cpp
===
--- clang/test/CodeGenCoroutines/coro-cleanup.cpp
+++ clang/test/CodeGenCoroutines/coro-cleanup.cpp
@@ -1,5 +1,6 @@
 // Verify that coroutine promise and allocated memory are freed up on exception.
-// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,THROWEND
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -fassume-nothrow-exception-dtor -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,NOTHROWEND
 
 namespace std {
 template  struct coroutine_traits;
@@ -49,7 +50,9 @@
   // CHECK: [[DeallocPad]]:
   // CHECK-NEXT: landingpad
   // CHECK-NEXT:   cleanup
-  // CHECK: br label %[[Dealloc:.+]]
+  // THROWEND:br label %[[Dealloc:.+]]
+  // NOTHROWEND:  icmp ne ptr %[[#]], null
+  // NOTHROWEND-NEXT: br i1 %[[#]], label %[[Dealloc:.+]], label
 
   Cleanup cleanup;
   may_throw();
@@ -68,13 +71,15 @@
   // CHECK: [[Catch]]:
   // CHECK:call ptr @__cxa_begin_catch(
   // CHECK:call void @_ZNSt16coroutine_traitsIJvEE12promise_type19unhandled_exceptionEv(
-  // CHECK:invoke void @__cxa_end_catch()
-  // CHECK-NEXT:to label %[[Cont:.+]] unwind
+  // THROWEND:invoke void @__cxa_end_catch()
+  // THROWEND-NEXT: to label %[[Cont:.+]] unwind
+  // NOTHROWEND:  call void @__cxa_end_catch()
+  // NOTHROWEND-NEXT:   br label %[[Cont2:.+]]
 
-  // CHECK: [[Cont]]:
-  // CHECK-NEXT: br label %[[Cont2:.+]]
-  // CHECK: [[Cont2]]:
-  // CHECK-NEXT: br label %[[Cleanup:.+]]
+  // THROWEND:  [[Cont]]:
+  // THROWEND-NEXT:   br label %[[Cont2:.+]]
+  // CHECK: [[Cont2]]:
+  // CHECK-NEXT:  br label %[[Cleanup:.+]]
 
   // CHECK: [[Cleanup]]:
   // CHECK: call void @_ZNSt16coroutine_traitsIJvEE12promise_typeD1Ev(
@@ -82,8 +87,8 @@
   // CHECK: call void @_ZdlPv(ptr noundef %[[Mem0]]
 
   // CHECK: [[Dealloc]]:
-  // CHECK:   %[[Mem:.+]] = call ptr @llvm.coro.free(
-  // CHECK:   call void @_ZdlPv(ptr noundef %[[Mem]])
+  // THROWEND:   %[[Mem:.+]] = call ptr @llvm.coro.free(
+  // THROWEND:   call void @_ZdlPv(ptr noundef %[[Mem]])
 
   co_return;
 }
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++98 -o - -fcxx-exceptions -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
-// RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions | FileCheck --check-prefixes=CHECK,CHECK11,THROWEND11 %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions -fassume-nothrow-exception-dtor | FileCheck --check-prefixes=CHECK,CHECK11,NOTHROWEND11 %s
 
 // CHECK: %[[STRUCT_TEST13_A:.*]] = type {

[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-31 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

Oh, I am not saying the legacy and old comment. I mean you need to touch 
ReleaseNotes.rst and UserManual.rst since we add a new flag. Also we need 
either add a TODO/FIXME saying we need to emit an error in Sema if we find the 
the dtor of the exception we're throwing may throw or implement the semantics 
actually.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-30 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:4435-4448
   struct CallEndCatch final : EHScopeStack::Cleanup {
 CallEndCatch(bool MightThrow) : MightThrow(MightThrow) {}
 bool MightThrow;
 
 void Emit(CodeGenFunction &CGF, Flags flags) override {
   if (!MightThrow) {
 CGF.EmitNounwindRuntimeCall(getEndCatchFn(CGF.CGM));

ChuanqiXu wrote:
> If `__cxa_end_catch ` is nounwind always now, do we need to refactor this 
> one? Like:
> ```
> struct CallEndCatch final : EHScopeStack::Cleanup {
> CallEndCatch() {}
> 
> void Emit(CodeGenFunction &CGF, Flags flags) override {
>   CGF.EmitNounwindRuntimeCall(getEndCatchFn(CGF.CGM));
> }
>   };
> ```
Since `__cxa_end_catch` is no longer `nounwind` in the latest revision, we 
cannot simplify the code...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-30 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

> We need to mention this in the docs and the ReleaseNotes since we add a new 
> flag.



> To make this self contained, we need to add a check in the frontend and emit 
> errors if the compiler find the throwing exception's destructor may throw. 
> This is not required in the current patch but it may be good to add a FIXME 
> or TODO somewhere.

There are 2 comments not addressed yet : )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-30 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I'll land this patch next week if there is no objection. This seems very useful 
to a few parties and the current behavior is opt-in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-23 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D108905#4654561 , @smeenai wrote:

> This looks great to me, thanks. @rjmccall should sign off on it though.

@rjmccall Are you happy with this opt-in option?

In D108905#4654626 , @ChuanqiXu wrote:

> LGTM since this is exactly what we do in the downstream. The effects of the 
> change in our workloads is 4% size reduction in a coroutine intensive 
> project. (But it requires the coroutine's final suspend can't except via 
> symetric transfer. I was meant to send a paper to WG21 to discuss this).   
> After all, this should be a win for most projects.
>
> We need to mention this in the docs and the ReleaseNotes since we add a new 
> flag.
>
> To make this self contained, we need to add a check in the frontend and emit 
> errors if the compiler find the throwing exception's destructor may throw. 
> This is not required in the current patch but it may be good to add a FIXME 
> or TODO somewhere.
>
> (BTW, the Phab itself is extremly slow now. So if we want more discuss on 
> this, let's move this to Github?)

The slowness was due to a malicious/aggressive crawler. I have fixed it and 
updated php-fpm config:) 
https://discourse.llvm.org/t/phabricator-is-very-slow/73132/14


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-20 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

LGTM since this is exactly what we do in the downstream. The effects of the 
change in our workloads is 4% size reduction in a coroutine intensive project. 
(But it requires the coroutine's final suspend can't except via symetric 
transfer. I was meant to send a paper to WG21 to discuss this).   After all, 
this should be a win for most projects.

We need to mention this in the docs and the ReleaseNotes since we add a new 
flag.

To make this self contained, we need to add a check in the frontend and emit 
errors if the compiler find the throwing exception's destructor may throw. This 
is not required in the current patch but it may be good to add a FIXME or TODO 
somewhere.

(BTW, the Phab itself is extremly slow now. So if we want more discuss on this, 
let's move this to Github?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-20 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

LGTM since this is exactly what we do in the downstream. The effects of the 
change in our workloads is 4% size reduction in a coroutine intensive project. 
(But it requires the coroutine's final suspend can't except via symetric 
transfer. I was meant to send a paper to WG21 to discuss this).   After all, 
this should be a win for most projects.

We need to mention this in the docs and the ReleaseNotes since we add a new 
flag.

To make this self contained, we need to add a check in the frontend and emit 
errors if the compiler find the throwing exception's destructor may throw. This 
is not required in the current patch but it may be good to add a FIXME or TODO 
somewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-19 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

This looks great to me, thanks. @rjmccall should sign off on it though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-19 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 557798.
MaskRay retitled this revision from "[ItaniumCXXABI] Make __cxa_end_catch calls 
unconditionally nounwind" to "[ItaniumCXXABI] Add 
-fassume-nothrow-exception-dtor to assume that an exception object' destructor 
is nothrow".
MaskRay edited the summary of this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Switch to opt-in

Add -fassume-nothrow-exception-dtor


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/Driver/clang-exception-flags.cpp

Index: clang/test/Driver/clang-exception-flags.cpp
===
--- clang/test/Driver/clang-exception-flags.cpp
+++ clang/test/Driver/clang-exception-flags.cpp
@@ -27,3 +27,6 @@
 // RUN: %clang -### -target x86_64-scei-ps4 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // RUN: %clang -### -target x86_64-sie-ps5 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // PS-OFF-NOT: "-cc1" {{.*}} "-f{{(cxx-)?}}exceptions"
+
+// RUN: %clang -### -fexceptions -fno-assume-nothrow-exception-dtor -fassume-nothrow-exception-dtor %s 2>&1 | FileCheck %s --check-prefix=NOTHROW-DTOR
+// NOTHROW-DTOR: "-cc1"{{.*}} "-fcxx-exceptions" "-fassume-nothrow-exception-dtor"
Index: clang/test/CodeGenCoroutines/coro-cleanup.cpp
===
--- clang/test/CodeGenCoroutines/coro-cleanup.cpp
+++ clang/test/CodeGenCoroutines/coro-cleanup.cpp
@@ -1,5 +1,6 @@
 // Verify that coroutine promise and allocated memory are freed up on exception.
-// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,THROWEND
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -fassume-nothrow-exception-dtor -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,NOTHROWEND
 
 namespace std {
 template  struct coroutine_traits;
@@ -49,7 +50,9 @@
   // CHECK: [[DeallocPad]]:
   // CHECK-NEXT: landingpad
   // CHECK-NEXT:   cleanup
-  // CHECK: br label %[[Dealloc:.+]]
+  // THROWEND:br label %[[Dealloc:.+]]
+  // NOTHROWEND:  icmp ne ptr %[[#]], null
+  // NOTHROWEND-NEXT: br i1 %[[#]], label %[[Dealloc:.+]], label
 
   Cleanup cleanup;
   may_throw();
@@ -64,17 +67,18 @@
   // CHECK-NEXT:   catch ptr null
   // CHECK:  call void @_ZN7CleanupD1Ev(
   // CHECK:  br label %[[Catch:.+]]
-
   // CHECK: [[Catch]]:
   // CHECK:call ptr @__cxa_begin_catch(
   // CHECK:call void @_ZNSt16coroutine_traitsIJvEE12promise_type19unhandled_exceptionEv(
-  // CHECK:invoke void @__cxa_end_catch()
-  // CHECK-NEXT:to label %[[Cont:.+]] unwind
+  // THROWEND:invoke void @__cxa_end_catch()
+  // THROWEND-NEXT: to label %[[Cont:.+]] unwind
+  // NOTHROWEND:  call void @__cxa_end_catch()
+  // NOTHROWEND-NEXT:   br label %[[Cont2:.+]]
 
-  // CHECK: [[Cont]]:
-  // CHECK-NEXT: br label %[[Cont2:.+]]
-  // CHECK: [[Cont2]]:
-  // CHECK-NEXT: br label %[[Cleanup:.+]]
+  // THROWEND: [[Cont]]:
+  // THROWEND-NEXT:   br label %[[Cont2:.+]]
+  // CHECK:[[Cont2]]:
+  // CHECK-NEXT:br label %[[Cleanup:.+]]
 
   // CHECK: [[Cleanup]]:
   // CHECK: call void @_ZNSt16coroutine_traitsIJvEE12promise_typeD1Ev(
@@ -82,8 +86,8 @@
   // CHECK: call void @_ZdlPv(ptr noundef %[[Mem0]]
 
   // CHECK: [[Dealloc]]:
-  // CHECK:   %[[Mem:.+]] = call ptr @llvm.coro.free(
-  // CHECK:   call void @_ZdlPv(ptr noundef %[[Mem]])
+  // THROWEND:   %[[Mem:.+]] = call ptr @llvm.coro.free(
+  // THROWEND:   call void @_ZdlPv(ptr noundef %[[Mem]])
 
   co_return;
 }
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++98 -o - -fcxx-exceptions -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
-// RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions | FileCheck --check-prefixes=CHECK,CHECK11,THROWE