| 1 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t.cir 2> %t-before.cir |
| 2 |
// RUN: FileCheck --input-file=%t-before.cir %s --check-prefix=CIR-BEFORE-LPP |
| 3 |
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR |
| 4 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll |
| 5 |
// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM |
| 6 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll |
| 7 |
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG |
| 8 |
|
| 9 |
// Declarations that appear before global-specific definitions |
| 10 |
|
| 11 |
// CIR: module @{{.*}} attributes { |
| 12 |
// CIR-SAME: cir.global_ctors = [#cir.global_ctor<"_GLOBAL__sub_I_[[FILENAME:.*]]", 65535>] |
| 13 |
|
| 14 |
// LLVM: @__dso_handle = external hidden global i8 |
| 15 |
// LLVM: @needsCtor = global %struct.NeedsCtor zeroinitializer, align 1 |
| 16 |
// LLVM: @needsDtor = global %struct.NeedsDtor zeroinitializer, align 1 |
| 17 |
// LLVM: @needsCtorDtor = global %struct.NeedsCtorDtor zeroinitializer, align 1 |
| 18 |
// LLVM: @arrDtor = global [16 x %struct.ArrayDtor] zeroinitializer, align 16 |
| 19 |
// LLVM: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_[[FILENAME:.*]], ptr null }] |
| 20 |
|
| 21 |
// OGCG: @needsCtor = global %struct.NeedsCtor zeroinitializer, align 1 |
| 22 |
// OGCG: @needsDtor = global %struct.NeedsDtor zeroinitializer, align 1 |
| 23 |
// OGCG: @__dso_handle = external hidden global i8 |
| 24 |
// OGCG: @needsCtorDtor = global %struct.NeedsCtorDtor zeroinitializer, align 1 |
| 25 |
// OGCG: @arrDtor = global [16 x %struct.ArrayDtor] zeroinitializer, align 16 |
| 26 |
// OGCG: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_[[FILENAME:.*]], ptr null }] |
| 27 |
|
| 28 |
struct NeedsCtor { |
| 29 |
NeedsCtor(); |
| 30 |
}; |
| 31 |
|
| 32 |
NeedsCtor needsCtor; |
| 33 |
|
| 34 |
// CIR-BEFORE-LPP: cir.global external @needsCtor = ctor : !rec_NeedsCtor { |
| 35 |
// CIR-BEFORE-LPP: %[[THIS:.*]] = cir.get_global @needsCtor : !cir.ptr<!rec_NeedsCtor> |
| 36 |
// CIR-BEFORE-LPP: cir.call @_ZN9NeedsCtorC1Ev(%[[THIS]]) : (!cir.ptr<!rec_NeedsCtor>) -> () |
| 37 |
|
| 38 |
// CIR: cir.global external @needsCtor = #cir.zero : !rec_NeedsCtor |
| 39 |
// CIR: cir.func internal private @__cxx_global_var_init() { |
| 40 |
// CIR: %0 = cir.get_global @needsCtor : !cir.ptr<!rec_NeedsCtor> |
| 41 |
// CIR: cir.call @_ZN9NeedsCtorC1Ev(%0) : (!cir.ptr<!rec_NeedsCtor>) -> () |
| 42 |
|
| 43 |
// LLVM: define internal void @__cxx_global_var_init() |
| 44 |
// LLVM: call void @_ZN9NeedsCtorC1Ev(ptr @needsCtor) |
| 45 |
|
| 46 |
// OGCG: define internal void @__cxx_global_var_init() {{.*}} section ".text.startup" { |
| 47 |
// OGCG: call void @_ZN9NeedsCtorC1Ev(ptr noundef nonnull align 1 dereferenceable(1) @needsCtor) |
| 48 |
|
| 49 |
|
| 50 |
struct NeedsDtor { |
| 51 |
~NeedsDtor(); |
| 52 |
}; |
| 53 |
|
| 54 |
NeedsDtor needsDtor; |
| 55 |
|
| 56 |
// CIR-BEFORE-LPP: cir.global external @needsDtor = #cir.zero : !rec_NeedsDtor dtor { |
| 57 |
// CIR-BEFORE-LPP: %[[THIS:.*]] = cir.get_global @needsDtor : !cir.ptr<!rec_NeedsDtor> |
| 58 |
// CIR-BEFORE-LPP: cir.call @_ZN9NeedsDtorD1Ev(%[[THIS]]) : (!cir.ptr<!rec_NeedsDtor>) -> () |
| 59 |
|
| 60 |
// CIR: cir.global external @needsDtor = #cir.zero : !rec_NeedsDtor |
| 61 |
// CIR: cir.func internal private @__cxx_global_var_init.1() { |
| 62 |
// CIR: %[[OBJ:.*]] = cir.get_global @needsDtor : !cir.ptr<!rec_NeedsDtor> |
| 63 |
// CIR: %[[DTOR:.*]] = cir.get_global @_ZN9NeedsDtorD1Ev : !cir.ptr<!cir.func<(!cir.ptr<!rec_NeedsDtor>)>> |
| 64 |
// CIR: %[[DTOR_CAST:.*]] = cir.cast bitcast %[[DTOR]] : !cir.ptr<!cir.func<(!cir.ptr<!rec_NeedsDtor>)>> -> !cir.ptr<!cir.func<(!cir.ptr<!void>)>> |
| 65 |
// CIR: %[[OBJ_CAST:.*]] = cir.cast bitcast %[[OBJ]] : !cir.ptr<!rec_NeedsDtor> -> !cir.ptr<!void> |
| 66 |
// CIR: %[[HANDLE:.*]] = cir.get_global @__dso_handle : !cir.ptr<i8> |
| 67 |
// CIR: cir.call @__cxa_atexit(%[[DTOR_CAST]], %[[OBJ_CAST]], %[[HANDLE]]) : (!cir.ptr<!cir.func<(!cir.ptr<!void>)>>, !cir.ptr<!void>, !cir.ptr<i8>) -> () |
| 68 |
|
| 69 |
// LLVM: define internal void @__cxx_global_var_init.1() { |
| 70 |
// LLVM: call void @__cxa_atexit(ptr @_ZN9NeedsDtorD1Ev, ptr @needsDtor, ptr @__dso_handle) |
| 71 |
|
| 72 |
// OGCG: define internal void @__cxx_global_var_init.1() {{.*}} section ".text.startup" { |
| 73 |
// OGCG: %{{.*}} = call i32 @__cxa_atexit(ptr @_ZN9NeedsDtorD1Ev, ptr @needsDtor, ptr @__dso_handle) |
| 74 |
|
| 75 |
struct NeedsCtorDtor { |
| 76 |
NeedsCtorDtor(); |
| 77 |
~NeedsCtorDtor(); |
| 78 |
}; |
| 79 |
|
| 80 |
NeedsCtorDtor needsCtorDtor; |
| 81 |
|
| 82 |
// CIR-BEFORE-LPP: cir.global external @needsCtorDtor = ctor : !rec_NeedsCtorDtor { |
| 83 |
// CIR-BEFORE-LPP: %[[THIS:.*]] = cir.get_global @needsCtorDtor : !cir.ptr<!rec_NeedsCtorDtor> |
| 84 |
// CIR-BEFORE-LPP: cir.call @_ZN13NeedsCtorDtorC1Ev(%[[THIS]]) : (!cir.ptr<!rec_NeedsCtorDtor>) -> () |
| 85 |
// CIR-BEFORE-LPP: } dtor { |
| 86 |
// CIR-BEFORE-LPP: %[[THIS:.*]] = cir.get_global @needsCtorDtor : !cir.ptr<!rec_NeedsCtorDtor> |
| 87 |
// CIR-BEFORE-LPP: cir.call @_ZN13NeedsCtorDtorD1Ev(%[[THIS]]) : (!cir.ptr<!rec_NeedsCtorDtor>) -> () |
| 88 |
|
| 89 |
// CIR: cir.global external @needsCtorDtor = #cir.zero : !rec_NeedsCtorDtor |
| 90 |
// CIR: cir.func internal private @__cxx_global_var_init.2() { |
| 91 |
// CIR: %[[OBJ:.*]] = cir.get_global @needsCtorDtor : !cir.ptr<!rec_NeedsCtorDtor> |
| 92 |
// CIR: cir.call @_ZN13NeedsCtorDtorC1Ev(%[[OBJ]]) : (!cir.ptr<!rec_NeedsCtorDtor>) -> () |
| 93 |
// CIR: %[[OBJ:.*]] = cir.get_global @needsCtorDtor : !cir.ptr<!rec_NeedsCtorDtor> |
| 94 |
// CIR: %[[DTOR:.*]] = cir.get_global @_ZN13NeedsCtorDtorD1Ev : !cir.ptr<!cir.func<(!cir.ptr<!rec_NeedsCtorDtor>)>> |
| 95 |
// CIR: %[[DTOR_CAST:.*]] = cir.cast bitcast %[[DTOR]] : !cir.ptr<!cir.func<(!cir.ptr<!rec_NeedsCtorDtor>)>> -> !cir.ptr<!cir.func<(!cir.ptr<!void>)>> |
| 96 |
// CIR: %[[OBJ_CAST:.*]] = cir.cast bitcast %[[OBJ]] : !cir.ptr<!rec_NeedsCtorDtor> -> !cir.ptr<!void> |
| 97 |
// CIR: %[[HANDLE:.*]] = cir.get_global @__dso_handle : !cir.ptr<i8> |
| 98 |
// CIR: cir.call @__cxa_atexit(%[[DTOR_CAST]], %[[OBJ_CAST]], %[[HANDLE]]) : (!cir.ptr<!cir.func<(!cir.ptr<!void>)>>, !cir.ptr<!void>, !cir.ptr<i8>) -> () |
| 99 |
|
| 100 |
// LLVM: define internal void @__cxx_global_var_init.2() { |
| 101 |
// LLVM: call void @_ZN13NeedsCtorDtorC1Ev(ptr @needsCtorDtor) |
| 102 |
// LLVM: call void @__cxa_atexit(ptr @_ZN13NeedsCtorDtorD1Ev, ptr @needsCtorDtor, ptr @__dso_handle) |
| 103 |
|
| 104 |
// OGCG: define internal void @__cxx_global_var_init.2() {{.*}} section ".text.startup" { |
| 105 |
// OGCG: call void @_ZN13NeedsCtorDtorC1Ev(ptr noundef nonnull align 1 dereferenceable(1) @needsCtorDtor) |
| 106 |
// OGCG: %{{.*}} = call i32 @__cxa_atexit(ptr @_ZN13NeedsCtorDtorD1Ev, ptr @needsCtorDtor, ptr @__dso_handle) |
| 107 |
|
| 108 |
float num; |
| 109 |
float _Complex a = {num, num}; |
| 110 |
|
| 111 |
// CIR-BEFORE-LPP: cir.global external @num = #cir.fp<0.000000e+00> : !cir.float |
| 112 |
// CIR-BEFORE-LPP: cir.global external @a = ctor : !cir.complex<!cir.float> { |
| 113 |
// CIR-BEFORE-LPP: %[[THIS:.*]] = cir.get_global @a : !cir.ptr<!cir.complex<!cir.float>> |
| 114 |
// CIR-BEFORE-LPP: %[[NUM:.*]] = cir.get_global @num : !cir.ptr<!cir.float> |
| 115 |
// CIR-BEFORE-LPP: %[[REAL:.*]] = cir.load{{.*}} %[[NUM]] : !cir.ptr<!cir.float>, !cir.float |
| 116 |
// CIR-BEFORE-LPP: %[[NUM:.*]] = cir.get_global @num : !cir.ptr<!cir.float> |
| 117 |
// CIR-BEFORE-LPP: %[[IMAG:.*]] = cir.load{{.*}} %[[NUM]] : !cir.ptr<!cir.float>, !cir.float |
| 118 |
// CIR-BEFORE-LPP: %[[COMPLEX_VAL:.*]] = cir.complex.create %[[REAL]], %[[IMAG]] : !cir.float -> !cir.complex<!cir.float> |
| 119 |
// CIR-BEFORE-LPP: cir.store{{.*}} %[[COMPLEX_VAL:.*]], %[[THIS]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>> |
| 120 |
// CIR-BEFORE-LPP: } |
| 121 |
|
| 122 |
// CIR: cir.global external @num = #cir.fp<0.000000e+00> : !cir.float |
| 123 |
// CIR: cir.global external @a = #cir.zero : !cir.complex<!cir.float> |
| 124 |
// CIR: cir.func internal private @__cxx_global_var_init.3() |
| 125 |
// CIR: %[[A_ADDR:.*]] = cir.get_global @a : !cir.ptr<!cir.complex<!cir.float>> |
| 126 |
// CIR: %[[NUM:.*]] = cir.get_global @num : !cir.ptr<!cir.float> |
| 127 |
// CIR: %[[REAL:.*]] = cir.load{{.*}} %[[NUM]] : !cir.ptr<!cir.float>, !cir.float |
| 128 |
// CIR: %[[NUM:.*]] = cir.get_global @num : !cir.ptr<!cir.float> |
| 129 |
// CIR: %[[IMAG:.*]] = cir.load{{.*}} %[[NUM]] : !cir.ptr<!cir.float>, !cir.float |
| 130 |
// CIR: %[[COMPLEX_VAL:.*]] = cir.complex.create %[[REAL]], %[[IMAG]] : !cir.float -> !cir.complex<!cir.float> |
| 131 |
// CIR: cir.store{{.*}} %[[COMPLEX_VAL]], %[[A_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>> |
| 132 |
|
| 133 |
// LLVM: define internal void @__cxx_global_var_init.3() |
| 134 |
// LLVM: %[[REAL:.*]] = load float, ptr @num, align 4 |
| 135 |
// LLVM: %[[IMAG:.*]] = load float, ptr @num, align 4 |
| 136 |
// LLVM: %[[TMP_COMPLEX_VAL:.*]] = insertvalue { float, float } {{.*}}, float %[[REAL]], 0 |
| 137 |
// LLVM: %[[COMPLEX_VAL:.*]] = insertvalue { float, float } %[[TMP_COMPLEX_VAL]], float %[[IMAG]], 1 |
| 138 |
// LLVM: store { float, float } %[[COMPLEX_VAL]], ptr @a, align 4 |
| 139 |
|
| 140 |
// OGCG: define internal void @__cxx_global_var_init.3() {{.*}} section ".text.startup" |
| 141 |
// OGCG: %[[REAL:.*]] = load float, ptr @num, align 4 |
| 142 |
// OGCG: %[[IMAG:.*]] = load float, ptr @num, align 4 |
| 143 |
// OGCG: store float %[[REAL]], ptr @a, align 4 |
| 144 |
// OGCG: store float %[[IMAG]], ptr getelementptr inbounds nuw ({ float, float }, ptr @a, i32 0, i32 1), align 4 |
| 145 |
|
| 146 |
float fp; |
| 147 |
int i = (int)fp; |
| 148 |
|
| 149 |
// CIR-BEFORE-LPP: cir.global external @i = ctor : !s32i { |
| 150 |
// CIR-BEFORE-LPP: %[[I:.*]] = cir.get_global @i : !cir.ptr<!s32i> |
| 151 |
// CIR-BEFORE-LPP: %[[FP:.*]] = cir.get_global @fp : !cir.ptr<!cir.float> |
| 152 |
// CIR-BEFORE-LPP: %[[FP_VAL:.*]] = cir.load{{.*}} %[[FP]] : !cir.ptr<!cir.float>, !cir.float |
| 153 |
// CIR-BEFORE-LPP: %[[FP_I32:.*]] = cir.cast float_to_int %[[FP_VAL]] : !cir.float -> !s32i |
| 154 |
// CIR-BEFORE-LPP: cir.store{{.*}} %[[FP_I32]], %[[I]] : !s32i, !cir.ptr<!s32i> |
| 155 |
// CIR-BEFORE-LPP: } |
| 156 |
|
| 157 |
// CIR: cir.func internal private @__cxx_global_var_init.4() |
| 158 |
// CIR: %[[I_ADDR:.*]] = cir.get_global @i : !cir.ptr<!s32i> |
| 159 |
// CIR: %[[FP_ADDR:.*]] = cir.get_global @fp : !cir.ptr<!cir.float> |
| 160 |
// CIR: %[[TMP_FP:.*]] = cir.load{{.*}} %[[FP_ADDR]] : !cir.ptr<!cir.float>, !cir.float |
| 161 |
// CIR: %[[FP_I32:.*]] = cir.cast float_to_int %[[TMP_FP]] : !cir.float -> !s32i |
| 162 |
// CIR: cir.store{{.*}} %[[FP_I32]], %[[I_ADDR]] : !s32i, !cir.ptr<!s32i> |
| 163 |
|
| 164 |
// LLVM: define internal void @__cxx_global_var_init.4() |
| 165 |
// LLVM: %[[TMP_FP:.*]] = load float, ptr @fp, align 4 |
| 166 |
// LLVM: %[[FP_I32:.*]] = fptosi float %[[TMP_FP]] to i32 |
| 167 |
// LLVM: store i32 %[[FP_I32]], ptr @i, align 4 |
| 168 |
|
| 169 |
// OGCG: define internal void @__cxx_global_var_init.4() {{.*}} section ".text.startup" |
| 170 |
// OGCG: %[[TMP_FP:.*]] = load float, ptr @fp, align 4 |
| 171 |
// OGCG: %[[FP_I32:.*]] = fptosi float %[[TMP_FP]] to i32 |
| 172 |
// OGCG: store i32 %[[FP_I32]], ptr @i, align 4 |
| 173 |
|
| 174 |
struct ArrayDtor { |
| 175 |
~ArrayDtor(); |
| 176 |
}; |
| 177 |
|
| 178 |
ArrayDtor arrDtor[16]; |
| 179 |
|
| 180 |
// CIR-BEFORE-LPP: cir.global external @arrDtor = #cir.zero : !cir.array<!rec_ArrayDtor x 16> |
| 181 |
// CIR-BEFORE-LPP-SAME: dtor { |
| 182 |
// CIR-BEFORE-LPP: %[[THIS:.*]] = cir.get_global @arrDtor : !cir.ptr<!cir.array<!rec_ArrayDtor x 16>> |
| 183 |
// CIR-BEFORE-LPP: cir.array.dtor %[[THIS]] : !cir.ptr<!cir.array<!rec_ArrayDtor x 16>> { |
| 184 |
// CIR-BEFORE-LPP: ^bb0(%[[ELEM:.*]]: !cir.ptr<!rec_ArrayDtor>): |
| 185 |
// CIR-BEFORE-LPP: cir.call @_ZN9ArrayDtorD1Ev(%[[ELEM]]) nothrow : (!cir.ptr<!rec_ArrayDtor>) -> () |
| 186 |
// CIR-BEFORE-LPP: cir.yield |
| 187 |
// CIR-BEFORE-LPP: } |
| 188 |
// CIR-BEFORE-LPP: } |
| 189 |
|
| 190 |
// CIR: cir.global external @arrDtor = #cir.zero : !cir.array<!rec_ArrayDtor x 16> {alignment = 16 : i64} |
| 191 |
// CIR: cir.func internal private @__cxx_global_array_dtor(%[[ARR_ARG:.*]]: !cir.ptr<!void> {{.*}}) { |
| 192 |
// CIR: %[[CONST15:.*]] = cir.const #cir.int<15> : !u64i |
| 193 |
// CIR: %[[BEGIN:.*]] = cir.cast array_to_ptrdecay %[[ARR_ARG]] : !cir.ptr<!void> -> !cir.ptr<!rec_ArrayDtor> |
| 194 |
// CIR: %[[END:.*]] = cir.ptr_stride %[[BEGIN]], %[[CONST15]] : (!cir.ptr<!rec_ArrayDtor>, !u64i) -> !cir.ptr<!rec_ArrayDtor> |
| 195 |
// CIR: %[[CUR_ADDR:.*]] = cir.alloca !cir.ptr<!rec_ArrayDtor>, !cir.ptr<!cir.ptr<!rec_ArrayDtor>>, ["__array_idx"] |
| 196 |
// CIR: cir.store %[[END]], %[[CUR_ADDR]] : !cir.ptr<!rec_ArrayDtor>, !cir.ptr<!cir.ptr<!rec_ArrayDtor>> |
| 197 |
// CIR: cir.do { |
| 198 |
// CIR: %[[CUR:.*]] = cir.load %[[CUR_ADDR]] : !cir.ptr<!cir.ptr<!rec_ArrayDtor>>, !cir.ptr<!rec_ArrayDtor> |
| 199 |
// CIR: cir.call @_ZN9ArrayDtorD1Ev(%[[CUR]]) nothrow : (!cir.ptr<!rec_ArrayDtor>) -> () |
| 200 |
// CIR: %[[NEG_ONE:.*]] = cir.const #cir.int<-1> : !s64i |
| 201 |
// CIR: %[[NEXT:.*]] = cir.ptr_stride %[[CUR]], %[[NEG_ONE]] : (!cir.ptr<!rec_ArrayDtor>, !s64i) -> !cir.ptr<!rec_ArrayDtor> |
| 202 |
// CIR: cir.store %[[NEXT]], %[[CUR_ADDR]] : !cir.ptr<!rec_ArrayDtor>, !cir.ptr<!cir.ptr<!rec_ArrayDtor>> |
| 203 |
// CIR: cir.yield |
| 204 |
// CIR: } while { |
| 205 |
// CIR: %[[CUR:.*]] = cir.load %[[CUR_ADDR]] : !cir.ptr<!cir.ptr<!rec_ArrayDtor>>, !cir.ptr<!rec_ArrayDtor> |
| 206 |
// CIR: %[[CMP:.*]] = cir.cmp(ne, %[[CUR]], %[[BEGIN]]) : !cir.ptr<!rec_ArrayDtor>, !cir.bool |
| 207 |
// CIR: cir.condition(%[[CMP]]) |
| 208 |
// CIR: } |
| 209 |
// CIR: cir.return |
| 210 |
// CIR: } |
| 211 |
// |
| 212 |
// CIR: cir.func internal private @__cxx_global_var_init.5() { |
| 213 |
// CIR: %[[ARR:.*]] = cir.get_global @arrDtor : !cir.ptr<!cir.array<!rec_ArrayDtor x 16>> |
| 214 |
// CIR: %[[DTOR:.*]] = cir.get_global @__cxx_global_array_dtor : !cir.ptr<!cir.func<(!cir.ptr<!void>)>> |
| 215 |
// CIR: %[[DTOR_CAST:.*]] = cir.cast bitcast %[[DTOR]] : !cir.ptr<!cir.func<(!cir.ptr<!void>)>> -> !cir.ptr<!cir.func<(!cir.ptr<!void>)>> |
| 216 |
// CIR: %[[ARR_CAST:.*]] = cir.cast bitcast %[[ARR]] : !cir.ptr<!cir.array<!rec_ArrayDtor x 16>> -> !cir.ptr<!void> |
| 217 |
// CIR: %[[HANDLE:.*]] = cir.get_global @__dso_handle : !cir.ptr<i8> |
| 218 |
// CIR: cir.call @__cxa_atexit(%[[DTOR_CAST]], %[[ARR_CAST]], %[[HANDLE]]) : (!cir.ptr<!cir.func<(!cir.ptr<!void>)>>, !cir.ptr<!void>, !cir.ptr<i8>) -> () |
| 219 |
|
| 220 |
// LLVM: define internal void @__cxx_global_array_dtor(ptr %[[ARR_ARG:.*]]) { |
| 221 |
// LLVM: %[[BEGIN:.*]] = getelementptr %struct.ArrayDtor, ptr %[[ARR_ARG]], i32 0 |
| 222 |
// LLVM: %[[END:.*]] = getelementptr %struct.ArrayDtor, ptr %[[BEGIN]], i64 15 |
| 223 |
// LLVM: %[[CUR_ADDR:.*]] = alloca ptr |
| 224 |
// LLVM: store ptr %[[END]], ptr %[[CUR_ADDR]] |
| 225 |
// LLVM: br label %[[LOOP_BODY:.*]] |
| 226 |
// LLVM: [[LOOP_COND:.*]]: |
| 227 |
// LLVM: %[[CUR:.*]] = load ptr, ptr %[[CUR_ADDR]] |
| 228 |
// LLVM: %[[CMP:.*]] = icmp ne ptr %[[CUR]], %[[BEGIN]] |
| 229 |
// LLVM: br i1 %[[CMP]], label %[[LOOP_BODY]], label %[[LOOP_END:.*]] |
| 230 |
// LLVM: [[LOOP_BODY]]: |
| 231 |
// LLVM: %[[CUR:.*]] = load ptr, ptr %[[CUR_ADDR]] |
| 232 |
// LLVM: call void @_ZN9ArrayDtorD1Ev(ptr %[[CUR]]) #0 |
| 233 |
// LLVM: %[[PREV:.*]] = getelementptr %struct.ArrayDtor, ptr %[[CUR]], i64 -1 |
| 234 |
// LLVM: store ptr %[[PREV]], ptr %[[CUR_ADDR]] |
| 235 |
// LLVM: br label %[[LOOP_COND]] |
| 236 |
// LLVM: [[LOOP_END]]: |
| 237 |
// LLVM: ret void |
| 238 |
// LLVM: } |
| 239 |
// |
| 240 |
// LLVM: define internal void @__cxx_global_var_init.5() { |
| 241 |
// LLVM: call void @__cxa_atexit(ptr @__cxx_global_array_dtor, ptr @arrDtor, ptr @__dso_handle) |
| 242 |
|
| 243 |
// Note: OGCG defines these functions in reverse order of CIR->LLVM. |
| 244 |
// Note also: OGCG doesn't pass the address of the array to the destructor function. |
| 245 |
// Instead, it uses the global directly in the helper function. |
| 246 |
|
| 247 |
// OGCG: define internal void @__cxx_global_var_init.5() {{.*}} section ".text.startup" { |
| 248 |
// OGCG: call i32 @__cxa_atexit(ptr @__cxx_global_array_dtor, ptr null, ptr @__dso_handle) |
| 249 |
|
| 250 |
// OGCG: define internal void @__cxx_global_array_dtor(ptr noundef %[[ARG:.*]]) {{.*}} section ".text.startup" { |
| 251 |
// OGCG: entry: |
| 252 |
// OGCG: %[[UNUSED_ADDR:.*]] = alloca ptr |
| 253 |
// OGCG: store ptr %[[ARG]], ptr %[[UNUSED_ADDR]] |
| 254 |
// OGCG: br label %[[LOOP_BODY:.*]] |
| 255 |
// OGCG: [[LOOP_BODY]]: |
| 256 |
// OGCG: %[[PREV:.*]] = phi ptr [ getelementptr inbounds (%struct.ArrayDtor, ptr @arrDtor, i64 16), %entry ], [ %[[CUR:.*]], %[[LOOP_BODY]] ] |
| 257 |
// OGCG: %[[CUR]] = getelementptr inbounds %struct.ArrayDtor, ptr %[[PREV]], i64 -1 |
| 258 |
// OGCG: call void @_ZN9ArrayDtorD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %[[CUR]]) |
| 259 |
// OGCG: %[[DONE:.*]] = icmp eq ptr %[[CUR]], @arrDtor |
| 260 |
// OGCG: br i1 %[[DONE]], label %[[LOOP_END:.*]], label %[[LOOP_BODY]] |
| 261 |
// OGCG: [[LOOP_END]]: |
| 262 |
// OGCG: ret void |
| 263 |
// OGCG: } |
| 264 |
|
| 265 |
// Common init function for all globals with default priority |
| 266 |
|
| 267 |
// CIR: cir.func private @_GLOBAL__sub_I_[[FILENAME:.*]]() { |
| 268 |
// CIR: cir.call @__cxx_global_var_init() : () -> () |
| 269 |
// CIR: cir.call @__cxx_global_var_init.1() : () -> () |
| 270 |
// CIR: cir.call @__cxx_global_var_init.2() : () -> () |
| 271 |
// CIR: cir.call @__cxx_global_var_init.3() : () -> () |
| 272 |
// CIR: cir.call @__cxx_global_var_init.4() : () -> () |
| 273 |
// CIR: cir.call @__cxx_global_var_init.5() : () -> () |
| 274 |
|
| 275 |
// LLVM: define void @_GLOBAL__sub_I_[[FILENAME]]() |
| 276 |
// LLVM: call void @__cxx_global_var_init() |
| 277 |
// LLVM: call void @__cxx_global_var_init.1() |
| 278 |
// LLVM: call void @__cxx_global_var_init.2() |
| 279 |
// LLVM: call void @__cxx_global_var_init.3() |
| 280 |
// LLVM: call void @__cxx_global_var_init.4() |
| 281 |
// LLVM: call void @__cxx_global_var_init.5() |
| 282 |
|
| 283 |
// OGCG: define internal void @_GLOBAL__sub_I_[[FILENAME]]() {{.*}} section ".text.startup" { |
| 284 |
// OGCG: call void @__cxx_global_var_init() |
| 285 |
// OGCG: call void @__cxx_global_var_init.1() |
| 286 |
// OGCG: call void @__cxx_global_var_init.2() |
| 287 |
// OGCG: call void @__cxx_global_var_init.3() |
| 288 |
// OGCG: call void @__cxx_global_var_init.4() |
| 289 |
// OGCG: call void @__cxx_global_var_init.5() |