[clang] [CIR] Represent Cleanups with Cleanup scopes (PR #180276)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 18 14:02:07 PST 2026
================
@@ -79,25 +79,32 @@ void test_array_destructor() {
// CIR: %[[CMP:.*]] = cir.cmp(ne, %[[ARR_CUR]], %[[ARR_END]])
// CIR: cir.condition(%[[CMP]])
// CIR: }
-// CIR: %[[FOUR:.*]] = cir.const #cir.int<4> : !u64i
-// CIR: %[[BEGIN:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!rec_array_element x 5>>
-// CIR: %[[END:.*]] = cir.ptr_stride %[[BEGIN]], %[[FOUR]] : (!cir.ptr<!rec_array_element>, !u64i)
-// CIR: %[[ARR_PTR:.*]] = cir.alloca !cir.ptr<!rec_array_element>, !cir.ptr<!cir.ptr<!rec_array_element>>, ["__array_idx"]
-// CIR: cir.store %[[END]], %[[ARR_PTR]]
-// CIR: cir.do {
-// CIR: %[[ARR_CUR:.*]] = cir.load{{.*}} %[[ARR_PTR]]
-// CIR: cir.call @_ZN13array_elementD1Ev(%[[ARR_CUR]]) nothrow : (!cir.ptr<!rec_array_element>) -> ()
-// CIR: %[[NEG_ONE:.*]] = cir.const #cir.int<-1> : !s64i
-// CIR: %[[ARR_NEXT:.*]] = cir.ptr_stride %[[ARR_CUR]], %[[NEG_ONE]] : (!cir.ptr<!rec_array_element>, !s64i)
-// CIR: cir.store %[[ARR_NEXT]], %[[ARR_PTR]]
+// CIR: cir.cleanup.scope {
+// CIR: cir.yield
+// CIR: } cleanup normal {
+// CIR: %[[FOUR:.*]] = cir.const #cir.int<4> : !u64i
+// CIR: %[[BEGIN:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!rec_array_element x 5>>
+// CIR: %[[END:.*]] = cir.ptr_stride %[[BEGIN]], %[[FOUR]] : (!cir.ptr<!rec_array_element>, !u64i)
+// CIR: %[[ARR_PTR:.*]] = cir.alloca !cir.ptr<!rec_array_element>, !cir.ptr<!cir.ptr<!rec_array_element>>, ["__array_idx"]
+// CIR: cir.store %[[END]], %[[ARR_PTR]]
+// CIR: cir.do {
+// CIR: %[[ARR_CUR:.*]] = cir.load{{.*}} %[[ARR_PTR]]
+// CIR: cir.call @_ZN13array_elementD1Ev(%[[ARR_CUR]]) nothrow : (!cir.ptr<!rec_array_element>) -> ()
+// CIR: %[[NEG_ONE:.*]] = cir.const #cir.int<-1> : !s64i
+// CIR: %[[ARR_NEXT:.*]] = cir.ptr_stride %[[ARR_CUR]], %[[NEG_ONE]] : (!cir.ptr<!rec_array_element>, !s64i)
+// CIR: cir.store %[[ARR_NEXT]], %[[ARR_PTR]]
+// CIR: cir.yield
+// CIR: } while {
+// CIR: %[[ARR_CUR:.*]] = cir.load{{.*}} %[[ARR_PTR]]
+// CIR: %[[CMP:.*]] = cir.cmp(ne, %[[ARR_CUR]], %[[BEGIN]])
+// CIR: cir.condition(%[[CMP]])
+// CIR: }
// CIR: cir.yield
-// CIR: } while {
-// CIR: %[[ARR_CUR:.*]] = cir.load{{.*}} %[[ARR_PTR]]
-// CIR: %[[CMP:.*]] = cir.cmp(ne, %[[ARR_CUR]], %[[BEGIN]])
-// CIR: cir.condition(%[[CMP]])
// CIR: }
+
// LLVM: define{{.*}} void @_Z21test_array_destructorv()
+// LLVM: %[[ARR_CUR:.*]] = alloca ptr, i64 1
----------------
andykaylor wrote:
```suggestion
// LLVM: %[[ARR_CUR:.*]] = alloca ptr
```
https://github.com/llvm/llvm-project/pull/180276
More information about the cfe-commits
mailing list