Files
TheRock/compiler/amd-llvm/clang/test/CIR/Transforms/canonicalize-cleanup-scope.cir
T
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

197 lines
5.2 KiB
Plaintext

// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s
!s32i = !cir.int<s, 32>
!rec_S = !cir.struct<"S" {!s32i}>
module {
cir.func private @dtor(!cir.ptr<!rec_S>) attributes {nothrow}
cir.func private @may_throw()
cir.func private @side_effect()
// EH cleanup with trivial body and trivial cleanup is erased (trivially dead).
cir.func @eh_both_trivial_erased() {
cir.cleanup.scope {
cir.yield
} cleanup eh {
cir.yield
}
cir.return
}
// CHECK-LABEL: @eh_both_trivial_erased
// CHECK-NEXT: cir.return
// EH cleanup with trivial body and non-trivial cleanup is erased: the body
// has no throwing operations so the EH cleanup can never fire.
cir.func @eh_empty_body_nontrivial_cleanup(%arg0: !cir.ptr<!rec_S>) {
cir.cleanup.scope {
cir.yield
} cleanup eh {
cir.call @dtor(%arg0) nothrow : (!cir.ptr<!rec_S>) -> ()
cir.yield
}
cir.return
}
// CHECK-LABEL: @eh_empty_body_nontrivial_cleanup
// CHECK-NEXT: cir.return
// EH cleanup with non-empty body should NOT be erased.
cir.func @eh_nonempty_body_kept(%arg0: !cir.ptr<!rec_S>) {
cir.cleanup.scope {
cir.call @may_throw() : () -> ()
cir.yield
} cleanup eh {
cir.call @dtor(%arg0) nothrow : (!cir.ptr<!rec_S>) -> ()
cir.yield
}
cir.return
}
// CHECK-LABEL: @eh_nonempty_body_kept
// CHECK: cir.cleanup.scope {
// CHECK: cir.call @may_throw()
// CHECK: cir.yield
// CHECK: } cleanup eh {
// CHECK: cir.call @dtor
// CHECK: cir.yield
// CHECK: }
// CHECK: cir.return
// All cleanup with non-trivial cleanup should NOT be erased.
cir.func @all_nonempty_cleanup_kept(%arg0: !cir.ptr<!rec_S>) {
cir.cleanup.scope {
cir.yield
} cleanup all {
cir.call @dtor(%arg0) nothrow : (!cir.ptr<!rec_S>) -> ()
cir.yield
}
cir.return
}
// CHECK-LABEL: @all_nonempty_cleanup_kept
// CHECK: cir.cleanup.scope {
// CHECK: cir.yield
// CHECK: } cleanup all {
// CHECK: cir.call @dtor
// CHECK: cir.yield
// CHECK: }
// CHECK: cir.return
// Normal cleanup with non-trivial cleanup should NOT be erased.
cir.func @normal_nonempty_cleanup_kept(%arg0: !cir.ptr<!rec_S>) {
cir.cleanup.scope {
cir.yield
} cleanup normal {
cir.call @dtor(%arg0) nothrow : (!cir.ptr<!rec_S>) -> ()
cir.yield
}
cir.return
}
// CHECK-LABEL: @normal_nonempty_cleanup_kept
// CHECK: cir.cleanup.scope {
// CHECK: cir.yield
// CHECK: } cleanup normal {
// CHECK: cir.call @dtor
// CHECK: cir.yield
// CHECK: }
// CHECK: cir.return
// Trivial cleanup region: body is inlined and scope is erased.
cir.func @trivial_cleanup_body_inlined() {
cir.cleanup.scope {
cir.call @side_effect() : () -> ()
cir.yield
} cleanup all {
cir.yield
}
cir.return
}
// CHECK-LABEL: @trivial_cleanup_body_inlined
// CHECK-NEXT: cir.call @side_effect()
// CHECK-NEXT: cir.return
// Trivial cleanup region with normal kind: body inlined.
cir.func @normal_trivial_cleanup_inlined() {
cir.cleanup.scope {
cir.call @side_effect() : () -> ()
cir.yield
} cleanup normal {
cir.yield
}
cir.return
}
// CHECK-LABEL: @normal_trivial_cleanup_inlined
// CHECK-NEXT: cir.call @side_effect()
// CHECK-NEXT: cir.return
// Trivial cleanup with multiple body ops: all inlined in order.
cir.func @trivial_cleanup_multi_ops(%arg0: !cir.ptr<!rec_S>) {
cir.cleanup.scope {
cir.call @may_throw() : () -> ()
cir.call @dtor(%arg0) nothrow : (!cir.ptr<!rec_S>) -> ()
cir.yield
} cleanup all {
cir.yield
}
cir.return
}
// CHECK-LABEL: @trivial_cleanup_multi_ops
// CHECK-NEXT: cir.call @may_throw()
// CHECK-NEXT: cir.call @dtor
// CHECK-NEXT: cir.return
// Nested: inner EH with empty body erased, outer kept.
cir.func @nested_inner_eh_erased(%arg0: !cir.ptr<!rec_S>) {
cir.cleanup.scope {
cir.call @may_throw() : () -> ()
cir.cleanup.scope {
cir.yield
} cleanup eh {
cir.call @dtor(%arg0) nothrow : (!cir.ptr<!rec_S>) -> ()
cir.yield
}
cir.yield
} cleanup eh {
cir.call @dtor(%arg0) nothrow : (!cir.ptr<!rec_S>) -> ()
cir.yield
}
cir.return
}
// CHECK-LABEL: @nested_inner_eh_erased
// CHECK: cir.cleanup.scope {
// CHECK: cir.call @may_throw()
// CHECK-NOT: cir.cleanup.scope
// CHECK: cir.yield
// CHECK: } cleanup eh {
// CHECK: cir.call @dtor
// CHECK: cir.yield
// CHECK: }
// CHECK: cir.return
// Nested: inner has trivial cleanup, outer does not. Inner body inlined
// into outer body; outer remains.
cir.func @nested_trivial_cleanup_inlined(%arg0: !cir.ptr<!rec_S>) {
cir.cleanup.scope {
cir.cleanup.scope {
cir.call @may_throw() : () -> ()
cir.yield
} cleanup eh {
cir.yield
}
cir.yield
} cleanup all {
cir.call @dtor(%arg0) nothrow : (!cir.ptr<!rec_S>) -> ()
cir.yield
}
cir.return
}
// CHECK-LABEL: @nested_trivial_cleanup_inlined
// CHECK: cir.cleanup.scope {
// CHECK-NEXT: cir.call @may_throw()
// CHECK-NEXT: cir.yield
// CHECK-NEXT: } cleanup all {
// CHECK: cir.call @dtor
// CHECK: cir.yield
// CHECK: }
// CHECK: cir.return
}