================
@@ -0,0 +1,106 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-fcxx-exceptions -fexceptions -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-fcxx-exceptions -fexceptions -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-fcxx-exceptions -fexceptions -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
+
+struct C {
+  C();
+  ~C();
+};
+
+// Two EH cleanups -- destroying the local `a` and freeing the thrown
+// `new C()` if its constructor throws -- funnel into the same catch dispatch,
+// so the throw's landing pad must carry both the cleanup and the catch clause.
+int testCaughtThrowSharedDispatch() {
+  try {
+    C a;
+    throw new C();
+  } catch (C *p) {
+    delete p;
+    return 0;
+  }
+  return 1;
+}
+
+// CIR: cir.func{{.*}} @_Z29testCaughtThrowSharedDispatchv()
+// CIR:   %[[A:.*]] = cir.alloca "a" {{.*}} : !cir.ptr<!rec_C>
+// CIR:   cir.try {
+// CIR:     cir.call @_ZN1CC1Ev(%[[A]])
+// CIR:     cir.cleanup.scope {
+// CIR:       cir.throw %{{.*}} : !cir.ptr<!cir.ptr<!rec_C>>, @_ZTIP1C
+// CIR:       cir.unreachable
+// CIR:     } cleanup all {
+// CIR:       cir.call @_ZN1CD1Ev(%[[A]]) nothrow
+// CIR:       cir.yield
+// CIR:     }
+// CIR:   } catch [type #cir.global_view<@_ZTIP1C> : !cir.ptr<!u8i>]
----------------
adams381 wrote:

Added a `cir-opt -cir-hoist-allocas -cir-flatten-cfg -cir-eh-abi-lowering` run 
with `CIR-EHABI` checks on the `inflight_exception cleanup [...]` clauses.

https://github.com/llvm/llvm-project/pull/205638
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to