| 1 |
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir -mno-constructor-aliases %s -o %t.cir |
| 2 |
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR |
| 3 |
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -mno-constructor-aliases -o %t-cir.ll |
| 4 |
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM |
| 5 |
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -mno-constructor-aliases -o %t.ll |
| 6 |
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG |
| 7 |
|
| 8 |
void some_function() noexcept; |
| 9 |
|
| 10 |
struct out_of_line_destructor { |
| 11 |
int prevent_tail_padding_reuse; |
| 12 |
~out_of_line_destructor(); |
| 13 |
}; |
| 14 |
|
| 15 |
out_of_line_destructor::~out_of_line_destructor() { |
| 16 |
some_function(); |
| 17 |
} |
| 18 |
|
| 19 |
// CIR: !rec_out_of_line_destructor = !cir.record<struct "out_of_line_destructor" {!s32i}> |
| 20 |
|
| 21 |
// CIR: cir.func {{.*}} @_ZN22out_of_line_destructorD2Ev(%{{.+}}: !cir.ptr<!rec_out_of_line_destructor> |
| 22 |
// CIR: cir.call @_Z13some_functionv() nothrow : () -> () |
| 23 |
// CIR: cir.return |
| 24 |
|
| 25 |
// LLVM: define dso_local void @_ZN22out_of_line_destructorD2Ev(ptr %{{.+}}) |
| 26 |
// LLVM: call void @_Z13some_functionv() |
| 27 |
// LLVM: ret void |
| 28 |
|
| 29 |
// OGCG: define dso_local void @_ZN22out_of_line_destructorD2Ev(ptr {{.*}}%{{.+}}) |
| 30 |
// OGCG: call void @_Z13some_functionv() |
| 31 |
// OGCG: ret void |
| 32 |
|
| 33 |
// CIR: cir.func {{.*}} @_ZN22out_of_line_destructorD1Ev(%{{.+}}: !cir.ptr<!rec_out_of_line_destructor> |
| 34 |
// CIR: cir.call @_ZN22out_of_line_destructorD2Ev(%{{.*}}) nothrow : (!cir.ptr<!rec_out_of_line_destructor>) |
| 35 |
// CIR: cir.return |
| 36 |
|
| 37 |
// LLVM: define dso_local void @_ZN22out_of_line_destructorD1Ev(ptr %{{.+}}) |
| 38 |
// LLVM: call void @_ZN22out_of_line_destructorD2Ev |
| 39 |
// LLVM: ret void |
| 40 |
|
| 41 |
// OGCG: define dso_local void @_ZN22out_of_line_destructorD1Ev(ptr {{.*}}%{{.+}}) |
| 42 |
// OGCG: call void @_ZN22out_of_line_destructorD2Ev |
| 43 |
// OGCG: ret void |
| 44 |
|
| 45 |
struct inline_destructor { |
| 46 |
int prevent_tail_padding_reuse; |
| 47 |
~inline_destructor() noexcept(false) { |
| 48 |
some_function(); |
| 49 |
} |
| 50 |
}; |
| 51 |
|
| 52 |
// This inline destructor is not odr-used in this TU. |
| 53 |
// Make sure we don't emit a definition |
| 54 |
|
| 55 |
// CIR-NOT: cir.func {{.*}}inline_destructor{{.*}} |
| 56 |
// LLVM-NOT: define {{.*}}inline_destructor{{.*}} |
| 57 |
// OGCG-NOT: define {{.*}}inline_destructor{{.*}} |
| 58 |
|
| 59 |
struct array_element {~array_element();}; |
| 60 |
void test_array_destructor() { |
| 61 |
array_element arr[5]{}; |
| 62 |
} |
| 63 |
|
| 64 |
// CIR: cir.func {{.*}} @_Z21test_array_destructorv() |
| 65 |
// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!rec_array_element x 5>, !cir.ptr<!cir.array<!rec_array_element x 5>>, ["arr", init] |
| 66 |
// CIR: %[[ARR_PTR:.*]] = cir.alloca !cir.ptr<!rec_array_element>, !cir.ptr<!cir.ptr<!rec_array_element>>, ["arrayinit.temp", init] |
| 67 |
// CIR: %[[BEGIN:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!rec_array_element x 5>> |
| 68 |
// CIR: cir.store{{.*}} %[[BEGIN]], %[[ARR_PTR]] |
| 69 |
// CIR: %[[FIVE:.*]] = cir.const #cir.int<5> : !s64i |
| 70 |
// CIR: %[[ARR_END:.*]] = cir.ptr_stride %[[BEGIN]], %[[FIVE]] : (!cir.ptr<!rec_array_element>, !s64i) |
| 71 |
// CIR: cir.do { |
| 72 |
// CIR: %[[ARR_CUR:.*]] = cir.load{{.*}} %[[ARR_PTR]] |
| 73 |
// CIR: %[[ONE:.*]] = cir.const #cir.int<1> : !s64i |
| 74 |
// CIR: %[[ARR_NEXT:.*]] = cir.ptr_stride %[[ARR_CUR]], %[[ONE]] : (!cir.ptr<!rec_array_element>, !s64i) |
| 75 |
// CIR: cir.store{{.*}} %[[ARR_NEXT]], %[[ARR_PTR]] : !cir.ptr<!rec_array_element>, !cir.ptr<!cir.ptr<!rec_array_element>> |
| 76 |
// CIR: cir.yield |
| 77 |
// CIR: } while { |
| 78 |
// CIR: %[[ARR_CUR:.*]] = cir.load{{.*}} %[[ARR_PTR]] |
| 79 |
// CIR: %[[CMP:.*]] = cir.cmp(ne, %[[ARR_CUR]], %[[ARR_END]]) |
| 80 |
// CIR: cir.condition(%[[CMP]]) |
| 81 |
// CIR: } |
| 82 |
// CIR: %[[FOUR:.*]] = cir.const #cir.int<4> : !u64i |
| 83 |
// CIR: %[[BEGIN:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!rec_array_element x 5>> |
| 84 |
// CIR: %[[END:.*]] = cir.ptr_stride %[[BEGIN]], %[[FOUR]] : (!cir.ptr<!rec_array_element>, !u64i) |
| 85 |
// CIR: %[[ARR_PTR:.*]] = cir.alloca !cir.ptr<!rec_array_element>, !cir.ptr<!cir.ptr<!rec_array_element>>, ["__array_idx"] |
| 86 |
// CIR: cir.store %[[END]], %[[ARR_PTR]] |
| 87 |
// CIR: cir.do { |
| 88 |
// CIR: %[[ARR_CUR:.*]] = cir.load{{.*}} %[[ARR_PTR]] |
| 89 |
// CIR: cir.call @_ZN13array_elementD1Ev(%[[ARR_CUR]]) nothrow : (!cir.ptr<!rec_array_element>) -> () |
| 90 |
// CIR: %[[NEG_ONE:.*]] = cir.const #cir.int<-1> : !s64i |
| 91 |
// CIR: %[[ARR_NEXT:.*]] = cir.ptr_stride %[[ARR_CUR]], %[[NEG_ONE]] : (!cir.ptr<!rec_array_element>, !s64i) |
| 92 |
// CIR: cir.store %[[ARR_NEXT]], %[[ARR_PTR]] |
| 93 |
// CIR: cir.yield |
| 94 |
// CIR: } while { |
| 95 |
// CIR: %[[ARR_CUR:.*]] = cir.load{{.*}} %[[ARR_PTR]] |
| 96 |
// CIR: %[[CMP:.*]] = cir.cmp(ne, %[[ARR_CUR]], %[[BEGIN]]) |
| 97 |
// CIR: cir.condition(%[[CMP]]) |
| 98 |
// CIR: } |
| 99 |
|
| 100 |
// LLVM: define{{.*}} void @_Z21test_array_destructorv() |
| 101 |
// LLVM: %[[ARR:.*]] = alloca [5 x %struct.array_element] |
| 102 |
// LLVM: %[[TMP:.*]] = alloca ptr |
| 103 |
// LLVM: %[[ARR_PTR:.*]] = getelementptr %struct.array_element, ptr %[[ARR]], i32 0 |
| 104 |
// LLVM: store ptr %[[ARR_PTR]], ptr %[[TMP]] |
| 105 |
// LLVM: %[[END_PTR:.*]] = getelementptr %struct.array_element, ptr %[[ARR_PTR]], i64 5 |
| 106 |
// LLVM: br label %[[INIT_LOOP_BODY:.*]] |
| 107 |
// LLVM: [[INIT_LOOP_NEXT:.*]]: |
| 108 |
// LLVM: %[[CUR:.*]] = load ptr, ptr %[[TMP]] |
| 109 |
// LLVM: %[[CMP:.*]] = icmp ne ptr %[[CUR]], %[[END_PTR]] |
| 110 |
// LLVM: br i1 %[[CMP]], label %[[INIT_LOOP_BODY]], label %[[INIT_LOOP_END:.*]] |
| 111 |
// LLVM: [[INIT_LOOP_BODY]]: |
| 112 |
// LLVM: %[[CUR:.*]] = load ptr, ptr %[[TMP]] |
| 113 |
// LLVM: %[[NEXT:.*]] = getelementptr %struct.array_element, ptr %[[CUR]], i64 1 |
| 114 |
// LLVM: store ptr %[[NEXT]], ptr %[[TMP]] |
| 115 |
// LLVM: br label %[[INIT_LOOP_NEXT:.*]] |
| 116 |
// LLVM: [[INIT_LOOP_END]]: |
| 117 |
// LLVM: %[[ARR_BEGIN:.*]] = getelementptr %struct.array_element, ptr %[[ARR]], i32 0 |
| 118 |
// LLVM: %[[ARR_END:.*]] = getelementptr %struct.array_element, ptr %[[ARR_BEGIN]], i64 4 |
| 119 |
// LLVM: %[[ARR_CUR:.*]] = alloca ptr |
| 120 |
// LLVM: store ptr %[[ARR_END]], ptr %[[ARR_CUR]] |
| 121 |
// LLVM: br label %[[DESTROY_LOOP_BODY:.*]] |
| 122 |
// LLVM: [[DESTROY_LOOP_NEXT:.*]]: |
| 123 |
// LLVM: %[[CUR:.*]] = load ptr, ptr %[[ARR_CUR]] |
| 124 |
// LLVM: %[[CMP:.*]] = icmp ne ptr %[[CUR]], %[[ARR_BEGIN]] |
| 125 |
// LLVM: br i1 %[[CMP]], label %[[DESTROY_LOOP_BODY]], label %[[DESTROY_LOOP_END:.*]] |
| 126 |
// LLVM: [[DESTROY_LOOP_BODY]]: |
| 127 |
// LLVM: %[[CUR:.*]] = load ptr, ptr %[[ARR_CUR]] |
| 128 |
// LLVM: call void @_ZN13array_elementD1Ev(ptr %[[CUR]]) |
| 129 |
// LLVM: %[[PREV:.*]] = getelementptr %struct.array_element, ptr %[[CUR]], i64 -1 |
| 130 |
// LLVM: store ptr %[[PREV]], ptr %[[ARR_CUR]] |
| 131 |
// LLVM: br label %[[DESTROY_LOOP_NEXT]] |
| 132 |
// LLVM: [[DESTROY_LOOP_END]]: |
| 133 |
// LLVM: ret void |
| 134 |
|
| 135 |
// OGCG: define{{.*}} void @_Z21test_array_destructorv() |
| 136 |
// OGCG: entry: |
| 137 |
// OGCG: %[[ARR:.*]] = alloca [5 x %struct.array_element] |
| 138 |
// OGCG: %[[ARRAYINIT_END:.*]] = getelementptr inbounds %struct.array_element, ptr %[[ARR]], i64 5 |
| 139 |
// OGCG: br label %[[INIT_LOOP_BODY:.*]] |
| 140 |
// OGCG: [[INIT_LOOP_BODY]]: |
| 141 |
// OGCG: %[[CUR:.*]] = phi ptr [ %[[ARR]], %entry ], [ %[[NEXT:.*]], %[[INIT_LOOP_BODY]] ] |
| 142 |
// OGCG: %[[NEXT]] = getelementptr inbounds %struct.array_element, ptr %[[CUR]], i64 1 |
| 143 |
// OGCG: %[[CMP:.*]] = icmp eq ptr %[[NEXT]], %[[ARRAYINIT_END]] |
| 144 |
// OGCG: br i1 %[[CMP]], label %[[INIT_LOOP_END:.*]], label %[[INIT_LOOP_BODY]] |
| 145 |
// OGCG: [[INIT_LOOP_END:.*]]: |
| 146 |
// OGCG: %[[BEGIN:.*]] = getelementptr inbounds [5 x %struct.array_element], ptr %[[ARR]], i32 0, i32 0 |
| 147 |
// OGCG: %[[END:.*]] = getelementptr inbounds %struct.array_element, ptr %[[BEGIN]], i64 5 |
| 148 |
// OGCG: br label %[[DESTROY_LOOP_BODY:.*]] |
| 149 |
// OGCG: [[DESTROY_LOOP_BODY:.*]]: |
| 150 |
// OGCG: %[[CUR:.*]] = phi ptr [ %[[END]], %[[INIT_LOOP_END]] ], [ %[[PREV:.*]], %[[DESTROY_LOOP_BODY]] ] |
| 151 |
// OGCG: %[[PREV]] = getelementptr inbounds %struct.array_element, ptr %[[CUR]], i64 -1 |
| 152 |
// OGCG: call void @_ZN13array_elementD1Ev(ptr {{.*}} %[[PREV]]) |
| 153 |
// OGCG: %[[CMP:.*]] = icmp eq ptr %[[PREV]], %[[BEGIN]] |
| 154 |
// OGCG: br i1 %[[CMP]], label %[[DESTROY_LOOP_END:.*]], label %[[DESTROY_LOOP_BODY]] |
| 155 |
// OGCG: [[DESTROY_LOOP_END:.*]]: |
| 156 |
// OGCG: ret void |