207 lines · cpp
1// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR3// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM5// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG7 8void 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: module29// 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> : !s32i48// CIR: cir.store align(4) %[[ONE]], %[[I_PTR]] : !s32i, !cir.ptr<!s32i>49// CIR: %[[TWO:.*]] = cir.const #cir.int<2> : !s64i50// CIR: cir.store align(8) %[[TWO]], %[[L_PTR]] : !s64i, !cir.ptr<!s64i>51// CIR: %[[THREE:.*]] = cir.const #cir.fp<3.0{{.*}}> : !cir.float52// CIR: cir.store align(4) %[[THREE]], %[[F_PTR]] : !cir.float, !cir.ptr<!cir.float>53// CIR: %[[FOUR:.*]] = cir.const #cir.fp<4.0{{.*}}> : !cir.double54// CIR: cir.store align(8) %[[FOUR]], %[[D_PTR]] : !cir.double, !cir.ptr<!cir.double>55// CIR: %[[TRUE:.*]] = cir.const #true56// CIR: cir.store align(1) %[[TRUE]], %[[B1_PTR]] : !cir.bool, !cir.ptr<!cir.bool>57// CIR: %[[FALSE:.*]] = cir.const #false58// CIR: cir.store align(1) %[[FALSE]], %[[B2_PTR]] : !cir.bool, !cir.ptr<!cir.bool>59// CIR: %[[ONEC:.*]] = cir.const #cir.int<1> : !s32i60// CIR: cir.store align(4) %[[ONEC]], %[[CI_PTR]] : !s32i, !cir.ptr<!s32i>61// CIR: %[[TWOC:.*]] = cir.const #cir.int<2> : !s64i62// CIR: cir.store align(8) %[[TWOC]], %[[CL_PTR]] : !s64i, !cir.ptr<!s64i>63// CIR: %[[THREEC:.*]] = cir.const #cir.fp<3.0{{.*}}> : !cir.float64// CIR: cir.store align(4) %[[THREEC]], %[[CF_PTR]] : !cir.float, !cir.ptr<!cir.float>65// CIR: %[[FOURC:.*]] = cir.const #cir.fp<4.0{{.*}}> : !cir.double66// CIR: cir.store align(8) %[[FOURC]], %[[CD_PTR]] : !cir.double, !cir.ptr<!cir.double>67// CIR: %[[TRUEC:.*]] = cir.const #true68// CIR: cir.store align(1) %[[TRUEC]], %[[CB1_PTR]] : !cir.bool, !cir.ptr<!cir.bool>69// CIR: %[[FALSEC:.*]] = cir.const #false70// 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 i3274// LLVM: %[[L_PTR:.+]] = alloca i6475// LLVM: %[[F_PTR:.+]] = alloca float76// LLVM: %[[D_PTR:.+]] = alloca double77// LLVM: %[[B1_PTR:.+]] = alloca i878// LLVM: %[[B2_PTR:.+]] = alloca i879// LLVM: %[[CI_PTR:.+]] = alloca i3280// LLVM: %[[CL_PTR:.+]] = alloca i6481// LLVM: %[[CF_PTR:.+]] = alloca float82// LLVM: %[[CD_PTR:.+]] = alloca double83// LLVM: %[[CB1_PTR:.+]] = alloca i884// LLVM: %[[CB2_PTR:.+]] = alloca i885// LLVM: %[[UII_PTR:.+]] = alloca i3286// LLVM: %[[UIL_PTR:.+]] = alloca i6487// LLVM: %[[UIF_PTR:.+]] = alloca float88// LLVM: %[[UID_PTR:.+]] = alloca double89// LLVM: %[[UIB_PTR:.+]] = alloca i890// 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 void103 104// OGCG: define dso_local void @_Z4testv()105// OGCG: %[[I_PTR:.+]] = alloca i32106// OGCG: %[[L_PTR:.+]] = alloca i64107// OGCG: %[[F_PTR:.+]] = alloca float108// OGCG: %[[D_PTR:.+]] = alloca double109// OGCG: %[[B1_PTR:.+]] = alloca i8110// OGCG: %[[B2_PTR:.+]] = alloca i8111// OGCG: %[[CI_PTR:.+]] = alloca i32112// OGCG: %[[CL_PTR:.+]] = alloca i64113// OGCG: %[[CF_PTR:.+]] = alloca float114// OGCG: %[[CD_PTR:.+]] = alloca double115// OGCG: %[[CB1_PTR:.+]] = alloca i8116// OGCG: %[[CB2_PTR:.+]] = alloca i8117// OGCG: %[[UII_PTR:.+]] = alloca i32118// OGCG: %[[UIL_PTR:.+]] = alloca i64119// OGCG: %[[UIF_PTR:.+]] = alloca float120// OGCG: %[[UID_PTR:.+]] = alloca double121// OGCG: %[[UIB_PTR:.+]] = alloca i8122// 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 void135 136void 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.float157// CIR: cir.store{{.*}} %[[ZEROF1]], %[[F_PTR]] : !cir.float, !cir.ptr<!cir.float>158// CIR: %[[FALSE1:.+]] = cir.const #false159// CIR: cir.store{{.*}} %[[FALSE1]], %[[B_PTR]] : !cir.bool, !cir.ptr<!cir.bool>160// CIR: %[[ZEROI1:.+]] = cir.const #cir.int<0> : !s32i161// CIR: cir.store{{.*}} %[[ZEROI1]], %[[I_PTR]] : !s32i, !cir.ptr<!s32i>162// CIR: %[[ZEROF2:.+]] = cir.const #cir.fp<0.000000e+00> : !cir.float163// CIR: cir.store{{.*}} %[[ZEROF2]], %[[F2_PTR]] : !cir.float, !cir.ptr<!cir.float>164// CIR: %[[FALSE2:.+]] = cir.const #false165// CIR: cir.store{{.*}} %[[FALSE2]], %[[B2_PTR]] : !cir.bool, !cir.ptr<!cir.bool>166// CIR: %[[ZEROI2:.+]] = cir.const #cir.int<0> : !s32i167// CIR: cir.store{{.*}} %[[ZEROI2]], %[[I2_PTR]] : !s32i, !cir.ptr<!s32i>168// CIR: %[[ZEROI_LHS:.+]] = cir.const #cir.int<0> : !s32i169// CIR: %[[ZEROI_RHS:.+]] = cir.const #cir.int<0> : !s32i170// CIR: %[[CMP:.+]] = cir.cmp(eq, %[[ZEROI_LHS]], %[[ZEROI_RHS]]) : !s32i, !cir.bool171// CIR: cir.store{{.*}} %[[CMP]], %[[S_PTR]] : !cir.bool, !cir.ptr<!cir.bool>172// CIR: cir.return173 174// LLVM: define{{.*}} void @_Z10value_initv()175// LLVM: %[[F_PTR:.+]] = alloca float176// LLVM: %[[B_PTR:.+]] = alloca i8177// LLVM: %[[I_PTR:.+]] = alloca i32178// LLVM: %[[F2_PTR:.+]] = alloca float179// LLVM: %[[B2_PTR:.+]] = alloca i8180// LLVM: %[[I2_PTR:.+]] = alloca i32181// LLVM: %[[S_PTR:.+]] = alloca i8182// 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 void190 191// OGCG: define{{.*}} void @_Z10value_initv()192// OGCG: %[[F_PTR:.+]] = alloca float193// OGCG: %[[B_PTR:.+]] = alloca i8194// OGCG: %[[I_PTR:.+]] = alloca i32195// OGCG: %[[F2_PTR:.+]] = alloca float196// OGCG: %[[B2_PTR:.+]] = alloca i8197// OGCG: %[[I2_PTR:.+]] = alloca i32198// OGCG: %[[S_PTR:.+]] = alloca i8199// 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 void207