================
@@ -0,0 +1,97 @@
+// 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: cir-opt --cir-flatten-cfg %t.cir -o %t-flat.cir
+// RUN: FileCheck --input-file=%t-flat.cir %s --check-prefix=CIR-FLAT
+// 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 Local { ~Local(); };
+void testSwitchWithCleanup(int n) {
+  Local x;
+  throw 42;
+}
+
+// In CIR, the throw is emitted inside a `cir.cleanup.scope` whose cleanup
+// region runs the destructor for `x` on the EH unwind path.
+
+// CIR: cir.func{{.*}} @_Z21testSwitchWithCleanupi(%[[ARG:.*]]: !s32i
+// CIR:   %[[N_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["n", init]
+// CIR:   %[[X:.*]] = cir.alloca !rec_Local, !cir.ptr<!rec_Local>, ["x"]
+// CIR:   cir.store %[[ARG]], %[[N_ADDR]] : !s32i
+// CIR:   cir.cleanup.scope {
+// CIR:     %[[EXN:.*]] = cir.alloc.exception 4 -> !cir.ptr<!s32i>
+// CIR:     %[[VAL:.*]] = cir.const #cir.int<42> : !s32i
+// CIR:     cir.store align(16) %[[VAL]], %[[EXN]] : !s32i, !cir.ptr<!s32i>
----------------
AmrDeveloper wrote:

```suggestion
// CIR:     cir.store {{.*}} %[[VAL]], %[[EXN]] : !s32i, !cir.ptr<!s32i>
```

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

Reply via email to