brintos

brintos / llvm-project-archived public Read only

0
0
Text · 24.0 KiB · 5e87381 Raw
462 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -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 -Wno-unused-value -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 -Wno-unused-value -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG7 8int a[10];9// CIR: cir.global external @a = #cir.zero : !cir.array<!s32i x 10>10 11// LLVM: @a = global [10 x i32] zeroinitializer12 13// OGCG: @a = global [10 x i32] zeroinitializer14 15int aa[10][5];16// CIR: cir.global external @aa = #cir.zero : !cir.array<!cir.array<!s32i x 5> x 10>17 18// LLVM: @aa = global [10 x [5 x i32]] zeroinitializer19 20// OGCG: @aa = global [10 x [5 x i32]] zeroinitializer21 22int c[10] = {};23// CIR: cir.global external @c = #cir.zero : !cir.array<!s32i x 10>24 25// LLVM: @c = global [10 x i32] zeroinitializer26 27// OGCG: @c = global [10 x i32] zeroinitializer28 29int d[3] = {1, 2, 3};30// CIR: cir.global external @d = #cir.const_array<[#cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i]> : !cir.array<!s32i x 3>31 32// LLVM: @d = global [3 x i32] [i32 1, i32 2, i32 3]33 34// OGCG: @d = global [3 x i32] [i32 1, i32 2, i32 3]35 36int dd[3][2] = {{1, 2}, {3, 4}, {5, 6}};37// CIR: cir.global external @dd = #cir.const_array<[#cir.const_array<[#cir.int<1> : !s32i, #cir.int<2> : !s32i]> : !cir.array<!s32i x 2>, #cir.const_array<[#cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.array<!s32i x 2>, #cir.const_array<[#cir.int<5> : !s32i, #cir.int<6> : !s32i]> : !cir.array<!s32i x 2>]> : !cir.array<!cir.array<!s32i x 2> x 3>38 39// LLVM: @dd = global [3 x [2 x i32]] [40// LLVM: [2 x i32] [i32 1, i32 2], [2 x i32]41// LLVM: [i32 3, i32 4], [2 x i32] [i32 5, i32 6]]42 43// OGCG: @dd = global [3 x [2 x i32]] [44// OGCG: [2 x i32] [i32 1, i32 2], [2 x i32]45// OGCG: [i32 3, i32 4], [2 x i32] [i32 5, i32 6]]46 47int e[10] = {1, 2};48// CIR: cir.global external @e = #cir.const_record<{#cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.zero : !cir.array<!s32i x 8>}> : !rec_anon_struct49 50// LLVM: @e = global <{ i32, i32, [8 x i32] }> <{ i32 1, i32 2, [8 x i32] zeroinitializer }>51 52// OGCG: @e = global <{ i32, i32, [8 x i32] }> <{ i32 1, i32 2, [8 x i32] zeroinitializer }>53 54int f[5] = {1, 2};55// CIR: cir.global external @f = #cir.const_array<[#cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<0> : !s32i]> : !cir.array<!s32i x 5>56 57// LLVM: @f = global [5 x i32] [i32 1, i32 2, i32 0, i32 0, i32 0]58 59// OGCG: @f = global [5 x i32] [i32 1, i32 2, i32 0, i32 0, i32 0]60 61int g[16] = {1, 2, 3, 4, 5, 6, 7, 8};62// CIR:      cir.global external @g = #cir.const_record<{63// CIR-SAME:   #cir.const_array<[#cir.int<1> : !s32i, #cir.int<2> : !s32i,64// CIR-SAME:                     #cir.int<3> : !s32i, #cir.int<4> : !s32i,65// CIR-SAME:                     #cir.int<5> : !s32i, #cir.int<6> : !s32i,66// CIR-SAME:                     #cir.int<7> : !s32i, #cir.int<8> : !s32i]>67// CIR-SAME:                     : !cir.array<!s32i x 8>,68// CIR-SAME:   #cir.zero : !cir.array<!s32i x 8>}> : !rec_anon_struct169 70// LLVM:       @g = global <{ [8 x i32], [8 x i32] }> 71// LLVM-SAME:          <{ [8 x i32]72// LLVM-SAME:              [i32 1, i32 2, i32 3, i32 4,73// LLVM-SAME:               i32 5, i32 6, i32 7, i32 8],74// LLVM-SAME:             [8 x i32] zeroinitializer }>75 76// OGCG:       @g = global <{ [8 x i32], [8 x i32] }> 77// OGCG-SAME:          <{ [8 x i32]78// OGCG-SAME:              [i32 1, i32 2, i32 3, i32 4,79// OGCG-SAME:               i32 5, i32 6, i32 7, i32 8],80// OGCG-SAME:             [8 x i32] zeroinitializer }>81 82 83extern int b[10];84// CIR: cir.global "private" external @b : !cir.array<!s32i x 10>85// LLVM: @b = external global [10 x i32]86// OGCG: @b = external global [10 x i32]87 88extern int bb[10][5];89// CIR: cir.global "private" external @bb : !cir.array<!cir.array<!s32i x 5> x 10>90// LLVM: @bb = external global [10 x [5 x i32]]91// OGCG: @bb = external global [10 x [5 x i32]]92 93// This function is only here to make sure the external globals are emitted.94void reference_externs() {95  b;96  bb;97}98 99// OGCG: @[[FUN2_ARR:.*]] = private unnamed_addr constant [2 x i32] [i32 5, i32 0], align 4100// OGCG: @[[FUN3_ARR:.*]] = private unnamed_addr constant [2 x i32] [i32 5, i32 6], align 4101// OGCG: @[[FUN4_ARR:.*]] = private unnamed_addr constant [2 x [1 x i32]] [102// OGCG: [1 x i32] [i32 5], [1 x i32] [i32 6]], align 4103// OGCG: @[[FUN5_ARR:.*]] = private unnamed_addr constant [2 x [1 x i32]] [104// OGCG: [1 x i32] [i32 5], [1 x i32] zeroinitializer], align 4105 106void func() {107  int arr[10];108  int e = arr[0];109  int e2 = arr[1];110}111 112// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!s32i x 10>, !cir.ptr<!cir.array<!s32i x 10>>, ["arr"]113// CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]114// CIR: %[[INIT_2:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e2", init]115// CIR: %[[IDX:.*]] = cir.const #cir.int<0> : !s32i116// CIR: %[[ARR_PTR:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!s32i x 10>> -> !cir.ptr<!s32i>117// CIR: %[[ELE_PTR:.*]] = cir.ptr_stride %[[ARR_PTR]], %[[IDX]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>118// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[ELE_PTR]] : !cir.ptr<!s32i>, !s32i119// CIR" cir.store %[[TMP]], %[[INIT]] : !s32i, !cir.ptr<!s32i>120// CIR: %[[IDX:.*]] = cir.const #cir.int<1> : !s32i121// CIR: %[[ARR_PTR:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!s32i x 10>> -> !cir.ptr<!s32i>122// CIR: %[[ELE_PTR:.*]] = cir.ptr_stride %[[ARR_PTR]], %[[IDX]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>123// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[ELE_PTR]] : !cir.ptr<!s32i>, !s32i124// CIR" cir.store %[[TMP]], %[[INIT_2]] : !s32i, !cir.ptr<!s32i>125 126// LLVM: define{{.*}} void @_Z4funcv(){{.*}}127// LLVM-NEXT: %[[ARR:.*]] = alloca [10 x i32], i64 1, align 16128// LLVM-NEXT: %[[INIT:.*]] = alloca i32, i64 1, align 4129// LLVM-NEXT: %[[INIT_2:.*]] = alloca i32, i64 1, align 4130// LLVM-NEXT: %[[ARR_PTR:.*]] = getelementptr i32, ptr %[[ARR]], i32 0131// LLVM-NEXT: %[[ELE_PTR:.*]] = getelementptr i32, ptr %[[ARR_PTR]], i64 0132// LLVM-NEXT: %[[TMP_1:.*]] = load i32, ptr %[[ELE_PTR]], align 16133// LLVM-NEXT: store i32 %[[TMP_1]], ptr %[[INIT]], align 4134// LLVM-NEXT: %[[ARR_PTR:.*]] = getelementptr i32, ptr %[[ARR]], i32 0135// LLVM-NEXT: %[[ELE_PTR:.*]] = getelementptr i32, ptr %[[ARR_PTR]], i64 1136// LLVM-NEXT: %[[TMP_2:.*]] = load i32, ptr %[[ELE_PTR]], align 4137// LLVM-NEXT: store i32 %[[TMP_2]], ptr %[[INIT_2]], align 4138 139// OGCG: %[[ARR:.*]] = alloca [10 x i32], align 16140// OGCG: %[[INIT:.*]] = alloca i32, align 4141// OGCG: %[[INIT_2:.*]] = alloca i32, align 4142// OGCG: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr %[[ARR]], i64 0, i64 0143// OGCG: %[[TMP_1:.*]] = load i32, ptr %[[ELE_PTR]], align 16144// OGCG: store i32 %[[TMP_1]], ptr %[[INIT]], align 4145// OGCG: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr %[[ARR]], i64 0, i64 1146// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_PTR]], align 4147// OGCG: store i32 %[[TMP_2]], ptr %[[INIT_2]], align 4148 149void func2() {150  int arr[2] = {5};151}152 153// CIR: %[[ARR2:.*]] = cir.alloca !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>, ["arr", init]154// CIR: %[[CONST:.*]] = cir.const #cir.const_array<[#cir.int<5> : !s32i, #cir.int<0> : !s32i]> : !cir.array<!s32i x 2>155// CIR: cir.store{{.*}} %[[CONST]], %[[ARR2]] : !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>156 157// LLVM: define{{.*}} void @_Z5func2v(){{.*}}158// LLVM:   %[[ARR:.*]] = alloca [2 x i32], i64 1, align 4159// LLVM:   store [2 x i32] [i32 5, i32 0], ptr %[[ARR]], align 4160 161// OGCG: %[[ARR:.*]] = alloca [2 x i32], align 4162// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[ARR]], ptr align 4 @[[FUN2_ARR]], i64 8, i1 false)163 164void func3() {165  int arr[2] = {5, 6};166 167  int idx = 1;168  int e = arr[idx];169}170 171// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>, ["arr", init]172// CIR: %[[IDX:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["idx", init]173// CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]174// CIR: %[[CONST:.*]] = cir.const #cir.const_array<[#cir.int<5> : !s32i, #cir.int<6> : !s32i]> : !cir.array<!s32i x 2>175// CIR: cir.store{{.*}} %[[CONST]], %[[ARR]] : !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>176// CIR: %[[IDX_V:.*]] = cir.const #cir.int<1> : !s32i177// CIR: cir.store{{.*}} %[[IDX_V]], %[[IDX]] : !s32i, !cir.ptr<!s32i>178// CIR: %[[TMP_IDX:.*]] = cir.load{{.*}} %[[IDX]] : !cir.ptr<!s32i>, !s32i179// CIR: %[[ARR_PTR:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!s32i x 2>> -> !cir.ptr<!s32i>180// CIR: %[[ELE_PTR:.*]] = cir.ptr_stride %[[ARR_PTR]], %[[TMP_IDX]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>181// CIR: %[[ELE_TMP:.*]] = cir.load{{.*}} %[[ELE_PTR]] : !cir.ptr<!s32i>, !s32i182// CIR: cir.store{{.*}} %[[ELE_TMP]], %[[INIT]] : !s32i, !cir.ptr<!s32i>183 184// LLVM: define{{.*}} void @_Z5func3v(){{.*}}185// LLVM:  %[[ARR:.*]] = alloca [2 x i32], i64 1, align 4186// LLVM:  %[[IDX:.*]] = alloca i32, i64 1, align 4187// LLVM:  %[[INIT:.*]] = alloca i32, i64 1, align 4188// LLVM:  store [2 x i32] [i32 5, i32 6], ptr %[[ARR]], align 4189// LLVM:  store i32 1, ptr %[[IDX]], align 4190// LLVM:  %[[TMP1:.*]] = load i32, ptr %[[IDX]], align 4191// LLVM:  %[[ARR_PTR:.*]] = getelementptr i32, ptr %[[ARR]], i32 0192// LLVM:  %[[IDX_I64:.*]] = sext i32 %[[TMP1]] to i64193// LLVM:  %[[ELE:.*]] = getelementptr i32, ptr %[[ARR_PTR]], i64 %[[IDX_I64]]194// LLVM:  %[[TMP2:.*]] = load i32, ptr %[[ELE]], align 4195// LLVM:  store i32 %[[TMP2]], ptr %[[INIT]], align 4196 197// OGCG:  %[[ARR:.*]] = alloca [2 x i32], align 4198// OGCG:  %[[IDX:.*]] = alloca i32, align 4199// OGCG:  %[[INIT:.*]] = alloca i32, align 4200// OGCG:  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[ARR]], ptr align 4 @[[FUN3_ARR]], i64 8, i1 false)201// OGCG:  store i32 1, ptr %[[IDX]], align 4202// OGCG:  %[[TMP:.*]] = load i32, ptr %[[IDX]], align 4203// OGCG:  %[[IDX_I64:.*]] = sext i32 %[[TMP]] to i64204// OGCG:  %[[ELE:.*]] = getelementptr inbounds [2 x i32], ptr %[[ARR]], i64 0, i64 %[[IDX_I64]]205// OGCG:  %[[TMP_2:.*]] = load i32, ptr %[[ELE]], align 4206// OGCG:  store i32 %[[TMP_2:.*]], ptr %[[INIT]], align 4207 208void func4() {209  int arr[2][1] = {{5}, {6}};210  int e = arr[1][0];211}212 213// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!cir.array<!s32i x 1> x 2>, !cir.ptr<!cir.array<!cir.array<!s32i x 1> x 2>>, ["arr", init]214// CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]215// CIR: %[[CONST:.*]] = cir.const #cir.const_array<[#cir.const_array<[#cir.int<5> : !s32i]> : !cir.array<!s32i x 1>, #cir.const_array<[#cir.int<6> : !s32i]> : !cir.array<!s32i x 1>]> : !cir.array<!cir.array<!s32i x 1> x 2>216// CIR: cir.store{{.*}} %[[CONST]], %[[ARR]] : !cir.array<!cir.array<!s32i x 1> x 2>, !cir.ptr<!cir.array<!cir.array<!s32i x 1> x 2>>217// CIR: %[[IDX:.*]] = cir.const #cir.int<0> : !s32i218// CIR: %[[IDX_1:.*]] = cir.const #cir.int<1> : !s32i219// CIR: %[[ARR_PTR:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!cir.array<!s32i x 1> x 2>> -> !cir.ptr<!cir.array<!s32i x 1>>220// CIR: %[[ARR_1:.*]] = cir.ptr_stride %[[ARR_PTR]], %[[IDX_1]] : (!cir.ptr<!cir.array<!s32i x 1>>, !s32i) -> !cir.ptr<!cir.array<!s32i x 1>>221// CIR: %[[ARR_1_PTR:.*]] = cir.cast array_to_ptrdecay %[[ARR_1]] : !cir.ptr<!cir.array<!s32i x 1>> -> !cir.ptr<!s32i>222// CIR: %[[ELE_0:.*]] = cir.ptr_stride %[[ARR_1_PTR]], %[[IDX]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>223// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[ELE_0]] : !cir.ptr<!s32i>, !s32i224// CIR: cir.store{{.*}} %[[TMP]], %[[INIT]] : !s32i, !cir.ptr<!s32i>225 226// LLVM: define{{.*}} void @_Z5func4v(){{.*}}227// LLVM:  %[[ARR:.*]] = alloca [2 x [1 x i32]], i64 1, align 4228// LLVM:  %[[INIT:.*]] = alloca i32, i64 1, align 4229// LLVM:  store [2 x [1 x i32]] {{\[}}[1 x i32] [i32 5], [1 x i32] [i32 6]], ptr %[[ARR]], align 4230// LLVM:  %[[ARR_PTR:.*]] = getelementptr [1 x i32], ptr %[[ARR]], i32 0231// LLVM:  %[[ARR_1:.*]] = getelementptr [1 x i32], ptr %[[ARR_PTR]], i64 1232// LLVM:  %[[ARR_1_0:.*]] = getelementptr i32, ptr %[[ARR_1]], i32 0233// LLVM:  %[[ELE_PTR:.*]] = getelementptr i32, ptr %[[ARR_1_0]], i64 0234// LLVM:  %[[TMP:.*]] = load i32, ptr %[[ELE_PTR]], align 4235// LLVM:  store i32 %[[TMP]], ptr %[[INIT]], align 4236 237// OGCG: %[[ARR:.*]] = alloca [2 x [1 x i32]], align 4238// OGCG: %[[INIT:.*]] = alloca i32, align 4239// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[ARR]], ptr align 4 @[[FUN4_ARR]], i64 8, i1 false)240// OGCG: %[[ARR_1:.*]] = getelementptr inbounds [2 x [1 x i32]], ptr %[[ARR]], i64 0, i64 1241// OGCG: %[[ARR_1_0:.*]] = getelementptr inbounds [1 x i32], ptr %[[ARR_1]], i64 0, i64 0242// OGCG: %[[TMP:.*]] = load i32, ptr %[[ARR_1_0]], align 4243// OGCG: store i32 %[[TMP]], ptr %[[INIT]], align 4244 245void func5() {246  int arr[2][1] = {{5}};247}248 249// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!cir.array<!s32i x 1> x 2>, !cir.ptr<!cir.array<!cir.array<!s32i x 1> x 2>>, ["arr", init]250// CIR: %[[CONST:.*]] = cir.const #cir.const_array<[#cir.const_array<[#cir.int<5> : !s32i]> : !cir.array<!s32i x 1>, #cir.zero : !cir.array<!s32i x 1>]> : !cir.array<!cir.array<!s32i x 1> x 2>251// CIR: cir.store{{.*}} %[[CONST]], %[[ARR]] : !cir.array<!cir.array<!s32i x 1> x 2>, !cir.ptr<!cir.array<!cir.array<!s32i x 1> x 2>>252 253// LLVM: define{{.*}} void @_Z5func5v(){{.*}}254// LLVM:   %[[ARR:.*]] = alloca [2 x [1 x i32]], i64 1, align 4255// LLVM:   store [2 x [1 x i32]] {{\[}}[1 x i32] [i32 5], [1 x i32] zeroinitializer], ptr %[[ARR]], align 4256 257// ORGC: %[[ARR:.*]] = alloca [2 x [1 x i32]], align 4258// ORGC: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[ARR]], ptr align 4 @[[FUN5_ARR]], i64 8, i1 false)259 260void func6() {261  int x = 4;262  int arr[2] = { x, 5 };263}264 265// CIR: %[[VAR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init]266// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>, ["arr", init]267// CIR: %[[V:.*]] = cir.const #cir.int<4> : !s32i268// CIR: cir.store{{.*}} %[[V]], %[[VAR]] : !s32i, !cir.ptr<!s32i>269// CIR: %[[ARR_PTR:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!s32i x 2>> -> !cir.ptr<!s32i>270// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[VAR]] : !cir.ptr<!s32i>, !s32i271// CIR: cir.store{{.*}} %[[TMP]], %[[ARR_PTR]] : !s32i, !cir.ptr<!s32i>272// CIR: %[[OFFSET:.*]] = cir.const #cir.int<1> : !s64i273// CIR: %[[ELE_PTR:.*]] = cir.ptr_stride %[[ARR_PTR]], %[[OFFSET]] : (!cir.ptr<!s32i>, !s64i) -> !cir.ptr<!s32i>274// CIR: %[[V1:.*]] = cir.const #cir.int<5> : !s32i275// CIR: cir.store{{.*}} %[[V1]], %[[ELE_PTR]] : !s32i, !cir.ptr<!s32i>276 277// LLVM: define{{.*}} void @_Z5func6v(){{.*}}278// LLVM:  %[[VAR:.*]] = alloca i32, i64 1, align 4279// LLVM:  %[[ARR:.*]] = alloca [2 x i32], i64 1, align 4280// LLVM:  store i32 4, ptr %[[VAR]], align 4281// LLVM:  %[[ELE_0:.*]] = getelementptr i32, ptr %[[ARR]], i32 0282// LLVM:  %[[TMP:.*]] = load i32, ptr %[[VAR]], align 4283// LLVM:  store i32 %[[TMP]], ptr %[[ELE_0]], align 4284// LLVM:  %[[ELE_1:.*]] = getelementptr i32, ptr %[[ELE_0]], i64 1285// LLVM:  store i32 5, ptr %[[ELE_1]], align 4286 287// OGCG:  %[[VAR:.*]] = alloca i32, align 4288// OGCG:  %[[ARR:.*]] = alloca [2 x i32], align 4289// OGCG:  store i32 4, ptr %[[VAR]], align 4290// OGCG:  %[[ELE_0:.*]] = load i32, ptr %[[VAR]], align 4291// OGCG:  store i32 %[[ELE_0]], ptr %[[ARR]], align 4292// OGCG:  %[[ELE_1:.*]] = getelementptr inbounds i32, ptr %[[ARR]], i64 1293// OGCG:  store i32 5, ptr %[[ELE_1:.*]], align 4294 295void func7() {296  int* arr[1] = {};297}298 299// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!cir.ptr<!s32i> x 1>, !cir.ptr<!cir.array<!cir.ptr<!s32i> x 1>>, ["arr", init]300// CIR: %[[CONST:.*]] = cir.const #cir.zero : !cir.array<!cir.ptr<!s32i> x 1>301// CIR: cir.store{{.*}} %[[CONST]], %[[ARR]] : !cir.array<!cir.ptr<!s32i> x 1>, !cir.ptr<!cir.array<!cir.ptr<!s32i> x 1>>302 303// LLVM: define{{.*}} void @_Z5func7v(){{.*}}304// LLVM:   %[[ARR:.*]] = alloca [1 x ptr], i64 1, align 8305// LLVM:   store [1 x ptr] zeroinitializer, ptr %[[ARR]], align 8306 307// OGCG: %[[ARR:.*]] = alloca [1 x ptr], align 8308// OGCG: call void @llvm.memset.p0.i64(ptr align 8 %[[ARR]], i8 0, i64 8, i1 false)309 310void func8(int arr[10]) {311  int e = arr[0];312  int e2 = arr[1];313}314 315// CIR: cir.func{{.*}} @_Z5func8Pi(%[[ARG:.*]]: !cir.ptr<!s32i>316// CIR:  %[[ARR:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["arr", init]317// CIR:  %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]318// CIR:  %[[INIT_2:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e2", init]319// CIR:  cir.store{{.*}} %[[ARG]], %[[ARR]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>320// CIR:  %[[IDX:.*]] = cir.const #cir.int<0> : !s32i321// CIR:  %[[TMP_1:.*]] = cir.load{{.*}} %[[ARR]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>322// CIR:  %[[ELE_0:.*]] = cir.ptr_stride %[[TMP_1]], %[[IDX]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>323// CIR:  %[[TMP_2:.*]] = cir.load{{.*}} %[[ELE_0]] : !cir.ptr<!s32i>, !s32i324// CIR:  cir.store{{.*}} %[[TMP_2]], %[[INIT]] : !s32i, !cir.ptr<!s32i>325// CIR:  %[[IDX_1:.*]] = cir.const #cir.int<1> : !s32i326// CIR:  %[[TMP_3:.*]] = cir.load{{.*}} %[[ARR]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>327// CIR:  %[[ELE_1:.*]] = cir.ptr_stride %[[TMP_3]], %[[IDX_1]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>328// CIR:  %[[TMP_4:.*]] = cir.load{{.*}} %[[ELE_1]] : !cir.ptr<!s32i>, !s32i329// CIR:  cir.store{{.*}} %[[TMP_4]], %[[INIT_2]] : !s32i, !cir.ptr<!s32i>330 331// LLVM: define{{.*}} void @_Z5func8Pi(ptr %[[ARG:.*]]){{.*}}332// LLVM:  %[[ARR:.*]] = alloca ptr, i64 1, align 8333// LLVM:  %[[INIT:.*]] = alloca i32, i64 1, align 4334// LLVM:  %[[INIT_2:.*]] = alloca i32, i64 1, align 4335// LLVM:  store ptr %[[ARG]], ptr %[[ARR]], align 8336// LLVM:  %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8337// LLVM:  %[[ELE_0:.*]] = getelementptr i32, ptr %[[TMP_1]], i64 0338// LLVM:  %[[TMP_2:.*]] = load i32, ptr %[[ELE_0]], align 4339// LLVM:  store i32 %[[TMP_2]], ptr %[[INIT]], align 4340// LLVM:  %[[TMP_3:.*]] = load ptr, ptr %[[ARR]], align 8341// LLVM:  %[[ELE_1:.*]] = getelementptr i32, ptr %[[TMP_3]], i64 1342// LLVM:  %[[TMP_4:.*]] = load i32, ptr %[[ELE_1]], align 4343// LLVM:  store i32 %[[TMP_4]], ptr %[[INIT_2]], align 4344 345// OGCG: %[[ARR:.*]] = alloca ptr, align 8346// OGCG: %[[INIT:.*]] = alloca i32, align 4347// OGCG: %[[INIT_2:.*]] = alloca i32, align 4348// OGCG: store ptr {{%.*}}, ptr %[[ARR]], align 8349// OGCG: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8350// OGCG: %[[ELE_0:.*]] = getelementptr inbounds i32, ptr %[[TMP_1]], i64 0351// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_0]], align 4352// OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4353// OGCG: %[[TMP_3:.*]] = load ptr, ptr %[[ARR]], align 8354// OGCG: %[[ELE_1:.*]] = getelementptr inbounds i32, ptr %[[TMP_3]], i64 1355// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_1]], align 4356// OGCG: store i32 %[[TMP_2]], ptr %[[INIT_2]], align 4357 358void func9(int arr[10][5]) {359  int e = arr[1][2];360}361 362// CIR: cir.func{{.*}} @_Z5func9PA5_i(%[[ARG:.*]]: !cir.ptr<!cir.array<!s32i x 5>>363// CIR:  %[[ARR:.*]] = cir.alloca !cir.ptr<!cir.array<!s32i x 5>>, !cir.ptr<!cir.ptr<!cir.array<!s32i x 5>>>, ["arr", init]364// CIR:  %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]365// CIR:  cir.store{{.*}} %[[ARG]], %[[ARR]] : !cir.ptr<!cir.array<!s32i x 5>>, !cir.ptr<!cir.ptr<!cir.array<!s32i x 5>>>366// CIR:  %[[IDX:.*]] = cir.const #cir.int<2> : !s32i367// CIR:  %[[IDX_1:.*]] = cir.const #cir.int<1> : !s32i368// CIR:  %[[TMP_1:.*]] = cir.load{{.*}} %[[ARR]] : !cir.ptr<!cir.ptr<!cir.array<!s32i x 5>>>, !cir.ptr<!cir.array<!s32i x 5>>369// CIR:  %[[ARR_1:.*]] = cir.ptr_stride %[[TMP_1]], %[[IDX_1]] : (!cir.ptr<!cir.array<!s32i x 5>>, !s32i) -> !cir.ptr<!cir.array<!s32i x 5>>370// CIR:  %[[ARR_1_PTR:.*]] = cir.cast array_to_ptrdecay %[[ARR_1]] : !cir.ptr<!cir.array<!s32i x 5>> -> !cir.ptr<!s32i>371// CIR:  %[[ARR_1_2:.*]] = cir.ptr_stride %[[ARR_1_PTR]], %[[IDX]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>372// CIR:  %[[TMP_2:.*]] = cir.load{{.*}} %[[ARR_1_2]] : !cir.ptr<!s32i>, !s32i373// CIR:  cir.store{{.*}} %[[TMP_2]], %[[INIT]] : !s32i, !cir.ptr<!s32i>374 375// LLVM: define{{.*}} void @_Z5func9PA5_i(ptr %[[ARG:.*]]){{.*}}376// LLVM:  %[[ARR:.*]] = alloca ptr, i64 1, align 8377// LLVM:  %[[INIT:.*]] = alloca i32, i64 1, align 4378// LLVM:  store ptr %[[ARG]], ptr %[[ARR]], align 8379// LLVM:  %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8380// LLVM:  %[[ARR_1:.*]] = getelementptr [5 x i32], ptr %[[TMP_1]], i64 1381// LLVM:  %[[ARR_1_PTR:.*]] = getelementptr i32, ptr %[[ARR_1]], i32 0382// LLVM:  %[[ARR_1_2:.*]] = getelementptr i32, ptr %[[ARR_1_PTR]], i64 2383// LLVM:  %[[TMP_2:.*]] = load i32, ptr %[[ARR_1_2]], align 4384// LLVM:  store i32 %[[TMP_2]], ptr %[[INIT]], align 4385 386// OGCG: %[[ARR:.*]] = alloca ptr, align 8387// OGCG: %[[INIT:.*]] = alloca i32, align 4388// OGCG: store ptr {{%.*}}, ptr %[[ARR]], align 8389// OGCG: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8390// OGCG: %[[ARR_1:.*]] = getelementptr inbounds [5 x i32], ptr %[[TMP_1]], i64 1391// OGCG: %[[ARR_1_2:.*]] = getelementptr inbounds [5 x i32], ptr %[[ARR_1]], i64 0, i64 2392// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ARR_1_2]], align 4393// OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4394 395void func10(int *a) {396  int e = a[5];397}398 399// CIR: cir.func{{.*}} @_Z6func10Pi(%[[ARG:.*]]: !cir.ptr<!s32i>400// CIR: %[[ARR:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["a", init]401// CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]402// CIR: cir.store{{.*}} %[[ARG]], %[[ARR]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>403// CIR: %[[IDX:.*]] = cir.const #cir.int<5> : !s32i404// CIR: %[[TMP_1:.*]] = cir.load{{.*}} %[[ARR]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>405// CIR: %[[ELE:.*]] = cir.ptr_stride %[[TMP_1]], %[[IDX]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>406// CIR: %[[TMP_2:.*]] = cir.load{{.*}} %[[ELE]] : !cir.ptr<!s32i>, !s32i407// CIR: cir.store{{.*}} %[[TMP_2]], %[[INIT]] : !s32i, !cir.ptr<!s32i>408 409// LLVM: define{{.*}} void @_Z6func10Pi(ptr %[[ARG:.*]]){{.*}} {410// LLVM:  %[[ARR:.*]] = alloca ptr, i64 1, align 8411// LLVM:  %[[INIT:.*]] = alloca i32, i64 1, align 4412// LLVM:  store ptr %[[ARG]], ptr %[[ARR]], align 8413// LLVM:  %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8414// LLVM:  %[[ELE:.*]] = getelementptr i32, ptr %[[TMP_1]], i64 5415// LLVM:  %[[TMP_2:.*]] = load i32, ptr %[[ELE]], align 4416// LLVM:  store i32 %[[TMP_2]], ptr %[[INIT]], align 4417 418// OGCG:  %[[ARR:.*]] = alloca ptr, align 8419// OGCG:  %[[INIT:.*]] = alloca i32, align 4420// OGCG:  store ptr {{%.*}}, ptr %[[ARR]], align 8421// OGCG:  %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8422// OGCG:  %[[ELE:.*]] = getelementptr inbounds i32, ptr %[[TMP_1]], i64 5423// OGCG:  %[[TMP_2:.*]] = load i32, ptr %[[ELE]], align 4424// OGCG:  store i32 %[[TMP_2]], ptr %[[INIT]], align 4425 426void func11() { int _Complex a[4]; }427 428// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!cir.complex<!s32i> x 4>, !cir.ptr<!cir.array<!cir.complex<!s32i> x 4>>, ["a"]429 430// LLVM: %[[ARR:.*]] = alloca [4 x { i32, i32 }], i64 1, align 16431 432// OGCG: %[[ARR:.*]] = alloca [4 x { i32, i32 }], align 16433 434void func12() {435  struct Point {436    int x;437    int y;438  };439 440  Point a[4];441}442 443// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!rec_Point x 4>, !cir.ptr<!cir.array<!rec_Point x 4>>, ["a"]444 445// LLVM: %[[ARR:.*]] = alloca [4 x %struct.Point], i64 1, align 16446 447// OGCG: %[[ARR:.*]] = alloca [4 x %struct.Point], align 16448 449void array_with_complex_elements() {450  _Complex float arr[2] = {{1.1f, 2.2f}, {3.3f, 4.4f}};451}452 453// CIR: %[[ARR_ADDR:.*]] = cir.alloca !cir.array<!cir.complex<!cir.float> x 2>, !cir.ptr<!cir.array<!cir.complex<!cir.float> x 2>>, ["arr", init]454// CIR: %[[CONST:.*]] = cir.const #cir.const_array<[#cir.const_complex<#cir.fp<1.100000e+00> : !cir.float, #cir.fp<2.200000e+00> : !cir.float> : !cir.complex<!cir.float>, #cir.const_complex<#cir.fp<3.300000e+00> : !cir.float, #cir.fp<4.400000e+00> : !cir.float> : !cir.complex<!cir.float>]> : !cir.array<!cir.complex<!cir.float> x 2>455// CIR: cir.store{{.*}} %[[CONST]], %[[ARR_ADDR]] : !cir.array<!cir.complex<!cir.float> x 2>, !cir.ptr<!cir.array<!cir.complex<!cir.float> x 2>>456 457// LLVM: %[[ARR_ADDR:.*]] = alloca [2 x { float, float }], i64 1, align 16458// LLVM: store [2 x { float, float }] [{ float, float } { float 0x3FF19999A0000000, float 0x40019999A0000000 }, { float, float } { float 0x400A666660000000, float 0x40119999A0000000 }], ptr %[[ARR_ADDR]], align 16459 460// OGCG: %[[ARR_ADDR:.*]] = alloca [2 x { float, float }], align 16461// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 16 %[[ARR_ADDR]], ptr align 16 @__const._Z27array_with_complex_elementsv.arr, i64 16, i1 false)462