| 1 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 |
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR |
| 3 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll |
| 4 |
// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM |
| 5 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll |
| 6 |
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG |
| 7 |
|
| 8 |
void test() { |
| 9 |
int i = 1; |
| 10 |
long l = 2l; |
| 11 |
float f = 3.0f; |
| 12 |
double d = 4.0; |
| 13 |
bool b1 = true; |
| 14 |
bool b2 = false; |
| 15 |
const int ci = 1; |
| 16 |
const long cl = 2l; |
| 17 |
const float cf = 3.0f; |
| 18 |
const double cd = 4.0; |
| 19 |
const bool cb1 = true; |
| 20 |
const bool cb2 = false; |
| 21 |
int uii; |
| 22 |
long uil; |
| 23 |
float uif; |
| 24 |
double uid; |
| 25 |
bool uib; |
| 26 |
} |
| 27 |
|
| 28 |
// CIR: module |
| 29 |
// CIR: cir.func{{.*}} @_Z4testv() |
| 30 |
// CIR: %[[I_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64} |
| 31 |
// CIR: %[[L_PTR:.*]] = cir.alloca !s64i, !cir.ptr<!s64i>, ["l", init] {alignment = 8 : i64} |
| 32 |
// CIR: %[[F_PTR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["f", init] {alignment = 4 : i64} |
| 33 |
// CIR: %[[D_PTR:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["d", init] {alignment = 8 : i64} |
| 34 |
// CIR: %[[B1_PTR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b1", init] {alignment = 1 : i64} |
| 35 |
// CIR: %[[B2_PTR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b2", init] {alignment = 1 : i64} |
| 36 |
// CIR: %[[CI_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["ci", init, const] {alignment = 4 : i64} |
| 37 |
// CIR: %[[CL_PTR:.*]] = cir.alloca !s64i, !cir.ptr<!s64i>, ["cl", init, const] {alignment = 8 : i64} |
| 38 |
// CIR: %[[CF_PTR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["cf", init, const] {alignment = 4 : i64} |
| 39 |
// CIR: %[[CD_PTR:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["cd", init, const] {alignment = 8 : i64} |
| 40 |
// CIR: %[[CB1_PTR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["cb1", init, const] {alignment = 1 : i64} |
| 41 |
// CIR: %[[CB2_PTR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["cb2", init, const] {alignment = 1 : i64} |
| 42 |
// CIR: %[[UII_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["uii"] {alignment = 4 : i64} |
| 43 |
// CIR: %[[UIL_PTR:.*]] = cir.alloca !s64i, !cir.ptr<!s64i>, ["uil"] {alignment = 8 : i64} |
| 44 |
// CIR: %[[UIF_PTR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["uif"] {alignment = 4 : i64} |
| 45 |
// CIR: %[[UID_PTR:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["uid"] {alignment = 8 : i64} |
| 46 |
// CIR: %[[UIB_PTR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["uib"] {alignment = 1 : i64} |
| 47 |
// CIR: %[[ONE:.*]] = cir.const #cir.int<1> : !s32i |
| 48 |
// CIR: cir.store align(4) %[[ONE]], %[[I_PTR]] : !s32i, !cir.ptr<!s32i> |
| 49 |
// CIR: %[[TWO:.*]] = cir.const #cir.int<2> : !s64i |
| 50 |
// CIR: cir.store align(8) %[[TWO]], %[[L_PTR]] : !s64i, !cir.ptr<!s64i> |
| 51 |
// CIR: %[[THREE:.*]] = cir.const #cir.fp<3.0{{.*}}> : !cir.float |
| 52 |
// CIR: cir.store align(4) %[[THREE]], %[[F_PTR]] : !cir.float, !cir.ptr<!cir.float> |
| 53 |
// CIR: %[[FOUR:.*]] = cir.const #cir.fp<4.0{{.*}}> : !cir.double |
| 54 |
// CIR: cir.store align(8) %[[FOUR]], %[[D_PTR]] : !cir.double, !cir.ptr<!cir.double> |
| 55 |
// CIR: %[[TRUE:.*]] = cir.const #true |
| 56 |
// CIR: cir.store align(1) %[[TRUE]], %[[B1_PTR]] : !cir.bool, !cir.ptr<!cir.bool> |
| 57 |
// CIR: %[[FALSE:.*]] = cir.const #false |
| 58 |
// CIR: cir.store align(1) %[[FALSE]], %[[B2_PTR]] : !cir.bool, !cir.ptr<!cir.bool> |
| 59 |
// CIR: %[[ONEC:.*]] = cir.const #cir.int<1> : !s32i |
| 60 |
// CIR: cir.store align(4) %[[ONEC]], %[[CI_PTR]] : !s32i, !cir.ptr<!s32i> |
| 61 |
// CIR: %[[TWOC:.*]] = cir.const #cir.int<2> : !s64i |
| 62 |
// CIR: cir.store align(8) %[[TWOC]], %[[CL_PTR]] : !s64i, !cir.ptr<!s64i> |
| 63 |
// CIR: %[[THREEC:.*]] = cir.const #cir.fp<3.0{{.*}}> : !cir.float |
| 64 |
// CIR: cir.store align(4) %[[THREEC]], %[[CF_PTR]] : !cir.float, !cir.ptr<!cir.float> |
| 65 |
// CIR: %[[FOURC:.*]] = cir.const #cir.fp<4.0{{.*}}> : !cir.double |
| 66 |
// CIR: cir.store align(8) %[[FOURC]], %[[CD_PTR]] : !cir.double, !cir.ptr<!cir.double> |
| 67 |
// CIR: %[[TRUEC:.*]] = cir.const #true |
| 68 |
// CIR: cir.store align(1) %[[TRUEC]], %[[CB1_PTR]] : !cir.bool, !cir.ptr<!cir.bool> |
| 69 |
// CIR: %[[FALSEC:.*]] = cir.const #false |
| 70 |
// CIR: cir.store align(1) %[[FALSEC]], %[[CB2_PTR]] : !cir.bool, !cir.ptr<!cir.bool> |
| 71 |
|
| 72 |
// LLVM: define dso_local void @_Z4testv() |
| 73 |
// LLVM: %[[I_PTR:.+]] = alloca i32 |
| 74 |
// LLVM: %[[L_PTR:.+]] = alloca i64 |
| 75 |
// LLVM: %[[F_PTR:.+]] = alloca float |
| 76 |
// LLVM: %[[D_PTR:.+]] = alloca double |
| 77 |
// LLVM: %[[B1_PTR:.+]] = alloca i8 |
| 78 |
// LLVM: %[[B2_PTR:.+]] = alloca i8 |
| 79 |
// LLVM: %[[CI_PTR:.+]] = alloca i32 |
| 80 |
// LLVM: %[[CL_PTR:.+]] = alloca i64 |
| 81 |
// LLVM: %[[CF_PTR:.+]] = alloca float |
| 82 |
// LLVM: %[[CD_PTR:.+]] = alloca double |
| 83 |
// LLVM: %[[CB1_PTR:.+]] = alloca i8 |
| 84 |
// LLVM: %[[CB2_PTR:.+]] = alloca i8 |
| 85 |
// LLVM: %[[UII_PTR:.+]] = alloca i32 |
| 86 |
// LLVM: %[[UIL_PTR:.+]] = alloca i64 |
| 87 |
// LLVM: %[[UIF_PTR:.+]] = alloca float |
| 88 |
// LLVM: %[[UID_PTR:.+]] = alloca double |
| 89 |
// LLVM: %[[UIB_PTR:.+]] = alloca i8 |
| 90 |
// LLVM: store i32 1, ptr %[[I_PTR]] |
| 91 |
// LLVM: store i64 2, ptr %[[L_PTR]] |
| 92 |
// LLVM: store float 3.000000e+00, ptr %[[F_PTR]] |
| 93 |
// LLVM: store double 4.000000e+00, ptr %[[D_PTR]] |
| 94 |
// LLVM: store i8 1, ptr %[[B1_PTR]] |
| 95 |
// LLVM: store i8 0, ptr %[[B2_PTR]] |
| 96 |
// LLVM: store i32 1, ptr %[[CI_PTR]] |
| 97 |
// LLVM: store i64 2, ptr %[[CL_PTR]] |
| 98 |
// LLVM: store float 3.000000e+00, ptr %[[CF_PTR]] |
| 99 |
// LLVM: store double 4.000000e+00, ptr %[[CD_PTR]] |
| 100 |
// LLVM: store i8 1, ptr %[[CB1_PTR]] |
| 101 |
// LLVM: store i8 0, ptr %[[CB2_PTR]] |
| 102 |
// LLVM: ret void |
| 103 |
|
| 104 |
// OGCG: define dso_local void @_Z4testv() |
| 105 |
// OGCG: %[[I_PTR:.+]] = alloca i32 |
| 106 |
// OGCG: %[[L_PTR:.+]] = alloca i64 |
| 107 |
// OGCG: %[[F_PTR:.+]] = alloca float |
| 108 |
// OGCG: %[[D_PTR:.+]] = alloca double |
| 109 |
// OGCG: %[[B1_PTR:.+]] = alloca i8 |
| 110 |
// OGCG: %[[B2_PTR:.+]] = alloca i8 |
| 111 |
// OGCG: %[[CI_PTR:.+]] = alloca i32 |
| 112 |
// OGCG: %[[CL_PTR:.+]] = alloca i64 |
| 113 |
// OGCG: %[[CF_PTR:.+]] = alloca float |
| 114 |
// OGCG: %[[CD_PTR:.+]] = alloca double |
| 115 |
// OGCG: %[[CB1_PTR:.+]] = alloca i8 |
| 116 |
// OGCG: %[[CB2_PTR:.+]] = alloca i8 |
| 117 |
// OGCG: %[[UII_PTR:.+]] = alloca i32 |
| 118 |
// OGCG: %[[UIL_PTR:.+]] = alloca i64 |
| 119 |
// OGCG: %[[UIF_PTR:.+]] = alloca float |
| 120 |
// OGCG: %[[UID_PTR:.+]] = alloca double |
| 121 |
// OGCG: %[[UIB_PTR:.+]] = alloca i8 |
| 122 |
// OGCG: store i32 1, ptr %[[I_PTR]] |
| 123 |
// OGCG: store i64 2, ptr %[[L_PTR]] |
| 124 |
// OGCG: store float 3.000000e+00, ptr %[[F_PTR]] |
| 125 |
// OGCG: store double 4.000000e+00, ptr %[[D_PTR]] |
| 126 |
// OGCG: store i8 1, ptr %[[B1_PTR]] |
| 127 |
// OGCG: store i8 0, ptr %[[B2_PTR]] |
| 128 |
// OGCG: store i32 1, ptr %[[CI_PTR]] |
| 129 |
// OGCG: store i64 2, ptr %[[CL_PTR]] |
| 130 |
// OGCG: store float 3.000000e+00, ptr %[[CF_PTR]] |
| 131 |
// OGCG: store double 4.000000e+00, ptr %[[CD_PTR]] |
| 132 |
// OGCG: store i8 1, ptr %[[CB1_PTR]] |
| 133 |
// OGCG: store i8 0, ptr %[[CB2_PTR]] |
| 134 |
// OGCG: ret void |
| 135 |
|
| 136 |
void value_init() { |
| 137 |
float f{}; |
| 138 |
bool b{}; |
| 139 |
int i{}; |
| 140 |
|
| 141 |
float f2 = {}; |
| 142 |
bool b2 = {}; |
| 143 |
int i2 = {}; |
| 144 |
|
| 145 |
bool scalar_value_init_expr = int() == 0; |
| 146 |
} |
| 147 |
|
| 148 |
// CIR: cir.func{{.*}} @_Z10value_initv() |
| 149 |
// CIR: %[[F_PTR:.+]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["f", init] |
| 150 |
// CIR: %[[B_PTR:.+]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b", init] |
| 151 |
// CIR: %[[I_PTR:.+]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] |
| 152 |
// CIR: %[[F2_PTR:.+]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["f2", init] |
| 153 |
// CIR: %[[B2_PTR:.+]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b2", init] |
| 154 |
// CIR: %[[I2_PTR:.+]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i2", init] |
| 155 |
// CIR: %[[S_PTR:.+]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["scalar_value_init_expr", init] |
| 156 |
// CIR: %[[ZEROF1:.+]] = cir.const #cir.fp<0.000000e+00> : !cir.float |
| 157 |
// CIR: cir.store{{.*}} %[[ZEROF1]], %[[F_PTR]] : !cir.float, !cir.ptr<!cir.float> |
| 158 |
// CIR: %[[FALSE1:.+]] = cir.const #false |
| 159 |
// CIR: cir.store{{.*}} %[[FALSE1]], %[[B_PTR]] : !cir.bool, !cir.ptr<!cir.bool> |
| 160 |
// CIR: %[[ZEROI1:.+]] = cir.const #cir.int<0> : !s32i |
| 161 |
// CIR: cir.store{{.*}} %[[ZEROI1]], %[[I_PTR]] : !s32i, !cir.ptr<!s32i> |
| 162 |
// CIR: %[[ZEROF2:.+]] = cir.const #cir.fp<0.000000e+00> : !cir.float |
| 163 |
// CIR: cir.store{{.*}} %[[ZEROF2]], %[[F2_PTR]] : !cir.float, !cir.ptr<!cir.float> |
| 164 |
// CIR: %[[FALSE2:.+]] = cir.const #false |
| 165 |
// CIR: cir.store{{.*}} %[[FALSE2]], %[[B2_PTR]] : !cir.bool, !cir.ptr<!cir.bool> |
| 166 |
// CIR: %[[ZEROI2:.+]] = cir.const #cir.int<0> : !s32i |
| 167 |
// CIR: cir.store{{.*}} %[[ZEROI2]], %[[I2_PTR]] : !s32i, !cir.ptr<!s32i> |
| 168 |
// CIR: %[[ZEROI_LHS:.+]] = cir.const #cir.int<0> : !s32i |
| 169 |
// CIR: %[[ZEROI_RHS:.+]] = cir.const #cir.int<0> : !s32i |
| 170 |
// CIR: %[[CMP:.+]] = cir.cmp(eq, %[[ZEROI_LHS]], %[[ZEROI_RHS]]) : !s32i, !cir.bool |
| 171 |
// CIR: cir.store{{.*}} %[[CMP]], %[[S_PTR]] : !cir.bool, !cir.ptr<!cir.bool> |
| 172 |
// CIR: cir.return |
| 173 |
|
| 174 |
// LLVM: define{{.*}} void @_Z10value_initv() |
| 175 |
// LLVM: %[[F_PTR:.+]] = alloca float |
| 176 |
// LLVM: %[[B_PTR:.+]] = alloca i8 |
| 177 |
// LLVM: %[[I_PTR:.+]] = alloca i32 |
| 178 |
// LLVM: %[[F2_PTR:.+]] = alloca float |
| 179 |
// LLVM: %[[B2_PTR:.+]] = alloca i8 |
| 180 |
// LLVM: %[[I2_PTR:.+]] = alloca i32 |
| 181 |
// LLVM: %[[S_PTR:.+]] = alloca i8 |
| 182 |
// LLVM: store float 0.000000e+00, ptr %[[F_PTR]] |
| 183 |
// LLVM: store i8 0, ptr %[[B_PTR]] |
| 184 |
// LLVM: store i32 0, ptr %[[I_PTR]] |
| 185 |
// LLVM: store float 0.000000e+00, ptr %[[F2_PTR]] |
| 186 |
// LLVM: store i8 0, ptr %[[B2_PTR]] |
| 187 |
// LLVM: store i32 0, ptr %[[I2_PTR]] |
| 188 |
// LLVM: store i8 1, ptr %[[S_PTR]] |
| 189 |
// LLVM: ret void |
| 190 |
|
| 191 |
// OGCG: define{{.*}} void @_Z10value_initv() |
| 192 |
// OGCG: %[[F_PTR:.+]] = alloca float |
| 193 |
// OGCG: %[[B_PTR:.+]] = alloca i8 |
| 194 |
// OGCG: %[[I_PTR:.+]] = alloca i32 |
| 195 |
// OGCG: %[[F2_PTR:.+]] = alloca float |
| 196 |
// OGCG: %[[B2_PTR:.+]] = alloca i8 |
| 197 |
// OGCG: %[[I2_PTR:.+]] = alloca i32 |
| 198 |
// OGCG: %[[S_PTR:.+]] = alloca i8 |
| 199 |
// OGCG: store float 0.000000e+00, ptr %[[F_PTR]] |
| 200 |
// OGCG: store i8 0, ptr %[[B_PTR]] |
| 201 |
// OGCG: store i32 0, ptr %[[I_PTR]] |
| 202 |
// OGCG: store float 0.000000e+00, ptr %[[F2_PTR]] |
| 203 |
// OGCG: store i8 0, ptr %[[B2_PTR]] |
| 204 |
// OGCG: store i32 0, ptr %[[I2_PTR]] |
| 205 |
// OGCG: store i8 1, ptr %[[S_PTR]] |
| 206 |
// OGCG: ret void |