Debian Codegraph @

clang/test/CIR/CodeGen/object-size.c

raw
1 // RUN: %clang_cc1 -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 -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 -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 char gbuf[63];
9 char *gp;
10 int gi, gj;
11
12 // CIR-LABEL: @test1
13 // LLVM-LABEL: define {{.*}} void @test1
14 // OGCG-LABEL: define {{.*}} void @test1
15 void test1(void) {
16 // CIR: cir.const #cir.int<59>
17 // LLVM: store i32 59
18 // OGCG: store i32 59
19 gi = __builtin_object_size(&gbuf[4], 1);
20 }
21
22 // CIR-LABEL: @test2
23 // LLVM-LABEL: define {{.*}} void @test2
24 // OGCG-LABEL: define {{.*}} void @test2
25 void test2(void) {
26 // CIR: cir.const #cir.int<63>
27 // LLVM: store i32 63
28 // OGCG: store i32 63
29 gi = __builtin_object_size(gbuf, 1);
30 }
31
32 // CIR-LABEL: @test3
33 // LLVM-LABEL: define {{.*}} void @test3
34 // OGCG-LABEL: define {{.*}} void @test3
35 void test3(void) {
36 // CIR: cir.const #cir.int<0>
37 // LLVM: store i32 0
38 // OGCG: store i32 0
39 gi = __builtin_object_size(&gbuf[100], 1);
40 }
41
42 // CIR-LABEL: @test4
43 // LLVM-LABEL: define {{.*}} void @test4
44 // OGCG-LABEL: define {{.*}} void @test4
45 void test4(void) {
46 // CIR: cir.const #cir.int<0>
47 // LLVM: store i32 0
48 // OGCG: store i32 0
49 gi = __builtin_object_size((char*)(void*)&gbuf[-1], 1);
50 }
51
52 // CIR-LABEL: @test5
53 // LLVM-LABEL: define {{.*}} void @test5
54 // OGCG-LABEL: define {{.*}} void @test5
55 void test5(void) {
56 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
57 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
58 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
59 gi = __builtin_object_size(gp, 0);
60 }
61
62 // CIR-LABEL: @test6
63 // LLVM-LABEL: define {{.*}} void @test6
64 // OGCG-LABEL: define {{.*}} void @test6
65 void test6(void) {
66 char buf[57];
67
68 // CIR: cir.const #cir.int<53>
69 // LLVM: store i32 53
70 // OGCG: store i32 53
71 gi = __builtin_object_size(&buf[4], 1);
72 }
73
74 // CIR-LABEL: @test18
75 // LLVM-LABEL: define {{.*}} i32 @test18
76 // OGCG-LABEL: define {{.*}} i32 @test18
77 unsigned test18(int cond) {
78 int a[4], b[4];
79 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
80 // LLVM: call i64 @llvm.objectsize.i64
81 // OGCG: call i64 @llvm.objectsize.i64
82 return __builtin_object_size(cond ? a : b, 0);
83 }
84
85 // CIR-LABEL: @test19
86 // LLVM-LABEL: define {{.*}} void @test19
87 // OGCG-LABEL: define {{.*}} void @test19
88 void test19(void) {
89 struct {
90 int a, b;
91 } foo;
92
93 // CIR: cir.const #cir.int<8>
94 // LLVM: store i32 8
95 // OGCG: store i32 8
96 gi = __builtin_object_size(&foo.a, 0);
97
98 // CIR: cir.const #cir.int<4>
99 // LLVM: store i32 4
100 // OGCG: store i32 4
101 gi = __builtin_object_size(&foo.a, 1);
102
103 // CIR: cir.const #cir.int<8>
104 // LLVM: store i32 8
105 // OGCG: store i32 8
106 gi = __builtin_object_size(&foo.a, 2);
107
108 // CIR: cir.const #cir.int<4>
109 // LLVM: store i32 4
110 // OGCG: store i32 4
111 gi = __builtin_object_size(&foo.a, 3);
112
113 // CIR: cir.const #cir.int<4>
114 // LLVM: store i32 4
115 // OGCG: store i32 4
116 gi = __builtin_object_size(&foo.b, 0);
117
118 // CIR: cir.const #cir.int<4>
119 // LLVM: store i32 4
120 // OGCG: store i32 4
121 gi = __builtin_object_size(&foo.b, 1);
122
123 // CIR: cir.const #cir.int<4>
124 // LLVM: store i32 4
125 // OGCG: store i32 4
126 gi = __builtin_object_size(&foo.b, 2);
127
128 // CIR: cir.const #cir.int<4>
129 // LLVM: store i32 4
130 // OGCG: store i32 4
131 gi = __builtin_object_size(&foo.b, 3);
132 }
133
134 // CIR-LABEL: @test20
135 // LLVM-LABEL: define {{.*}} void @test20
136 // OGCG-LABEL: define {{.*}} void @test20
137 void test20(void) {
138 struct { int t[10]; } t[10];
139
140 // CIR: cir.const #cir.int<380>
141 // LLVM: store i32 380
142 // OGCG: store i32 380
143 gi = __builtin_object_size(&t[0].t[5], 0);
144
145 // CIR: cir.const #cir.int<20>
146 // LLVM: store i32 20
147 // OGCG: store i32 20
148 gi = __builtin_object_size(&t[0].t[5], 1);
149
150 // CIR: cir.const #cir.int<380>
151 // LLVM: store i32 380
152 // OGCG: store i32 380
153 gi = __builtin_object_size(&t[0].t[5], 2);
154
155 // CIR: cir.const #cir.int<20>
156 // LLVM: store i32 20
157 // OGCG: store i32 20
158 gi = __builtin_object_size(&t[0].t[5], 3);
159 }
160
161 // CIR-LABEL: @test21
162 // LLVM-LABEL: define {{.*}} void @test21
163 // OGCG-LABEL: define {{.*}} void @test21
164 void test21(void) {
165 struct { int t; } t;
166
167 // CIR: cir.const #cir.int<0>
168 // LLVM: store i32 0
169 // OGCG: store i32 0
170 gi = __builtin_object_size(&t + 1, 0);
171
172 // CIR: cir.const #cir.int<0>
173 // LLVM: store i32 0
174 // OGCG: store i32 0
175 gi = __builtin_object_size(&t + 1, 1);
176
177 // CIR: cir.const #cir.int<0>
178 // LLVM: store i32 0
179 // OGCG: store i32 0
180 gi = __builtin_object_size(&t + 1, 2);
181
182 // CIR: cir.const #cir.int<0>
183 // LLVM: store i32 0
184 // OGCG: store i32 0
185 gi = __builtin_object_size(&t + 1, 3);
186
187 // CIR: cir.const #cir.int<0>
188 // LLVM: store i32 0
189 // OGCG: store i32 0
190 gi = __builtin_object_size(&t.t + 1, 0);
191
192 // CIR: cir.const #cir.int<0>
193 // LLVM: store i32 0
194 // OGCG: store i32 0
195 gi = __builtin_object_size(&t.t + 1, 1);
196
197 // CIR: cir.const #cir.int<0>
198 // LLVM: store i32 0
199 // OGCG: store i32 0
200 gi = __builtin_object_size(&t.t + 1, 2);
201
202 // CIR: cir.const #cir.int<0>
203 // LLVM: store i32 0
204 // OGCG: store i32 0
205 gi = __builtin_object_size(&t.t + 1, 3);
206 }
207
208 // CIR-LABEL: @test22
209 // LLVM-LABEL: define {{.*}} void @test22
210 // OGCG-LABEL: define {{.*}} void @test22
211 void test22(void) {
212 struct { int t[10]; } t[10];
213
214 // CIR: cir.const #cir.int<0>
215 // LLVM: store i32 0
216 // OGCG: store i32 0
217 gi = __builtin_object_size(&t[10], 0);
218
219 // CIR: cir.const #cir.int<0>
220 // LLVM: store i32 0
221 // OGCG: store i32 0
222 gi = __builtin_object_size(&t[10], 1);
223
224 // CIR: cir.const #cir.int<0>
225 // LLVM: store i32 0
226 // OGCG: store i32 0
227 gi = __builtin_object_size(&t[10], 2);
228
229 // CIR: cir.const #cir.int<0>
230 // LLVM: store i32 0
231 // OGCG: store i32 0
232 gi = __builtin_object_size(&t[10], 3);
233
234 // CIR: cir.const #cir.int<0>
235 // LLVM: store i32 0
236 // OGCG: store i32 0
237 gi = __builtin_object_size(&t[9].t[10], 0);
238
239 // CIR: cir.const #cir.int<0>
240 // LLVM: store i32 0
241 // OGCG: store i32 0
242 gi = __builtin_object_size(&t[9].t[10], 1);
243
244 // CIR: cir.const #cir.int<0>
245 // LLVM: store i32 0
246 // OGCG: store i32 0
247 gi = __builtin_object_size(&t[9].t[10], 2);
248
249 // CIR: cir.const #cir.int<0>
250 // LLVM: store i32 0
251 // OGCG: store i32 0
252 gi = __builtin_object_size(&t[9].t[10], 3);
253
254 // CIR: cir.const #cir.int<0>
255 // LLVM: store i32 0
256 // OGCG: store i32 0
257 gi = __builtin_object_size((char*)&t[0] + sizeof(t), 0);
258
259 // CIR: cir.const #cir.int<0>
260 // LLVM: store i32 0
261 // OGCG: store i32 0
262 gi = __builtin_object_size((char*)&t[0] + sizeof(t), 1);
263
264 // CIR: cir.const #cir.int<0>
265 // LLVM: store i32 0
266 // OGCG: store i32 0
267 gi = __builtin_object_size((char*)&t[0] + sizeof(t), 2);
268
269 // CIR: cir.const #cir.int<0>
270 // LLVM: store i32 0
271 // OGCG: store i32 0
272 gi = __builtin_object_size((char*)&t[0] + sizeof(t), 3);
273
274 // CIR: cir.const #cir.int<0>
275 // LLVM: store i32 0
276 // OGCG: store i32 0
277 gi = __builtin_object_size((char*)&t[9].t[0] + 10*sizeof(t[0].t), 0);
278
279 // CIR: cir.const #cir.int<0>
280 // LLVM: store i32 0
281 // OGCG: store i32 0
282 gi = __builtin_object_size((char*)&t[9].t[0] + 10*sizeof(t[0].t), 1);
283
284 // CIR: cir.const #cir.int<0>
285 // LLVM: store i32 0
286 // OGCG: store i32 0
287 gi = __builtin_object_size((char*)&t[9].t[0] + 10*sizeof(t[0].t), 2);
288
289 // CIR: cir.const #cir.int<0>
290 // LLVM: store i32 0
291 // OGCG: store i32 0
292 gi = __builtin_object_size((char*)&t[9].t[0] + 10*sizeof(t[0].t), 3);
293 }
294
295 struct Test23Ty { int a; int t[10]; };
296
297 // CIR-LABEL: @test23
298 // LLVM-LABEL: define {{.*}} void @test23
299 // OGCG-LABEL: define {{.*}} void @test23
300 void test23(struct Test23Ty *p) {
301 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
302 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
303 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
304 gi = __builtin_object_size(p, 0);
305
306 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
307 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
308 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
309 gi = __builtin_object_size(p, 1);
310
311 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
312 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
313 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
314 gi = __builtin_object_size(p, 2);
315
316 // CIR: cir.const #cir.int<0>
317 // LLVM: store i32 0
318 // OGCG: store i32 0
319 gi = __builtin_object_size(p, 3);
320
321 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
322 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
323 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
324 gi = __builtin_object_size(&p->a, 0);
325
326 // CIR: cir.const #cir.int<4>
327 // LLVM: store i32 4
328 // OGCG: store i32 4
329 gi = __builtin_object_size(&p->a, 1);
330
331 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
332 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
333 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
334 gi = __builtin_object_size(&p->a, 2);
335
336 // CIR: cir.const #cir.int<4>
337 // LLVM: store i32 4
338 // OGCG: store i32 4
339 gi = __builtin_object_size(&p->a, 3);
340
341 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
342 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
343 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
344 gi = __builtin_object_size(&p->t[5], 0);
345
346 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
347 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
348 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
349 gi = __builtin_object_size(&p->t[5], 1);
350
351 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
352 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
353 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
354 gi = __builtin_object_size(&p->t[5], 2);
355
356 // CIR: cir.const #cir.int<20>
357 // LLVM: store i32 20
358 // OGCG: store i32 20
359 gi = __builtin_object_size(&p->t[5], 3);
360 }
361
362 // CIR-LABEL: @test24
363 // LLVM-LABEL: define {{.*}} void @test24
364 // OGCG-LABEL: define {{.*}} void @test24
365 void test24(void) {
366 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
367 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
368 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
369 gi = __builtin_object_size((void*)0, 0);
370
371 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
372 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
373 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
374 gi = __builtin_object_size((void*)0, 1);
375
376 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
377 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1
378 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1
379 gi = __builtin_object_size((void*)0, 2);
380
381 // CIR: cir.const #cir.int<0>
382 // LLVM: store i32 0
383 // OGCG: store i32 0
384 gi = __builtin_object_size((void*)0, 3);
385 }
386
387 // CIR-LABEL: @test25
388 // LLVM-LABEL: define {{.*}} void @test25
389 // OGCG-LABEL: define {{.*}} void @test25
390 void test25(void) {
391 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
392 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
393 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
394 gi = __builtin_object_size((void*)0x1000, 0);
395
396 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
397 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
398 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
399 gi = __builtin_object_size((void*)0x1000, 1);
400
401 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
402 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1
403 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1
404 gi = __builtin_object_size((void*)0x1000, 2);
405
406 // CIR: cir.const #cir.int<0>
407 // LLVM: store i32 0
408 // OGCG: store i32 0
409 gi = __builtin_object_size((void*)0x1000, 3);
410
411 // Skipping (void*)0 + 0x1000 tests - void pointer arithmetic NYI in CIR
412 }
413
414 // CIR-LABEL: @test26
415 // LLVM-LABEL: define {{.*}} void @test26
416 // OGCG-LABEL: define {{.*}} void @test26
417 void test26(void) {
418 struct { int v[10]; } t[10];
419
420 // CIR: cir.const #cir.int<316>
421 // LLVM: store i32 316
422 // OGCG: store i32 316
423 gi = __builtin_object_size(&t[1].v[11], 0);
424
425 // CIR: cir.const #cir.int<312>
426 // LLVM: store i32 312
427 // OGCG: store i32 312
428 gi = __builtin_object_size(&t[1].v[12], 1);
429
430 // CIR: cir.const #cir.int<308>
431 // LLVM: store i32 308
432 // OGCG: store i32 308
433 gi = __builtin_object_size(&t[1].v[13], 2);
434
435 // CIR: cir.const #cir.int<0>
436 // LLVM: store i32 0
437 // OGCG: store i32 0
438 gi = __builtin_object_size(&t[1].v[14], 3);
439 }
440
441 struct Test27IncompleteTy;
442
443 // CIR-LABEL: @test27
444 // LLVM-LABEL: define {{.*}} void @test27
445 // OGCG-LABEL: define {{.*}} void @test27
446 void test27(struct Test27IncompleteTy *t) {
447 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
448 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
449 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
450 gi = __builtin_object_size(t, 0);
451
452 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
453 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
454 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
455 gi = __builtin_object_size(t, 1);
456
457 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
458 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
459 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
460 gi = __builtin_object_size(t, 2);
461
462 // CIR: cir.const #cir.int<0>
463 // LLVM: store i32 0
464 // OGCG: store i32 0
465 gi = __builtin_object_size(t, 3);
466
467 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
468 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
469 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
470 gi = __builtin_object_size(&test27, 0);
471
472 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
473 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
474 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1
475 gi = __builtin_object_size(&test27, 1);
476
477 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
478 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1
479 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1
480 gi = __builtin_object_size(&test27, 2);
481
482 // CIR: cir.const #cir.int<0>
483 // LLVM: store i32 0
484 // OGCG: store i32 0
485 gi = __builtin_object_size(&test27, 3);
486 }
487
488 // CIR-LABEL: @test28
489 // LLVM-LABEL: define {{.*}} void @test28
490 // OGCG-LABEL: define {{.*}} void @test28
491 void test28(void) {
492 struct { int v[10]; } t[10];
493
494 // CIR: cir.const #cir.int<360>
495 // LLVM: store i32 360
496 // OGCG: store i32 360
497 gi = __builtin_object_size((char*)((short*)(&t[1])), 0);
498
499 // CIR: cir.const #cir.int<360>
500 // LLVM: store i32 360
501 // OGCG: store i32 360
502 gi = __builtin_object_size((char*)((short*)(&t[1])), 1);
503
504 // CIR: cir.const #cir.int<360>
505 // LLVM: store i32 360
506 // OGCG: store i32 360
507 gi = __builtin_object_size((char*)((short*)(&t[1])), 2);
508
509 // CIR: cir.const #cir.int<360>
510 // LLVM: store i32 360
511 // OGCG: store i32 360
512 gi = __builtin_object_size((char*)((short*)(&t[1])), 3);
513
514 // CIR: cir.const #cir.int<356>
515 // LLVM: store i32 356
516 // OGCG: store i32 356
517 gi = __builtin_object_size((char*)((short*)(&t[1].v[1])), 0);
518
519 // CIR: cir.const #cir.int<36>
520 // LLVM: store i32 36
521 // OGCG: store i32 36
522 gi = __builtin_object_size((char*)((short*)(&t[1].v[1])), 1);
523
524 // CIR: cir.const #cir.int<356>
525 // LLVM: store i32 356
526 // OGCG: store i32 356
527 gi = __builtin_object_size((char*)((short*)(&t[1].v[1])), 2);
528
529 // CIR: cir.const #cir.int<36>
530 // LLVM: store i32 36
531 // OGCG: store i32 36
532 gi = __builtin_object_size((char*)((short*)(&t[1].v[1])), 3);
533 }
534
535 struct DynStructVar {
536 char fst[16];
537 char snd[];
538 };
539
540 struct DynStruct0 {
541 char fst[16];
542 char snd[0];
543 };
544
545 struct DynStruct1 {
546 char fst[16];
547 char snd[1];
548 };
549
550 struct StaticStruct {
551 char fst[16];
552 char snd[2];
553 };
554
555 // CIR-LABEL: @test29
556 // LLVM-LABEL: define {{.*}} void @test29
557 // OGCG-LABEL: define {{.*}} void @test29
558 void test29(struct DynStructVar *dv, struct DynStruct0 *d0,
559 struct DynStruct1 *d1, struct StaticStruct *ss) {
560 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
561 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
562 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
563 gi = __builtin_object_size(dv->snd, 0);
564
565 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
566 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
567 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
568 gi = __builtin_object_size(dv->snd, 1);
569
570 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
571 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
572 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
573 gi = __builtin_object_size(dv->snd, 2);
574
575 // CIR: cir.const #cir.int<0>
576 // LLVM: store i32 0
577 // OGCG: store i32 0
578 gi = __builtin_object_size(dv->snd, 3);
579
580 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
581 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
582 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
583 gi = __builtin_object_size(d0->snd, 0);
584
585 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
586 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
587 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
588 gi = __builtin_object_size(d0->snd, 1);
589
590 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
591 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
592 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
593 gi = __builtin_object_size(d0->snd, 2);
594
595 // CIR: cir.const #cir.int<0>
596 // LLVM: store i32 0
597 // OGCG: store i32 0
598 gi = __builtin_object_size(d0->snd, 3);
599
600 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
601 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
602 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
603 gi = __builtin_object_size(d1->snd, 0);
604
605 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
606 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
607 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
608 gi = __builtin_object_size(d1->snd, 1);
609
610 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
611 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
612 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
613 gi = __builtin_object_size(d1->snd, 2);
614
615 // CIR: cir.const #cir.int<1>
616 // LLVM: store i32 1
617 // OGCG: store i32 1
618 gi = __builtin_object_size(d1->snd, 3);
619
620 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
621 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
622 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
623 gi = __builtin_object_size(ss->snd, 0);
624
625 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
626 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
627 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
628 gi = __builtin_object_size(ss->snd, 1);
629
630 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
631 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
632 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
633 gi = __builtin_object_size(ss->snd, 2);
634
635 // CIR: cir.const #cir.int<2>
636 // LLVM: store i32 2
637 // OGCG: store i32 2
638 gi = __builtin_object_size(ss->snd, 3);
639 }
640
641 // CIR-LABEL: @test30
642 // LLVM-LABEL: define {{.*}} void @test30
643 // OGCG-LABEL: define {{.*}} void @test30
644 void test30(void) {
645 struct { struct DynStruct1 fst, snd; } *nested;
646
647 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
648 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
649 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
650 gi = __builtin_object_size(nested->fst.snd, 0);
651
652 // CIR: cir.const #cir.int<1>
653 // LLVM: store i32 1
654 // OGCG: store i32 1
655 gi = __builtin_object_size(nested->fst.snd, 1);
656
657 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
658 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
659 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
660 gi = __builtin_object_size(nested->fst.snd, 2);
661
662 // CIR: cir.const #cir.int<1>
663 // LLVM: store i32 1
664 // OGCG: store i32 1
665 gi = __builtin_object_size(nested->fst.snd, 3);
666
667 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
668 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
669 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
670 gi = __builtin_object_size(nested->snd.snd, 0);
671
672 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
673 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
674 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
675 gi = __builtin_object_size(nested->snd.snd, 1);
676
677 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
678 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
679 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
680 gi = __builtin_object_size(nested->snd.snd, 2);
681
682 // CIR: cir.const #cir.int<1>
683 // LLVM: store i32 1
684 // OGCG: store i32 1
685 gi = __builtin_object_size(nested->snd.snd, 3);
686
687 union { struct DynStruct1 d1; char c[1]; } *u;
688
689 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
690 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
691 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
692 gi = __builtin_object_size(u->c, 0);
693
694 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
695 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
696 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
697 gi = __builtin_object_size(u->c, 1);
698
699 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
700 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
701 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
702 gi = __builtin_object_size(u->c, 2);
703
704 // CIR: cir.const #cir.int<1>
705 // LLVM: store i32 1
706 // OGCG: store i32 1
707 gi = __builtin_object_size(u->c, 3);
708
709 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
710 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
711 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
712 gi = __builtin_object_size(u->d1.snd, 0);
713
714 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
715 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
716 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
717 gi = __builtin_object_size(u->d1.snd, 1);
718
719 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
720 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
721 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
722 gi = __builtin_object_size(u->d1.snd, 2);
723
724 // CIR: cir.const #cir.int<1>
725 // LLVM: store i32 1
726 // OGCG: store i32 1
727 gi = __builtin_object_size(u->d1.snd, 3);
728 }
729
730 // CIR-LABEL: @test32
731 // LLVM-LABEL: define {{.*}} i64 @test32
732 // OGCG-LABEL: define {{.*}} i64 @test32
733 static struct DynStructVar D32 = {
734 .fst = {},
735 .snd = { 0, 1, 2, },
736 };
737 unsigned long test32(void) {
738 // CIR: cir.const #cir.int<19>
739 // LLVM: store i64 19
740 // OGCG: ret i64 19
741 return __builtin_object_size(&D32, 1);
742 }
743
744 // CIR-LABEL: @test33
745 // LLVM-LABEL: define {{.*}} i64 @test33
746 // OGCG-LABEL: define {{.*}} i64 @test33
747 static struct DynStructVar D33 = {
748 .fst = {},
749 .snd = {},
750 };
751 unsigned long test33(void) {
752 // CIR: cir.const #cir.int<16>
753 // LLVM: store i64 16
754 // OGCG: ret i64 16
755 return __builtin_object_size(&D33, 1);
756 }
757
758 // CIR-LABEL: @test34
759 // LLVM-LABEL: define {{.*}} i64 @test34
760 // OGCG-LABEL: define {{.*}} i64 @test34
761 static struct DynStructVar D34 = {
762 .fst = {},
763 };
764 unsigned long test34(void) {
765 // CIR: cir.const #cir.int<16>
766 // LLVM: store i64 16
767 // OGCG: ret i64 16
768 return __builtin_object_size(&D34, 1);
769 }
770
771 // CIR-LABEL: @test35
772 // LLVM-LABEL: define {{.*}} i64 @test35
773 // OGCG-LABEL: define {{.*}} i64 @test35
774 unsigned long test35(void) {
775 // CIR: cir.const #cir.int<16>
776 // LLVM: store i64 16
777 // OGCG: ret i64 16
778 return __builtin_object_size(&(struct DynStructVar){}, 1);
779 }
780
781 // CIR-LABEL: @test37
782 // LLVM-LABEL: define {{.*}} i64 @test37
783 // OGCG-LABEL: define {{.*}} i64 @test37
784 struct Z { struct A { int x, y[]; } z; int a; int b[]; };
785 static struct Z my_z = { .b = {1,2,3} };
786 unsigned long test37(void) {
787 // CIR: cir.const #cir.int<4>
788 // LLVM: store i64 4
789 // OGCG: ret i64 4
790 return __builtin_object_size(&my_z.z, 1);
791 }
792
793 // CIR-LABEL: @PR30346
794 // LLVM-LABEL: define {{.*}} void @PR30346
795 // OGCG-LABEL: define {{.*}} void @PR30346
796 void PR30346(void) {
797 struct sa_family_t {};
798 struct sockaddr {
799 struct sa_family_t sa_family;
800 char sa_data[14];
801 };
802
803 struct sockaddr *sa;
804
805 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
806 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
807 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
808 gi = __builtin_object_size(sa->sa_data, 0);
809
810 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
811 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
812 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1
813 gi = __builtin_object_size(sa->sa_data, 1);
814
815 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
816 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
817 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1
818 gi = __builtin_object_size(sa->sa_data, 2);
819
820 // CIR: cir.const #cir.int<14>
821 // LLVM: store i32 14
822 // OGCG: store i32 14
823 gi = __builtin_object_size(sa->sa_data, 3);
824 }
825
826 extern char incomplete_char_array[];
827
828 // CIR-LABEL: @incomplete_and_function_types
829 // LLVM-LABEL: define {{.*}} void @incomplete_and_function_types
830 // OGCG-LABEL: define {{.*}} void @incomplete_and_function_types
831 void incomplete_and_function_types(void) {
832 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
833 // LLVM: call i64 @llvm.objectsize.i64.p0
834 // OGCG: call i64 @llvm.objectsize.i64.p0
835 gi = __builtin_object_size(incomplete_char_array, 0);
836
837 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
838 // LLVM: call i64 @llvm.objectsize.i64.p0
839 // OGCG: call i64 @llvm.objectsize.i64.p0
840 gi = __builtin_object_size(incomplete_char_array, 1);
841
842 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i
843 // LLVM: call i64 @llvm.objectsize.i64.p0
844 // OGCG: call i64 @llvm.objectsize.i64.p0
845 gi = __builtin_object_size(incomplete_char_array, 2);
846
847 // CIR: cir.const #cir.int<0>
848 // LLVM: store i32 0
849 // OGCG: store i32 0
850 gi = __builtin_object_size(incomplete_char_array, 3);
851 }
852
853 // CIR-LABEL: @deeply_nested
854 // LLVM-LABEL: define {{.*}} void @deeply_nested
855 // OGCG-LABEL: define {{.*}} void @deeply_nested
856 void deeply_nested(void) {
857 struct {
858 struct {
859 struct {
860 struct {
861 int e[2];
862 char f;
863 } d[2];
864 } c[2];
865 } b[2];
866 } *a;
867
868 // CIR: cir.const #cir.int<4>
869 // LLVM: store i32 4
870 // OGCG: store i32 4
871 gi = __builtin_object_size(&a->b[1].c[1].d[1].e[1], 1);
872
873 // CIR: cir.const #cir.int<4>
874 // LLVM: store i32 4
875 // OGCG: store i32 4
876 gi = __builtin_object_size(&a->b[1].c[1].d[1].e[1], 3);
877 }