CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
98 lines
4.6 KiB
C++
98 lines
4.6 KiB
C++
// 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{{.*}} %[[VAL]], %[[EXN]] : !s32i, !cir.ptr<!s32i>
|
|
// CIR: cir.throw %[[EXN]] : !cir.ptr<!s32i>, @_ZTIi
|
|
// CIR: cir.unreachable
|
|
// CIR: cir.yield
|
|
// CIR: } cleanup all {
|
|
// CIR: cir.call @_ZN5LocalD1Ev(%[[X]]) nothrow
|
|
// CIR: cir.yield
|
|
// CIR: }
|
|
// CIR: cir.return
|
|
|
|
// After CFG flattening the cleanup scope is gone: the `cir.throw` becomes a
|
|
// `cir.try_throw` whose normal destination is a literally-unreachable block
|
|
// at the end of the function and whose unwind destination is the EH
|
|
// cleanup chain that runs the destructor and then resumes.
|
|
|
|
// CIR-FLAT: cir.func{{.*}} @_Z21testSwitchWithCleanupi(%[[ARG:.*]]: !s32i
|
|
// CIR-FLAT: %[[N_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["n", init]
|
|
// CIR-FLAT: %[[X:.*]] = cir.alloca !rec_Local, !cir.ptr<!rec_Local>, ["x"]
|
|
// CIR-FLAT: cir.store %[[ARG]], %[[N_ADDR]]
|
|
// CIR-FLAT: cir.br ^[[BODY:.+]]
|
|
// CIR-FLAT: ^[[BODY]]:
|
|
// CIR-FLAT: %[[EXN:.*]] = cir.alloc.exception 4 -> !cir.ptr<!s32i>
|
|
// CIR-FLAT: %[[VAL:.*]] = cir.const #cir.int<42> : !s32i
|
|
// CIR-FLAT: cir.store{{.*}} %[[VAL]], %[[EXN]]
|
|
// CIR-FLAT: cir.try_throw %[[EXN]] : !cir.ptr<!s32i>, @_ZTIi ^[[UNREACH:.+]], ^[[UNWIND:.+]]
|
|
// CIR-FLAT: ^[[UNWIND]]:
|
|
// CIR-FLAT: %[[ET:.*]] = cir.eh.initiate cleanup : !cir.eh_token
|
|
// CIR-FLAT: cir.br ^[[CLEANUP:.+]](%[[ET]] : !cir.eh_token)
|
|
// CIR-FLAT: ^[[CLEANUP]](%[[ET2:.*]]: !cir.eh_token):
|
|
// CIR-FLAT: %[[CT:.*]] = cir.begin_cleanup %[[ET2]]
|
|
// CIR-FLAT: cir.call @_ZN5LocalD1Ev(%[[X]]) nothrow
|
|
// CIR-FLAT: cir.end_cleanup %[[CT]]
|
|
// CIR-FLAT: cir.resume %[[ET2]]
|
|
// CIR-FLAT: cir.return
|
|
// CIR-FLAT: ^[[UNREACH]]:
|
|
// CIR-FLAT: cir.unreachable
|
|
|
|
// In LLVM IR the throw becomes an `invoke @__cxa_throw` whose unwind
|
|
// destination is a landingpad with a `cleanup` clause, runs the destructor,
|
|
// and resumes. The "normal" destination of the invoke is a block containing
|
|
// just `unreachable`.
|
|
|
|
// LLVM: define dso_local void @_Z21testSwitchWithCleanupi(i32 noundef %{{.*}}) {{.*}} personality ptr @__gxx_personality_v0
|
|
// LLVM: %[[X:.*]] = alloca %struct.Local
|
|
// LLVM: %[[EXN:.*]] = call ptr @__cxa_allocate_exception(i64 4)
|
|
// LLVM: store i32 42, ptr %[[EXN]]
|
|
// LLVM: invoke void @__cxa_throw(ptr %[[EXN]], ptr @_ZTIi, ptr null)
|
|
// LLVM-NEXT: to label %[[NORMAL:.*]] unwind label %[[LPAD:.*]]
|
|
// LLVM: [[LPAD]]:
|
|
// LLVM: %{{.*}} = landingpad { ptr, i32 }
|
|
// LLVM-NEXT: cleanup
|
|
// LLVM: call void @_ZN5LocalD1Ev(ptr {{.*}} %[[X]])
|
|
// LLVM: resume { ptr, i32 } %{{.*}}
|
|
// LLVM: [[NORMAL]]:
|
|
// LLVM: unreachable
|
|
|
|
// OGCG produces equivalent IR: an `invoke __cxa_throw` whose unwind path
|
|
// is a `cleanup` landingpad that calls the destructor and resumes.
|
|
|
|
// OGCG: define dso_local void @_Z21testSwitchWithCleanupi(i32 noundef %n) {{.*}} personality ptr @__gxx_personality_v0
|
|
// OGCG: %[[X:.*]] = alloca %struct.Local
|
|
// OGCG: %[[EXN:.*]] = call ptr @__cxa_allocate_exception(i64 4)
|
|
// OGCG: store i32 42, ptr %[[EXN]]
|
|
// OGCG: invoke void @__cxa_throw(ptr %[[EXN]], ptr @_ZTIi, ptr null)
|
|
// OGCG-NEXT: to label %[[NORMAL:.*]] unwind label %[[LPAD:.*]]
|
|
// OGCG: [[LPAD]]:
|
|
// OGCG: %{{.*}} = landingpad { ptr, i32 }
|
|
// OGCG-NEXT: cleanup
|
|
// OGCG: call void @_ZN5LocalD1Ev(ptr {{.*}} %[[X]])
|
|
// OGCG: resume { ptr, i32 } %{{.*}}
|
|
// OGCG: [[NORMAL]]:
|
|
// OGCG: unreachable
|