brintos

brintos / llvm-project-archived public Read only

0
0
Text · 12.9 KiB · 3a89c77 Raw
246 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -mconstructor-aliases -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -mconstructor-aliases -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -mconstructor-aliases -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG7 8struct Pair {9  int a;10  int b;11};12 13struct ZeroInit {14  int i{};15  Pair p{};16  int  arr[4]{};17  float _Complex c{};18  unsigned bf : 8 {};19  ZeroInit() = default;20};21 22// CIR: cir.func{{.*}} @_ZN8ZeroInitC2Ev(%[[THIS_ARG:.*]]: !cir.ptr<!rec_ZeroInit> {{.*}})23// CIR:   %[[ITER:.*]] = cir.alloca {{.*}} ["arrayinit.temp"]24// CIR:   %[[THIS:.*]] = cir.load %[[THIS_ALLOCA:.*]]25// CIR:   %[[I:.*]] = cir.get_member %[[THIS]][0] {name = "i"}26// CIR:   %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i27// CIR:   cir.store{{.*}} %[[ZERO]], %[[I]]28// CIR:   %[[P:.*]] = cir.get_member %[[THIS]][1] {name = "p"}29// CIR:   %[[P_A:.*]] = cir.get_member %[[P]][0] {name = "a"}30// CIR:   %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i31// CIR:   cir.store{{.*}} %[[ZERO]], %[[P_A]]32// CIR:   %[[P_B:.*]] = cir.get_member %[[P]][1] {name = "b"}33// CIR:   %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i34// CIR:   cir.store{{.*}} %[[ZERO]], %[[P_B]]35// CIR:   %[[ARR:.*]] = cir.get_member %[[THIS]][2] {name = "arr"}36// CIR:   %[[ARR_BEGIN:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!s32i x 4>> -> !cir.ptr<!s32i>37// CIR:   cir.store{{.*}} %[[ARR_BEGIN]], %[[ITER]]38// CIR:   %[[FOUR:.*]] = cir.const #cir.int<4> : !s64i39// CIR:   %[[END:.*]] = cir.ptr_stride %[[ARR_BEGIN]], %[[FOUR]] : (!cir.ptr<!s32i>, !s64i)40// CIR:   cir.do {41// CIR:     %[[CUR:.*]] = cir.load{{.*}} %[[ITER]]42// CIR:     %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i43// CIR:     cir.store{{.*}} %[[ZERO]], %[[CUR]]44// CIR:     %[[ONE:.*]] = cir.const #cir.int<1> : !s64i45// CIR:     %[[NEXT:.*]] = cir.ptr_stride %[[CUR]], %[[ONE]] : (!cir.ptr<!s32i>, !s64i)46// CIR:     cir.store{{.*}} %[[NEXT]], %[[ITER]]47// CIR:     cir.yield48// CIR:   } while {49// CIR:     %[[CUR:.*]] = cir.load{{.*}} %[[ITER]]50// CIR:     %[[CMP:.*]] = cir.cmp(ne, %[[CUR]], %[[END]])51// CIR:     cir.condition(%[[CMP]])52// CIR:   }53// CIR:   %[[C:.*]] = cir.get_member %[[THIS]][3] {name = "c"}54// CIR:   %[[ZERO:.*]] = cir.const #cir.zero : !cir.complex<!cir.float>55// CIR:   cir.store{{.*}} %[[ZERO]], %[[C]]56// CIR:   %[[BF:.*]] = cir.get_member %[[THIS]][4] {name = "bf"}57// CIR:   %[[ZERO:.*]] = cir.const #cir.int<0> : !u32i58// CIR:   %[[BF_VAL:.*]] = cir.set_bitfield{{.*}} (#bfi_bf, %[[BF]] : !cir.ptr<!u8i>, %[[ZERO]] : !u32i)59 60// LLVM: define{{.*}} void @_ZN8ZeroInitC2Ev(ptr %[[THIS_ARG:.*]])61// LLVM:   %[[THIS_ALLOCA:.*]] = alloca ptr62// LLVM:   %[[ITER:.*]] = alloca ptr63// LLVM:   %[[THIS:.*]] = load ptr, ptr %[[THIS_ALLOCA]]64// LLVM:   %[[I:.*]] = getelementptr %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 065// LLVM:   store i32 0, ptr %[[I]]66// LLVM:   %[[P:.*]] = getelementptr %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 167// LLVM:   %[[P_A:.*]] = getelementptr %struct.Pair, ptr %[[P]], i32 0, i32 068// LLVM:   store i32 0, ptr %[[P_A]]69// LLVM:   %[[P_B:.*]] = getelementptr %struct.Pair, ptr %[[P]], i32 0, i32 170// LLVM:   store i32 0, ptr %[[P_B]]71// LLVM:   %[[ARR:.*]] = getelementptr %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 272// LLVM:   %[[ARR_BEGIN:.*]] = getelementptr i32, ptr %[[ARR]], i32 073// LLVM:   store ptr %[[ARR_BEGIN]], ptr %[[ITER]]74// LLVM:   %[[ARR_END:.*]] = getelementptr i32, ptr %[[ARR_BEGIN]], i64 475// LLVM:   br label %[[LOOP_BODY:.*]]76// LLVM: [[LOOP_COND:.*]]:77// LLVM:   %[[CUR:.*]] = load ptr, ptr %[[ITER]]78// LLVM:   %[[CMP:.*]] = icmp ne ptr %[[CUR]], %[[ARR_END]]79// LLVM:   br i1 %[[CMP]], label %[[LOOP_BODY]], label %[[LOOP_END:.*]]80// LLVM: [[LOOP_BODY]]:81// LLVM:   %[[CUR:.*]] = load ptr, ptr %[[ITER]]82// LLVM:   store i32 0, ptr %[[CUR]]83// LLVM:   %[[NEXT:.*]] = getelementptr i32, ptr %[[CUR]], i64 184// LLVM:   store ptr %[[NEXT]], ptr %[[ITER]]85// LLVM:   br label %[[LOOP_COND]]86// LLVM: [[LOOP_END]]:87// LLVM:   %[[C:.*]] = getelementptr %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 388// LLVM:   store { float, float } zeroinitializer, ptr %[[C]]89// LLVM:   %[[BF:.*]] = getelementptr %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 490// LLVM:   store i8 0, ptr %[[BF]]91 92// OGCG: define{{.*}} void @_ZN8ZeroInitC2Ev(ptr {{.*}} %[[THIS_ARG:.*]])93// OGCG:   %[[THIS:.*]] = load ptr, ptr %[[THIS_ALLOCA:.*]]94// OGCG:   %[[I:.*]] = getelementptr inbounds nuw %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 095// OGCG:   store i32 0, ptr %[[I]]96// OGCG:   %[[P:.*]] = getelementptr inbounds nuw %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 197// OGCG:   %[[P_A:.*]] = getelementptr inbounds nuw %struct.Pair, ptr %[[P]], i32 0, i32 098// OGCG:   store i32 0, ptr %[[P_A]]99// OGCG:   %[[P_B:.*]] = getelementptr inbounds nuw %struct.Pair, ptr %[[P]], i32 0, i32 1100// OGCG:   store i32 0, ptr %[[P_B]]101// OGCG:   %[[ARR:.*]] = getelementptr inbounds nuw %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 2102// OGCG:   %[[ARR_END:.*]] = getelementptr inbounds i32, ptr %[[ARR]], i64 4103// OGCG:   br label %[[LOOP_BODY:.*]]104// OGCG: [[LOOP_BODY]]:105// OGCG:   %[[CUR:.*]] = phi ptr [ %[[ARR]], %entry ], [ %[[NEXT:.*]], %[[LOOP_BODY]] ]106// OGCG:   store i32 0, ptr %[[CUR]]107// OGCG:   %[[NEXT]] = getelementptr inbounds i32, ptr %[[CUR]], i64 1108// OGCG:   %[[CMP:.*]] = icmp eq ptr %[[NEXT]], %[[ARR_END]]109// OGCG:   br i1 %[[CMP]], label %[[LOOP_END:.*]], label %[[LOOP_BODY]]110// OGCG: [[LOOP_END]]:111// OGCG:   %[[C:.*]] = getelementptr inbounds nuw %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 3112// OGCG:   %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C]], i32 0, i32 0113// OGCG:   %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C]], i32 0, i32 1114// OGCG:   store float 0.000000e+00, ptr %[[C_REAL_PTR]]115// OGCG:   store float 0.000000e+00, ptr %[[C_IMAG_PTR]]116// OGCG:   %[[BF:.*]] = getelementptr inbounds nuw %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 4117// OGCG:   store i8 0, ptr %[[BF]]118 119struct ValueInit {120  int i{1};121  Pair p{2, 3};122  int  arr[4]{4, 5};123  float _Complex c{6.0f, 7.0f};124  unsigned bf : 8 {0xFF};125  ValueInit() = default;126};127 128// CIR: cir.func{{.*}} @_ZN9ValueInitC2Ev(%[[THIS_ARG:.*]]: !cir.ptr<!rec_ValueInit> {{.*}})129// CIR:   %[[ITER:.*]] = cir.alloca {{.*}} ["arrayinit.temp"]130// CIR:   %[[THIS:.*]] = cir.load %[[THIS_ALLOCA:.*]]131// CIR:   %[[I:.*]] = cir.get_member %[[THIS]][0] {name = "i"}132// CIR:   %[[ONE:.*]] = cir.const #cir.int<1> : !s32i133// CIR:   cir.store{{.*}} %[[ONE]], %[[I]]134// CIR:   %[[P:.*]] = cir.get_member %[[THIS]][1] {name = "p"}135// CIR:   %[[P_A:.*]] = cir.get_member %[[P]][0] {name = "a"}136// CIR:   %[[TWO:.*]] = cir.const #cir.int<2> : !s32i137// CIR:   cir.store{{.*}} %[[TWO]], %[[P_A]]138// CIR:   %[[P_B:.*]] = cir.get_member %[[P]][1] {name = "b"}139// CIR:   %[[THREE:.*]] = cir.const #cir.int<3> : !s32i140// CIR:   cir.store{{.*}} %[[THREE]], %[[P_B]]141// CIR:   %[[ARR:.*]] = cir.get_member %[[THIS]][2] {name = "arr"}142// CIR:   %[[ARR_BEGIN:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!s32i x 4>> -> !cir.ptr<!s32i>143// CIR:   %[[FOUR:.*]] = cir.const #cir.int<4> : !s32i144// CIR:   cir.store{{.*}} %[[FOUR]], %[[ARR_BEGIN]]145// CIR:   %[[ONE:.*]] = cir.const #cir.int<1> : !s64i146// CIR:   %[[SECOND:.*]] = cir.ptr_stride %[[ARR_BEGIN]], %[[ONE]] : (!cir.ptr<!s32i>, !s64i)147// CIR:   %[[FIVE:.*]] = cir.const #cir.int<5> : !s32i148// CIR:   cir.store{{.*}} %[[FIVE]], %[[SECOND]]149// CIR:   %[[ONE:.*]] = cir.const #cir.int<1> : !s64i150// CIR:   %[[NEXT:.*]] = cir.ptr_stride %[[SECOND]], %[[ONE]] : (!cir.ptr<!s32i>, !s64i)151// CIR:   cir.store{{.*}} %[[NEXT]], %[[ITER]]152// CIR:   %[[FOUR:.*]] = cir.const #cir.int<4> : !s64i153// CIR:   %[[END:.*]] = cir.ptr_stride %[[ARR_BEGIN]], %[[FOUR]] : (!cir.ptr<!s32i>, !s64i)154// CIR:   cir.do {155// CIR:     %[[CUR:.*]] = cir.load{{.*}} %[[ITER]]156// CIR:     %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i157// CIR:     cir.store{{.*}} %[[ZERO]], %[[CUR]]158// CIR:     %[[ONE:.*]] = cir.const #cir.int<1> : !s64i159// CIR:     %[[NEXT:.*]] = cir.ptr_stride %[[CUR]], %[[ONE]] : (!cir.ptr<!s32i>, !s64i)160// CIR:     cir.store{{.*}} %[[NEXT]], %[[ITER]]161// CIR:     cir.yield162// CIR:   } while {163// CIR:     %[[CUR:.*]] = cir.load{{.*}} %[[ITER]]164// CIR:     %[[CMP:.*]] = cir.cmp(ne, %[[CUR]], %[[END]])165// CIR:     cir.condition(%[[CMP]])166// CIR:   }167// CIR:   %[[C:.*]] = cir.get_member %[[THIS]][3] {name = "c"}168// CIR:   %[[FOUR_FIVEI:.*]] = cir.const #cir.const_complex<#cir.fp<6.000000e+00> : !cir.float, #cir.fp<7.000000e+00>169// CIR:   cir.store{{.*}} %[[FOUR_FIVEI]], %[[C]]170// CIR:   %[[BF:.*]] = cir.get_member %[[THIS]][4] {name = "bf"}171// CIR:   %[[FF:.*]] = cir.const #cir.int<255> : !s32i172// CIR:   %[[FF_CAST:.*]] = cir.cast integral %[[FF]] : !s32i -> !u32i173// CIR:   %[[BF_VAL:.*]] = cir.set_bitfield{{.*}} (#bfi_bf, %[[BF]] : !cir.ptr<!u8i>, %[[FF_CAST]] : !u32i)174 175// LLVM: define{{.*}} void @_ZN9ValueInitC2Ev(ptr %[[THIS_ARG:.*]])176// LLVM:   %[[THIS_ALLOCA:.*]] = alloca ptr177// LLVM:   %[[ITER:.*]] = alloca ptr178// LLVM:   %[[THIS:.*]] = load ptr, ptr %[[THIS_ALLOCA]]179// LLVM:   %[[I:.*]] = getelementptr %struct.ValueInit, ptr %[[THIS]], i32 0, i32 0180// LLVM:   store i32 1, ptr %[[I]]181// LLVM:   %[[P:.*]] = getelementptr %struct.ValueInit, ptr %[[THIS]], i32 0, i32 1182// LLVM:   %[[P_A:.*]] = getelementptr %struct.Pair, ptr %[[P]], i32 0, i32 0183// LLVM:   store i32 2, ptr %[[P_A]]184// LLVM:   %[[P_B:.*]] = getelementptr %struct.Pair, ptr %[[P]], i32 0, i32 1185// LLVM:   store i32 3, ptr %[[P_B]]186// LLVM:   %[[ARR:.*]] = getelementptr %struct.ValueInit, ptr %[[THIS]], i32 0, i32 2187// LLVM:   %[[ARR_BEGIN:.*]] = getelementptr i32, ptr %[[ARR]], i32 0188// LLVM:   store i32 4, ptr %[[ARR_BEGIN]]189// LLVM:   %[[ARR_1:.*]] = getelementptr i32, ptr %[[ARR_BEGIN]], i64 1190// LLVM:   store i32 5, ptr %[[ARR_1]]191// LLVM:   %[[ARR_2:.*]] = getelementptr i32, ptr %[[ARR_1]], i64 1192// LLVM:   store ptr %[[ARR_2]], ptr %[[ITER]]193// LLVM:   %[[ARR_END:.*]] = getelementptr i32, ptr %[[ARR_BEGIN]], i64 4194// LLVM:   br label %[[LOOP_BODY:.*]]195// LLVM: [[LOOP_COND:.*]]:196// LLVM:   %[[CUR:.*]] = load ptr, ptr %[[ITER]]197// LLVM:   %[[CMP:.*]] = icmp ne ptr %[[CUR]], %[[ARR_END]]198// LLVM:   br i1 %[[CMP]], label %[[LOOP_BODY]], label %[[LOOP_END:.*]]199// LLVM: [[LOOP_BODY]]:200// LLVM:   %[[CUR:.*]] = load ptr, ptr %[[ITER]]201// LLVM:   store i32 0, ptr %[[CUR]]202// LLVM:   %[[NEXT:.*]] = getelementptr i32, ptr %[[CUR]], i64 1203// LLVM:   store ptr %[[NEXT]], ptr %[[ITER]]204// LLVM:   br label %[[LOOP_COND]]205// LLVM: [[LOOP_END]]:206// LLVM:   %[[C:.*]] = getelementptr %struct.ValueInit, ptr %[[THIS]], i32 0, i32 3207// LLVM:   store { float, float } { float 6.000000e+00, float 7.000000e+00 }, ptr %[[C]]208// LLVM:   %[[BF:.*]] = getelementptr %struct.ValueInit, ptr %[[THIS]], i32 0, i32 4209// LLVM:   store i8 -1, ptr %[[BF]]210 211// OGCG: define{{.*}} void @_ZN9ValueInitC2Ev(ptr {{.*}} %[[THIS_ARG:.*]])212// OGCG:   %[[THIS:.*]] = load ptr, ptr %[[THIS_ALLOCA:.*]]213// OGCG:   %[[I:.*]] = getelementptr inbounds nuw %struct.ValueInit, ptr %[[THIS]], i32 0, i32 0214// OGCG:   store i32 1, ptr %[[I]]215// OGCG:   %[[P:.*]] = getelementptr inbounds nuw %struct.ValueInit, ptr %[[THIS]], i32 0, i32 1216// OGCG:   %[[P_A:.*]] = getelementptr inbounds nuw %struct.Pair, ptr %[[P]], i32 0, i32 0217// OGCG:   store i32 2, ptr %[[P_A]]218// OGCG:   %[[P_B:.*]] = getelementptr inbounds nuw %struct.Pair, ptr %[[P]], i32 0, i32 1219// OGCG:   store i32 3, ptr %[[P_B]]220// OGCG:   %[[ARR:.*]] = getelementptr inbounds nuw %struct.ValueInit, ptr %[[THIS]], i32 0, i32 2221// OGCG:   store i32 4, ptr %[[ARR]]222// OGCG:   %[[ARR_1:.*]] = getelementptr inbounds i32, ptr %[[ARR]], i64 1223// OGCG:   store i32 5, ptr %[[ARR_1]]224// OGCG:   %[[ARR_BEGIN:.*]] = getelementptr inbounds i32, ptr %[[ARR]], i64 2225// OGCG:   %[[ARR_END:.*]] = getelementptr inbounds i32, ptr %[[ARR]], i64 4226// OGCG:   br label %[[LOOP_BODY:.*]]227// OGCG: [[LOOP_BODY]]:228// OGCG:   %[[CUR:.*]] = phi ptr [ %[[ARR_BEGIN]], %entry ], [ %[[NEXT:.*]], %[[LOOP_BODY]] ]229// OGCG:   store i32 0, ptr %[[CUR]]230// OGCG:   %[[NEXT]] = getelementptr inbounds i32, ptr %[[CUR]], i64 1231// OGCG:   %[[CMP:.*]] = icmp eq ptr %[[NEXT]], %[[ARR_END]]232// OGCG:   br i1 %[[CMP]], label %[[LOOP_END:.*]], label %[[LOOP_BODY]]233// OGCG: [[LOOP_END]]:234// OGCG:   %[[C:.*]] = getelementptr inbounds nuw %struct.ValueInit, ptr %[[THIS]], i32 0, i32 3235// OGCG:   %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C]], i32 0, i32 0236// OGCG:   %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C]], i32 0, i32 1237// OGCG:   store float 6.000000e+00, ptr %[[C_REAL_PTR]]238// OGCG:   store float 7.000000e+00, ptr %[[C_IMAG_PTR]]239// OGCG:   %[[BF:.*]] = getelementptr inbounds nuw %struct.ValueInit, ptr %[[THIS]], i32 0, i32 4240// OGCG:   store i8 -1, ptr %[[BF]]241 242void use_structs() {243  ZeroInit zi;244  ValueInit vi;245}246