Debian Codegraph @

clang/test/CIR/CodeGen/array.cpp

raw
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2 // RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4 // RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6 // RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7
8 int a[10];
9 // CIR: cir.global external @a = #cir.zero : !cir.array<!s32i x 10>
10
11 // LLVM: @a = global [10 x i32] zeroinitializer
12
13 // OGCG: @a = global [10 x i32] zeroinitializer
14
15 int 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]] zeroinitializer
19
20 // OGCG: @aa = global [10 x [5 x i32]] zeroinitializer
21
22 int c[10] = {};
23 // CIR: cir.global external @c = #cir.zero : !cir.array<!s32i x 10>
24
25 // LLVM: @c = global [10 x i32] zeroinitializer
26
27 // OGCG: @c = global [10 x i32] zeroinitializer
28
29 int 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
36 int 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
47 int 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_struct
49
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
54 int 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
61 int 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_struct1
69
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
83 extern 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
88 extern 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.
94 void reference_externs() {
95 b;
96 bb;
97 }
98
99 // OGCG: @[[FUN2_ARR:.*]] = private unnamed_addr constant [2 x i32] [i32 5, i32 0], align 4
100 // OGCG: @[[FUN3_ARR:.*]] = private unnamed_addr constant [2 x i32] [i32 5, i32 6], align 4
101 // 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 4
103 // OGCG: @[[FUN5_ARR:.*]] = private unnamed_addr constant [2 x [1 x i32]] [
104 // OGCG: [1 x i32] [i32 5], [1 x i32] zeroinitializer], align 4
105
106 void 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> : !s32i
116 // CIR: %[[ELE_PTR:.*]] = cir.get_element %[[ARR]][%[[IDX]] : !s32i] : !cir.ptr<!cir.array<!s32i x 10>> -> !cir.ptr<!s32i>
117 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[ELE_PTR]] : !cir.ptr<!s32i>, !s32i
118 // CIR" cir.store %[[TMP]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
119 // CIR: %[[IDX:.*]] = cir.const #cir.int<1> : !s32i
120 // CIR: %[[ELE_PTR:.*]] = cir.get_element %[[ARR]][%[[IDX]] : !s32i] : !cir.ptr<!cir.array<!s32i x 10>> -> !cir.ptr<!s32i>
121 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[ELE_PTR]] : !cir.ptr<!s32i>, !s32i
122 // CIR" cir.store %[[TMP]], %[[INIT_2]] : !s32i, !cir.ptr<!s32i>
123
124 // LLVM: define{{.*}} void @_Z4funcv(){{.*}}
125 // LLVM-NEXT: %[[ARR:.*]] = alloca [10 x i32], i64 1, align 16
126 // LLVM-NEXT: %[[INIT:.*]] = alloca i32, i64 1, align 4
127 // LLVM-NEXT: %[[INIT_2:.*]] = alloca i32, i64 1, align 4
128 // LLVM-NEXT: %[[ELE_PTR:.*]] = getelementptr [10 x i32], ptr %[[ARR]], i32 0, i64 0
129 // LLVM-NEXT: %[[TMP_1:.*]] = load i32, ptr %[[ELE_PTR]], align 16
130 // LLVM-NEXT: store i32 %[[TMP_1]], ptr %[[INIT]], align 4
131 // LLVM-NEXT: %[[ELE_PTR:.*]] = getelementptr [10 x i32], ptr %[[ARR]], i32 0, i64 1
132 // LLVM-NEXT: %[[TMP_2:.*]] = load i32, ptr %[[ELE_PTR]], align 4
133 // LLVM-NEXT: store i32 %[[TMP_2]], ptr %[[INIT_2]], align 4
134
135 // OGCG: %[[ARR:.*]] = alloca [10 x i32], align 16
136 // OGCG: %[[INIT:.*]] = alloca i32, align 4
137 // OGCG: %[[INIT_2:.*]] = alloca i32, align 4
138 // OGCG: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr %[[ARR]], i64 0, i64 0
139 // OGCG: %[[TMP_1:.*]] = load i32, ptr %[[ELE_PTR]], align 16
140 // OGCG: store i32 %[[TMP_1]], ptr %[[INIT]], align 4
141 // OGCG: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr %[[ARR]], i64 0, i64 1
142 // OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_PTR]], align 4
143 // OGCG: store i32 %[[TMP_2]], ptr %[[INIT_2]], align 4
144
145 void func2() {
146 int arr[2] = {5};
147 }
148
149 // CIR: %[[ARR2:.*]] = cir.alloca !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>, ["arr", init]
150 // CIR: %[[CONST:.*]] = cir.const #cir.const_array<[#cir.int<5> : !s32i, #cir.int<0> : !s32i]> : !cir.array<!s32i x 2>
151 // CIR: cir.store{{.*}} %[[CONST]], %[[ARR2]] : !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>
152
153 // LLVM: define{{.*}} void @_Z5func2v(){{.*}}
154 // LLVM: %[[ARR:.*]] = alloca [2 x i32], i64 1, align 4
155 // LLVM: store [2 x i32] [i32 5, i32 0], ptr %[[ARR]], align 4
156
157 // OGCG: %[[ARR:.*]] = alloca [2 x i32], align 4
158 // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[ARR]], ptr align 4 @[[FUN2_ARR]], i64 8, i1 false)
159
160 void func3() {
161 int arr[2] = {5, 6};
162
163 int idx = 1;
164 int e = arr[idx];
165 }
166
167 // CIR: %[[ARR:.*]] = cir.alloca !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>, ["arr", init]
168 // CIR: %[[IDX:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["idx", init]
169 // CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]
170 // CIR: %[[CONST:.*]] = cir.const #cir.const_array<[#cir.int<5> : !s32i, #cir.int<6> : !s32i]> : !cir.array<!s32i x 2>
171 // CIR: cir.store{{.*}} %[[CONST]], %[[ARR]] : !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>
172 // CIR: %[[IDX_V:.*]] = cir.const #cir.int<1> : !s32i
173 // CIR: cir.store{{.*}} %[[IDX_V]], %[[IDX]] : !s32i, !cir.ptr<!s32i>
174 // CIR: %[[TMP_IDX:.*]] = cir.load{{.*}} %[[IDX]] : !cir.ptr<!s32i>, !s32i
175 // CIR: %[[ELE_PTR:.*]] = cir.get_element %[[ARR]][%[[TMP_IDX]] : !s32i] : !cir.ptr<!cir.array<!s32i x 2>> -> !cir.ptr<!s32i>
176 // CIR: %[[ELE_TMP:.*]] = cir.load{{.*}} %[[ELE_PTR]] : !cir.ptr<!s32i>, !s32i
177 // CIR: cir.store{{.*}} %[[ELE_TMP]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
178
179 // LLVM: define{{.*}} void @_Z5func3v(){{.*}}
180 // LLVM: %[[ARR:.*]] = alloca [2 x i32], i64 1, align 4
181 // LLVM: %[[IDX:.*]] = alloca i32, i64 1, align 4
182 // LLVM: %[[INIT:.*]] = alloca i32, i64 1, align 4
183 // LLVM: store [2 x i32] [i32 5, i32 6], ptr %[[ARR]], align 4
184 // LLVM: store i32 1, ptr %[[IDX]], align 4
185 // LLVM: %[[TMP1:.*]] = load i32, ptr %[[IDX]], align 4
186 // LLVM: %[[IDX_I64:.*]] = sext i32 %[[TMP1]] to i64
187 // LLVM: %[[ELE:.*]] = getelementptr [2 x i32], ptr %[[ARR]], i32 0, i64 %[[IDX_I64]]
188 // LLVM: %[[TMP2:.*]] = load i32, ptr %[[ELE]], align 4
189 // LLVM: store i32 %[[TMP2]], ptr %[[INIT]], align 4
190
191 // OGCG: %[[ARR:.*]] = alloca [2 x i32], align 4
192 // OGCG: %[[IDX:.*]] = alloca i32, align 4
193 // OGCG: %[[INIT:.*]] = alloca i32, align 4
194 // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[ARR]], ptr align 4 @[[FUN3_ARR]], i64 8, i1 false)
195 // OGCG: store i32 1, ptr %[[IDX]], align 4
196 // OGCG: %[[TMP:.*]] = load i32, ptr %[[IDX]], align 4
197 // OGCG: %[[IDX_I64:.*]] = sext i32 %[[TMP]] to i64
198 // OGCG: %[[ELE:.*]] = getelementptr inbounds [2 x i32], ptr %[[ARR]], i64 0, i64 %[[IDX_I64]]
199 // OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE]], align 4
200 // OGCG: store i32 %[[TMP_2:.*]], ptr %[[INIT]], align 4
201
202 void func4() {
203 int arr[2][1] = {{5}, {6}};
204 int e = arr[1][0];
205 }
206
207 // 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]
208 // CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]
209 // 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>
210 // 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>>
211 // CIR: %[[IDX:.*]] = cir.const #cir.int<0> : !s32i
212 // CIR: %[[IDX_1:.*]] = cir.const #cir.int<1> : !s32i
213 // CIR: %[[ARR_1:.*]] = cir.get_element %[[ARR]][%[[IDX_1]] : !s32i] : !cir.ptr<!cir.array<!cir.array<!s32i x 1> x 2>> -> !cir.ptr<!cir.array<!s32i x 1>>
214 // CIR: %[[ELE_0:.*]] = cir.get_element %[[ARR_1]][%[[IDX]] : !s32i] : !cir.ptr<!cir.array<!s32i x 1>> -> !cir.ptr<!s32i>
215 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[ELE_0]] : !cir.ptr<!s32i>, !s32i
216 // CIR: cir.store{{.*}} %[[TMP]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
217
218 // LLVM: define{{.*}} void @_Z5func4v(){{.*}}
219 // LLVM: %[[ARR:.*]] = alloca [2 x [1 x i32]], i64 1, align 4
220 // LLVM: %[[INIT:.*]] = alloca i32, i64 1, align 4
221 // LLVM: store [2 x [1 x i32]] {{\[}}[1 x i32] [i32 5], [1 x i32] [i32 6]], ptr %[[ARR]], align 4
222 // LLVM: %[[ARR_1:.*]] = getelementptr [2 x [1 x i32]], ptr %[[ARR]], i32 0, i64 1
223 // LLVM: %[[ELE_PTR:.*]] = getelementptr [1 x i32], ptr %[[ARR_1]], i32 0, i64 0
224 // LLVM: %[[TMP:.*]] = load i32, ptr %[[ELE_PTR]], align 4
225 // LLVM: store i32 %[[TMP]], ptr %[[INIT]], align 4
226
227 // OGCG: %[[ARR:.*]] = alloca [2 x [1 x i32]], align 4
228 // OGCG: %[[INIT:.*]] = alloca i32, align 4
229 // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[ARR]], ptr align 4 @[[FUN4_ARR]], i64 8, i1 false)
230 // OGCG: %[[ARR_1:.*]] = getelementptr inbounds [2 x [1 x i32]], ptr %[[ARR]], i64 0, i64 1
231 // OGCG: %[[ARR_1_0:.*]] = getelementptr inbounds [1 x i32], ptr %[[ARR_1]], i64 0, i64 0
232 // OGCG: %[[TMP:.*]] = load i32, ptr %[[ARR_1_0]], align 4
233 // OGCG: store i32 %[[TMP]], ptr %[[INIT]], align 4
234
235 void func5() {
236 int arr[2][1] = {{5}};
237 }
238
239 // 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]
240 // 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>
241 // 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>>
242
243 // LLVM: define{{.*}} void @_Z5func5v(){{.*}}
244 // LLVM: %[[ARR:.*]] = alloca [2 x [1 x i32]], i64 1, align 4
245 // LLVM: store [2 x [1 x i32]] {{\[}}[1 x i32] [i32 5], [1 x i32] zeroinitializer], ptr %[[ARR]], align 4
246
247 // ORGC: %[[ARR:.*]] = alloca [2 x [1 x i32]], align 4
248 // ORGC: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[ARR]], ptr align 4 @[[FUN5_ARR]], i64 8, i1 false)
249
250 void func6() {
251 int x = 4;
252 int arr[2] = { x, 5 };
253 }
254
255 // CIR: %[[VAR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init]
256 // CIR: %[[ARR:.*]] = cir.alloca !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>, ["arr", init]
257 // CIR: %[[V:.*]] = cir.const #cir.int<4> : !s32i
258 // CIR: cir.store{{.*}} %[[V]], %[[VAR]] : !s32i, !cir.ptr<!s32i>
259 // CIR: %[[ARR_PTR:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!s32i x 2>> -> !cir.ptr<!s32i>
260 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[VAR]] : !cir.ptr<!s32i>, !s32i
261 // CIR: cir.store{{.*}} %[[TMP]], %[[ARR_PTR]] : !s32i, !cir.ptr<!s32i>
262 // CIR: %[[OFFSET:.*]] = cir.const #cir.int<1> : !s64i
263 // CIR: %[[ELE_PTR:.*]] = cir.ptr_stride %[[ARR_PTR]], %[[OFFSET]] : (!cir.ptr<!s32i>, !s64i) -> !cir.ptr<!s32i>
264 // CIR: %[[V1:.*]] = cir.const #cir.int<5> : !s32i
265 // CIR: cir.store{{.*}} %[[V1]], %[[ELE_PTR]] : !s32i, !cir.ptr<!s32i>
266
267 // LLVM: define{{.*}} void @_Z5func6v(){{.*}}
268 // LLVM: %[[VAR:.*]] = alloca i32, i64 1, align 4
269 // LLVM: %[[ARR:.*]] = alloca [2 x i32], i64 1, align 4
270 // LLVM: store i32 4, ptr %[[VAR]], align 4
271 // LLVM: %[[ELE_0:.*]] = getelementptr i32, ptr %[[ARR]], i32 0
272 // LLVM: %[[TMP:.*]] = load i32, ptr %[[VAR]], align 4
273 // LLVM: store i32 %[[TMP]], ptr %[[ELE_0]], align 4
274 // LLVM: %[[ELE_1:.*]] = getelementptr i32, ptr %[[ELE_0]], i64 1
275 // LLVM: store i32 5, ptr %[[ELE_1]], align 4
276
277 // OGCG: %[[VAR:.*]] = alloca i32, align 4
278 // OGCG: %[[ARR:.*]] = alloca [2 x i32], align 4
279 // OGCG: store i32 4, ptr %[[VAR]], align 4
280 // OGCG: %[[ELE_0:.*]] = load i32, ptr %[[VAR]], align 4
281 // OGCG: store i32 %[[ELE_0]], ptr %[[ARR]], align 4
282 // OGCG: %[[ELE_1:.*]] = getelementptr inbounds i32, ptr %[[ARR]], i64 1
283 // OGCG: store i32 5, ptr %[[ELE_1:.*]], align 4
284
285 void func7() {
286 int* arr[1] = {};
287 }
288
289 // CIR: %[[ARR:.*]] = cir.alloca !cir.array<!cir.ptr<!s32i> x 1>, !cir.ptr<!cir.array<!cir.ptr<!s32i> x 1>>, ["arr", init]
290 // CIR: %[[CONST:.*]] = cir.const #cir.zero : !cir.array<!cir.ptr<!s32i> x 1>
291 // CIR: cir.store{{.*}} %[[CONST]], %[[ARR]] : !cir.array<!cir.ptr<!s32i> x 1>, !cir.ptr<!cir.array<!cir.ptr<!s32i> x 1>>
292
293 // LLVM: define{{.*}} void @_Z5func7v(){{.*}}
294 // LLVM: %[[ARR:.*]] = alloca [1 x ptr], i64 1, align 8
295 // LLVM: store [1 x ptr] zeroinitializer, ptr %[[ARR]], align 8
296
297 // OGCG: %[[ARR:.*]] = alloca [1 x ptr], align 8
298 // OGCG: call void @llvm.memset.p0.i64(ptr align 8 %[[ARR]], i8 0, i64 8, i1 false)
299
300 void func8(int arr[10]) {
301 int e = arr[0];
302 int e2 = arr[1];
303 }
304
305 // CIR: cir.func{{.*}} @_Z5func8Pi(%[[ARG:.*]]: !cir.ptr<!s32i>
306 // CIR: %[[ARR:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["arr", init]
307 // CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]
308 // CIR: %[[INIT_2:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e2", init]
309 // CIR: cir.store{{.*}} %[[ARG]], %[[ARR]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
310 // CIR: %[[IDX:.*]] = cir.const #cir.int<0> : !s32i
311 // CIR: %[[TMP_1:.*]] = cir.load{{.*}} %[[ARR]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>
312 // CIR: %[[ELE_0:.*]] = cir.ptr_stride %[[TMP_1]], %[[IDX]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>
313 // CIR: %[[TMP_2:.*]] = cir.load{{.*}} %[[ELE_0]] : !cir.ptr<!s32i>, !s32i
314 // CIR: cir.store{{.*}} %[[TMP_2]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
315 // CIR: %[[IDX_1:.*]] = cir.const #cir.int<1> : !s32i
316 // CIR: %[[TMP_3:.*]] = cir.load{{.*}} %[[ARR]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>
317 // CIR: %[[ELE_1:.*]] = cir.ptr_stride %[[TMP_3]], %[[IDX_1]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>
318 // CIR: %[[TMP_4:.*]] = cir.load{{.*}} %[[ELE_1]] : !cir.ptr<!s32i>, !s32i
319 // CIR: cir.store{{.*}} %[[TMP_4]], %[[INIT_2]] : !s32i, !cir.ptr<!s32i>
320
321 // LLVM: define{{.*}} void @_Z5func8Pi(ptr %[[ARG:.*]]){{.*}}
322 // LLVM: %[[ARR:.*]] = alloca ptr, i64 1, align 8
323 // LLVM: %[[INIT:.*]] = alloca i32, i64 1, align 4
324 // LLVM: %[[INIT_2:.*]] = alloca i32, i64 1, align 4
325 // LLVM: store ptr %[[ARG]], ptr %[[ARR]], align 8
326 // LLVM: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
327 // LLVM: %[[ELE_0:.*]] = getelementptr i32, ptr %[[TMP_1]], i64 0
328 // LLVM: %[[TMP_2:.*]] = load i32, ptr %[[ELE_0]], align 4
329 // LLVM: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
330 // LLVM: %[[TMP_3:.*]] = load ptr, ptr %[[ARR]], align 8
331 // LLVM: %[[ELE_1:.*]] = getelementptr i32, ptr %[[TMP_3]], i64 1
332 // LLVM: %[[TMP_4:.*]] = load i32, ptr %[[ELE_1]], align 4
333 // LLVM: store i32 %[[TMP_4]], ptr %[[INIT_2]], align 4
334
335 // OGCG: %[[ARR:.*]] = alloca ptr, align 8
336 // OGCG: %[[INIT:.*]] = alloca i32, align 4
337 // OGCG: %[[INIT_2:.*]] = alloca i32, align 4
338 // OGCG: store ptr {{%.*}}, ptr %[[ARR]], align 8
339 // OGCG: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
340 // OGCG: %[[ELE_0:.*]] = getelementptr inbounds i32, ptr %[[TMP_1]], i64 0
341 // OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_0]], align 4
342 // OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
343 // OGCG: %[[TMP_3:.*]] = load ptr, ptr %[[ARR]], align 8
344 // OGCG: %[[ELE_1:.*]] = getelementptr inbounds i32, ptr %[[TMP_3]], i64 1
345 // OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_1]], align 4
346 // OGCG: store i32 %[[TMP_2]], ptr %[[INIT_2]], align 4
347
348 void func9(int arr[10][5]) {
349 int e = arr[1][2];
350 }
351
352 // CIR: cir.func{{.*}} @_Z5func9PA5_i(%[[ARG:.*]]: !cir.ptr<!cir.array<!s32i x 5>>
353 // CIR: %[[ARR:.*]] = cir.alloca !cir.ptr<!cir.array<!s32i x 5>>, !cir.ptr<!cir.ptr<!cir.array<!s32i x 5>>>, ["arr", init]
354 // CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]
355 // CIR: cir.store{{.*}} %[[ARG]], %[[ARR]] : !cir.ptr<!cir.array<!s32i x 5>>, !cir.ptr<!cir.ptr<!cir.array<!s32i x 5>>>
356 // CIR: %[[IDX:.*]] = cir.const #cir.int<2> : !s32i
357 // CIR: %[[IDX_1:.*]] = cir.const #cir.int<1> : !s32i
358 // CIR: %[[TMP_1:.*]] = cir.load{{.*}} %[[ARR]] : !cir.ptr<!cir.ptr<!cir.array<!s32i x 5>>>, !cir.ptr<!cir.array<!s32i x 5>>
359 // 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>>
360 // CIR: %[[ARR_1_2:.*]] = cir.get_element %[[ARR_1]][%[[IDX]] : !s32i] : !cir.ptr<!cir.array<!s32i x 5>> -> !cir.ptr<!s32i>
361 // CIR: %[[TMP_2:.*]] = cir.load{{.*}} %[[ARR_1_2]] : !cir.ptr<!s32i>, !s32i
362 // CIR: cir.store{{.*}} %[[TMP_2]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
363
364 // LLVM: define{{.*}} void @_Z5func9PA5_i(ptr %[[ARG:.*]]){{.*}}
365 // LLVM: %[[ARR:.*]] = alloca ptr, i64 1, align 8
366 // LLVM: %[[INIT:.*]] = alloca i32, i64 1, align 4
367 // LLVM: store ptr %[[ARG]], ptr %[[ARR]], align 8
368 // LLVM: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
369 // LLVM: %[[ARR_1:.*]] = getelementptr [5 x i32], ptr %[[TMP_1]], i64 1
370 // LLVM: %[[ARR_1_2:.*]] = getelementptr [5 x i32], ptr %[[ARR_1]], i32 0, i64 2
371 // LLVM: %[[TMP_2:.*]] = load i32, ptr %[[ARR_1_2]], align 4
372 // LLVM: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
373
374 // OGCG: %[[ARR:.*]] = alloca ptr, align 8
375 // OGCG: %[[INIT:.*]] = alloca i32, align 4
376 // OGCG: store ptr {{%.*}}, ptr %[[ARR]], align 8
377 // OGCG: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
378 // OGCG: %[[ARR_1:.*]] = getelementptr inbounds [5 x i32], ptr %[[TMP_1]], i64 1
379 // OGCG: %[[ARR_1_2:.*]] = getelementptr inbounds [5 x i32], ptr %[[ARR_1]], i64 0, i64 2
380 // OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ARR_1_2]], align 4
381 // OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
382
383 void func10(int *a) {
384 int e = a[5];
385 }
386
387 // CIR: cir.func{{.*}} @_Z6func10Pi(%[[ARG:.*]]: !cir.ptr<!s32i>
388 // CIR: %[[ARR:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["a", init]
389 // CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]
390 // CIR: cir.store{{.*}} %[[ARG]], %[[ARR]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
391 // CIR: %[[IDX:.*]] = cir.const #cir.int<5> : !s32i
392 // CIR: %[[TMP_1:.*]] = cir.load{{.*}} %[[ARR]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>
393 // CIR: %[[ELE:.*]] = cir.ptr_stride %[[TMP_1]], %[[IDX]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>
394 // CIR: %[[TMP_2:.*]] = cir.load{{.*}} %[[ELE]] : !cir.ptr<!s32i>, !s32i
395 // CIR: cir.store{{.*}} %[[TMP_2]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
396
397 // LLVM: define{{.*}} void @_Z6func10Pi(ptr %[[ARG:.*]]){{.*}} {
398 // LLVM: %[[ARR:.*]] = alloca ptr, i64 1, align 8
399 // LLVM: %[[INIT:.*]] = alloca i32, i64 1, align 4
400 // LLVM: store ptr %[[ARG]], ptr %[[ARR]], align 8
401 // LLVM: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
402 // LLVM: %[[ELE:.*]] = getelementptr i32, ptr %[[TMP_1]], i64 5
403 // LLVM: %[[TMP_2:.*]] = load i32, ptr %[[ELE]], align 4
404 // LLVM: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
405
406 // OGCG: %[[ARR:.*]] = alloca ptr, align 8
407 // OGCG: %[[INIT:.*]] = alloca i32, align 4
408 // OGCG: store ptr {{%.*}}, ptr %[[ARR]], align 8
409 // OGCG: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
410 // OGCG: %[[ELE:.*]] = getelementptr inbounds i32, ptr %[[TMP_1]], i64 5
411 // OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE]], align 4
412 // OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
413
414 void func11() { int _Complex a[4]; }
415
416 // CIR: %[[ARR:.*]] = cir.alloca !cir.array<!cir.complex<!s32i> x 4>, !cir.ptr<!cir.array<!cir.complex<!s32i> x 4>>, ["a"]
417
418 // LLVM: %[[ARR:.*]] = alloca [4 x { i32, i32 }], i64 1, align 16
419
420 // OGCG: %[[ARR:.*]] = alloca [4 x { i32, i32 }], align 16
421
422 void func12() {
423 struct Point {
424 int x;
425 int y;
426 };
427
428 Point a[4];
429 }
430
431 // CIR: %[[ARR:.*]] = cir.alloca !cir.array<!rec_Point x 4>, !cir.ptr<!cir.array<!rec_Point x 4>>, ["a"]
432
433 // LLVM: %[[ARR:.*]] = alloca [4 x %struct.Point], i64 1, align 16
434
435 // OGCG: %[[ARR:.*]] = alloca [4 x %struct.Point], align 16
436
437 void array_with_complex_elements() {
438 _Complex float arr[2] = {{1.1f, 2.2f}, {3.3f, 4.4f}};
439 }
440
441 // 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]
442 // 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>
443 // CIR: cir.store{{.*}} %[[CONST]], %[[ARR_ADDR]] : !cir.array<!cir.complex<!cir.float> x 2>, !cir.ptr<!cir.array<!cir.complex<!cir.float> x 2>>
444
445 // LLVM: %[[ARR_ADDR:.*]] = alloca [2 x { float, float }], i64 1, align 16
446 // LLVM: store [2 x { float, float }] [{ float, float } { float 0x3FF19999A0000000, float 0x40019999A0000000 }, { float, float } { float 0x400A666660000000, float 0x40119999A0000000 }], ptr %[[ARR_ADDR]], align 16
447
448 // OGCG: %[[ARR_ADDR:.*]] = alloca [2 x { float, float }], align 16
449 // 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)