878 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG7 8char gbuf[63];9char *gp;10int gi, gj;11 12// CIR-LABEL: @test113// LLVM-LABEL: define {{.*}} void @test114// OGCG-LABEL: define {{.*}} void @test115void test1(void) {16 // CIR: cir.const #cir.int<59>17 // LLVM: store i32 5918 // OGCG: store i32 5919 gi = __builtin_object_size(&gbuf[4], 1);20}21 22// CIR-LABEL: @test223// LLVM-LABEL: define {{.*}} void @test224// OGCG-LABEL: define {{.*}} void @test225void test2(void) {26 // CIR: cir.const #cir.int<63>27 // LLVM: store i32 6328 // OGCG: store i32 6329 gi = __builtin_object_size(gbuf, 1);30}31 32// CIR-LABEL: @test333// LLVM-LABEL: define {{.*}} void @test334// OGCG-LABEL: define {{.*}} void @test335void test3(void) {36 // CIR: cir.const #cir.int<0>37 // LLVM: store i32 038 // OGCG: store i32 039 gi = __builtin_object_size(&gbuf[100], 1);40}41 42// CIR-LABEL: @test443// LLVM-LABEL: define {{.*}} void @test444// OGCG-LABEL: define {{.*}} void @test445void test4(void) {46 // CIR: cir.const #cir.int<0>47 // LLVM: store i32 048 // OGCG: store i32 049 gi = __builtin_object_size((char*)(void*)&gbuf[-1], 1);50}51 52// CIR-LABEL: @test553// LLVM-LABEL: define {{.*}} void @test554// OGCG-LABEL: define {{.*}} void @test555void test5(void) {56 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i57 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i158 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i159 gi = __builtin_object_size(gp, 0);60}61 62// CIR-LABEL: @test663// LLVM-LABEL: define {{.*}} void @test664// OGCG-LABEL: define {{.*}} void @test665void test6(void) {66 char buf[57];67 68 // CIR: cir.const #cir.int<53>69 // LLVM: store i32 5370 // OGCG: store i32 5371 gi = __builtin_object_size(&buf[4], 1);72}73 74// CIR-LABEL: @test1875// LLVM-LABEL: define {{.*}} i32 @test1876// OGCG-LABEL: define {{.*}} i32 @test1877unsigned test18(int cond) {78 int a[4], b[4];79 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i80 // LLVM: call i64 @llvm.objectsize.i6481 // OGCG: call i64 @llvm.objectsize.i6482 return __builtin_object_size(cond ? a : b, 0);83}84 85// CIR-LABEL: @test1986// LLVM-LABEL: define {{.*}} void @test1987// OGCG-LABEL: define {{.*}} void @test1988void test19(void) {89 struct {90 int a, b;91 } foo;92 93 // CIR: cir.const #cir.int<8>94 // LLVM: store i32 895 // OGCG: store i32 896 gi = __builtin_object_size(&foo.a, 0);97 98 // CIR: cir.const #cir.int<4>99 // LLVM: store i32 4100 // OGCG: store i32 4101 gi = __builtin_object_size(&foo.a, 1);102 103 // CIR: cir.const #cir.int<8>104 // LLVM: store i32 8105 // OGCG: store i32 8106 gi = __builtin_object_size(&foo.a, 2);107 108 // CIR: cir.const #cir.int<4>109 // LLVM: store i32 4110 // OGCG: store i32 4111 gi = __builtin_object_size(&foo.a, 3);112 113 // CIR: cir.const #cir.int<4>114 // LLVM: store i32 4115 // OGCG: store i32 4116 gi = __builtin_object_size(&foo.b, 0);117 118 // CIR: cir.const #cir.int<4>119 // LLVM: store i32 4120 // OGCG: store i32 4121 gi = __builtin_object_size(&foo.b, 1);122 123 // CIR: cir.const #cir.int<4>124 // LLVM: store i32 4125 // OGCG: store i32 4126 gi = __builtin_object_size(&foo.b, 2);127 128 // CIR: cir.const #cir.int<4>129 // LLVM: store i32 4130 // OGCG: store i32 4131 gi = __builtin_object_size(&foo.b, 3);132}133 134// CIR-LABEL: @test20135// LLVM-LABEL: define {{.*}} void @test20136// OGCG-LABEL: define {{.*}} void @test20137void test20(void) {138 struct { int t[10]; } t[10];139 140 // CIR: cir.const #cir.int<380>141 // LLVM: store i32 380142 // OGCG: store i32 380143 gi = __builtin_object_size(&t[0].t[5], 0);144 145 // CIR: cir.const #cir.int<20>146 // LLVM: store i32 20147 // OGCG: store i32 20148 gi = __builtin_object_size(&t[0].t[5], 1);149 150 // CIR: cir.const #cir.int<380>151 // LLVM: store i32 380152 // OGCG: store i32 380153 gi = __builtin_object_size(&t[0].t[5], 2);154 155 // CIR: cir.const #cir.int<20>156 // LLVM: store i32 20157 // OGCG: store i32 20158 gi = __builtin_object_size(&t[0].t[5], 3);159}160 161// CIR-LABEL: @test21162// LLVM-LABEL: define {{.*}} void @test21163// OGCG-LABEL: define {{.*}} void @test21164void test21(void) {165 struct { int t; } t;166 167 // CIR: cir.const #cir.int<0>168 // LLVM: store i32 0169 // OGCG: store i32 0170 gi = __builtin_object_size(&t + 1, 0);171 172 // CIR: cir.const #cir.int<0>173 // LLVM: store i32 0174 // OGCG: store i32 0175 gi = __builtin_object_size(&t + 1, 1);176 177 // CIR: cir.const #cir.int<0>178 // LLVM: store i32 0179 // OGCG: store i32 0180 gi = __builtin_object_size(&t + 1, 2);181 182 // CIR: cir.const #cir.int<0>183 // LLVM: store i32 0184 // OGCG: store i32 0185 gi = __builtin_object_size(&t + 1, 3);186 187 // CIR: cir.const #cir.int<0>188 // LLVM: store i32 0189 // OGCG: store i32 0190 gi = __builtin_object_size(&t.t + 1, 0);191 192 // CIR: cir.const #cir.int<0>193 // LLVM: store i32 0194 // OGCG: store i32 0195 gi = __builtin_object_size(&t.t + 1, 1);196 197 // CIR: cir.const #cir.int<0>198 // LLVM: store i32 0199 // OGCG: store i32 0200 gi = __builtin_object_size(&t.t + 1, 2);201 202 // CIR: cir.const #cir.int<0>203 // LLVM: store i32 0204 // OGCG: store i32 0205 gi = __builtin_object_size(&t.t + 1, 3);206}207 208// CIR-LABEL: @test22209// LLVM-LABEL: define {{.*}} void @test22210// OGCG-LABEL: define {{.*}} void @test22211void test22(void) {212 struct { int t[10]; } t[10];213 214 // CIR: cir.const #cir.int<0>215 // LLVM: store i32 0216 // OGCG: store i32 0217 gi = __builtin_object_size(&t[10], 0);218 219 // CIR: cir.const #cir.int<0>220 // LLVM: store i32 0221 // OGCG: store i32 0222 gi = __builtin_object_size(&t[10], 1);223 224 // CIR: cir.const #cir.int<0>225 // LLVM: store i32 0226 // OGCG: store i32 0227 gi = __builtin_object_size(&t[10], 2);228 229 // CIR: cir.const #cir.int<0>230 // LLVM: store i32 0231 // OGCG: store i32 0232 gi = __builtin_object_size(&t[10], 3);233 234 // CIR: cir.const #cir.int<0>235 // LLVM: store i32 0236 // OGCG: store i32 0237 gi = __builtin_object_size(&t[9].t[10], 0);238 239 // CIR: cir.const #cir.int<0>240 // LLVM: store i32 0241 // OGCG: store i32 0242 gi = __builtin_object_size(&t[9].t[10], 1);243 244 // CIR: cir.const #cir.int<0>245 // LLVM: store i32 0246 // OGCG: store i32 0247 gi = __builtin_object_size(&t[9].t[10], 2);248 249 // CIR: cir.const #cir.int<0>250 // LLVM: store i32 0251 // OGCG: store i32 0252 gi = __builtin_object_size(&t[9].t[10], 3);253 254 // CIR: cir.const #cir.int<0>255 // LLVM: store i32 0256 // OGCG: store i32 0257 gi = __builtin_object_size((char*)&t[0] + sizeof(t), 0);258 259 // CIR: cir.const #cir.int<0>260 // LLVM: store i32 0261 // OGCG: store i32 0262 gi = __builtin_object_size((char*)&t[0] + sizeof(t), 1);263 264 // CIR: cir.const #cir.int<0>265 // LLVM: store i32 0266 // OGCG: store i32 0267 gi = __builtin_object_size((char*)&t[0] + sizeof(t), 2);268 269 // CIR: cir.const #cir.int<0>270 // LLVM: store i32 0271 // OGCG: store i32 0272 gi = __builtin_object_size((char*)&t[0] + sizeof(t), 3);273 274 // CIR: cir.const #cir.int<0>275 // LLVM: store i32 0276 // OGCG: store i32 0277 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 0281 // OGCG: store i32 0282 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 0286 // OGCG: store i32 0287 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 0291 // OGCG: store i32 0292 gi = __builtin_object_size((char*)&t[9].t[0] + 10*sizeof(t[0].t), 3);293}294 295struct Test23Ty { int a; int t[10]; };296 297// CIR-LABEL: @test23298// LLVM-LABEL: define {{.*}} void @test23299// OGCG-LABEL: define {{.*}} void @test23300void test23(struct Test23Ty *p) {301 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i302 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1303 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1304 gi = __builtin_object_size(p, 0);305 306 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i307 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1308 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1309 gi = __builtin_object_size(p, 1);310 311 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i312 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1313 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1314 gi = __builtin_object_size(p, 2);315 316 // CIR: cir.const #cir.int<0>317 // LLVM: store i32 0318 // OGCG: store i32 0319 gi = __builtin_object_size(p, 3);320 321 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i322 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1323 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1324 gi = __builtin_object_size(&p->a, 0);325 326 // CIR: cir.const #cir.int<4>327 // LLVM: store i32 4328 // OGCG: store i32 4329 gi = __builtin_object_size(&p->a, 1);330 331 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i332 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1333 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1334 gi = __builtin_object_size(&p->a, 2);335 336 // CIR: cir.const #cir.int<4>337 // LLVM: store i32 4338 // OGCG: store i32 4339 gi = __builtin_object_size(&p->a, 3);340 341 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i342 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1343 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1344 gi = __builtin_object_size(&p->t[5], 0);345 346 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i347 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1348 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1349 gi = __builtin_object_size(&p->t[5], 1);350 351 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i352 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1353 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1354 gi = __builtin_object_size(&p->t[5], 2);355 356 // CIR: cir.const #cir.int<20>357 // LLVM: store i32 20358 // OGCG: store i32 20359 gi = __builtin_object_size(&p->t[5], 3);360}361 362// CIR-LABEL: @test24363// LLVM-LABEL: define {{.*}} void @test24364// OGCG-LABEL: define {{.*}} void @test24365void test24(void) {366 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i367 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1368 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1369 gi = __builtin_object_size((void*)0, 0);370 371 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i372 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1373 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1374 gi = __builtin_object_size((void*)0, 1);375 376 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i377 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1378 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1379 gi = __builtin_object_size((void*)0, 2);380 381 // CIR: cir.const #cir.int<0>382 // LLVM: store i32 0383 // OGCG: store i32 0384 gi = __builtin_object_size((void*)0, 3);385}386 387// CIR-LABEL: @test25388// LLVM-LABEL: define {{.*}} void @test25389// OGCG-LABEL: define {{.*}} void @test25390void test25(void) {391 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i392 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1393 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1394 gi = __builtin_object_size((void*)0x1000, 0);395 396 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i397 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1398 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1399 gi = __builtin_object_size((void*)0x1000, 1);400 401 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i402 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1403 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1404 gi = __builtin_object_size((void*)0x1000, 2);405 406 // CIR: cir.const #cir.int<0>407 // LLVM: store i32 0408 // OGCG: store i32 0409 gi = __builtin_object_size((void*)0x1000, 3);410 411 // Skipping (void*)0 + 0x1000 tests - void pointer arithmetic NYI in CIR412}413 414// CIR-LABEL: @test26415// LLVM-LABEL: define {{.*}} void @test26416// OGCG-LABEL: define {{.*}} void @test26417void test26(void) {418 struct { int v[10]; } t[10];419 420 // CIR: cir.const #cir.int<316>421 // LLVM: store i32 316422 // OGCG: store i32 316423 gi = __builtin_object_size(&t[1].v[11], 0);424 425 // CIR: cir.const #cir.int<312>426 // LLVM: store i32 312427 // OGCG: store i32 312428 gi = __builtin_object_size(&t[1].v[12], 1);429 430 // CIR: cir.const #cir.int<308>431 // LLVM: store i32 308432 // OGCG: store i32 308433 gi = __builtin_object_size(&t[1].v[13], 2);434 435 // CIR: cir.const #cir.int<0>436 // LLVM: store i32 0437 // OGCG: store i32 0438 gi = __builtin_object_size(&t[1].v[14], 3);439}440 441struct Test27IncompleteTy;442 443// CIR-LABEL: @test27444// LLVM-LABEL: define {{.*}} void @test27445// OGCG-LABEL: define {{.*}} void @test27446void test27(struct Test27IncompleteTy *t) {447 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i448 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1449 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1450 gi = __builtin_object_size(t, 0);451 452 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i453 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1454 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1455 gi = __builtin_object_size(t, 1);456 457 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i458 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1459 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1460 gi = __builtin_object_size(t, 2);461 462 // CIR: cir.const #cir.int<0>463 // LLVM: store i32 0464 // OGCG: store i32 0465 gi = __builtin_object_size(t, 3);466 467 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i468 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1469 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1470 gi = __builtin_object_size(&test27, 0);471 472 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i473 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1474 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1475 gi = __builtin_object_size(&test27, 1);476 477 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i478 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1479 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr {{.*}}, i1 true, i1 true, i1480 gi = __builtin_object_size(&test27, 2);481 482 // CIR: cir.const #cir.int<0>483 // LLVM: store i32 0484 // OGCG: store i32 0485 gi = __builtin_object_size(&test27, 3);486}487 488// CIR-LABEL: @test28489// LLVM-LABEL: define {{.*}} void @test28490// OGCG-LABEL: define {{.*}} void @test28491void test28(void) {492 struct { int v[10]; } t[10];493 494 // CIR: cir.const #cir.int<360>495 // LLVM: store i32 360496 // OGCG: store i32 360497 gi = __builtin_object_size((char*)((short*)(&t[1])), 0);498 499 // CIR: cir.const #cir.int<360>500 // LLVM: store i32 360501 // OGCG: store i32 360502 gi = __builtin_object_size((char*)((short*)(&t[1])), 1);503 504 // CIR: cir.const #cir.int<360>505 // LLVM: store i32 360506 // OGCG: store i32 360507 gi = __builtin_object_size((char*)((short*)(&t[1])), 2);508 509 // CIR: cir.const #cir.int<360>510 // LLVM: store i32 360511 // OGCG: store i32 360512 gi = __builtin_object_size((char*)((short*)(&t[1])), 3);513 514 // CIR: cir.const #cir.int<356>515 // LLVM: store i32 356516 // OGCG: store i32 356517 gi = __builtin_object_size((char*)((short*)(&t[1].v[1])), 0);518 519 // CIR: cir.const #cir.int<36>520 // LLVM: store i32 36521 // OGCG: store i32 36522 gi = __builtin_object_size((char*)((short*)(&t[1].v[1])), 1);523 524 // CIR: cir.const #cir.int<356>525 // LLVM: store i32 356526 // OGCG: store i32 356527 gi = __builtin_object_size((char*)((short*)(&t[1].v[1])), 2);528 529 // CIR: cir.const #cir.int<36>530 // LLVM: store i32 36531 // OGCG: store i32 36532 gi = __builtin_object_size((char*)((short*)(&t[1].v[1])), 3);533}534 535struct DynStructVar {536 char fst[16];537 char snd[];538};539 540struct DynStruct0 {541 char fst[16];542 char snd[0];543};544 545struct DynStruct1 {546 char fst[16];547 char snd[1];548};549 550struct StaticStruct {551 char fst[16];552 char snd[2];553};554 555// CIR-LABEL: @test29556// LLVM-LABEL: define {{.*}} void @test29557// OGCG-LABEL: define {{.*}} void @test29558void test29(struct DynStructVar *dv, struct DynStruct0 *d0,559 struct DynStruct1 *d1, struct StaticStruct *ss) {560 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i561 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1562 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1563 gi = __builtin_object_size(dv->snd, 0);564 565 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i566 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1567 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1568 gi = __builtin_object_size(dv->snd, 1);569 570 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i571 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1572 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1573 gi = __builtin_object_size(dv->snd, 2);574 575 // CIR: cir.const #cir.int<0>576 // LLVM: store i32 0577 // OGCG: store i32 0578 gi = __builtin_object_size(dv->snd, 3);579 580 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i581 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1582 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1583 gi = __builtin_object_size(d0->snd, 0);584 585 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i586 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1587 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1588 gi = __builtin_object_size(d0->snd, 1);589 590 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i591 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1592 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1593 gi = __builtin_object_size(d0->snd, 2);594 595 // CIR: cir.const #cir.int<0>596 // LLVM: store i32 0597 // OGCG: store i32 0598 gi = __builtin_object_size(d0->snd, 3);599 600 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i601 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1602 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1603 gi = __builtin_object_size(d1->snd, 0);604 605 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i606 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1607 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1608 gi = __builtin_object_size(d1->snd, 1);609 610 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i611 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1612 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1613 gi = __builtin_object_size(d1->snd, 2);614 615 // CIR: cir.const #cir.int<1>616 // LLVM: store i32 1617 // OGCG: store i32 1618 gi = __builtin_object_size(d1->snd, 3);619 620 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i621 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1622 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1623 gi = __builtin_object_size(ss->snd, 0);624 625 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i626 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1627 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1628 gi = __builtin_object_size(ss->snd, 1);629 630 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i631 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1632 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1633 gi = __builtin_object_size(ss->snd, 2);634 635 // CIR: cir.const #cir.int<2>636 // LLVM: store i32 2637 // OGCG: store i32 2638 gi = __builtin_object_size(ss->snd, 3);639}640 641// CIR-LABEL: @test30642// LLVM-LABEL: define {{.*}} void @test30643// OGCG-LABEL: define {{.*}} void @test30644void test30(void) {645 struct { struct DynStruct1 fst, snd; } *nested;646 647 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i648 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1649 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1650 gi = __builtin_object_size(nested->fst.snd, 0);651 652 // CIR: cir.const #cir.int<1>653 // LLVM: store i32 1654 // OGCG: store i32 1655 gi = __builtin_object_size(nested->fst.snd, 1);656 657 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i658 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1659 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1660 gi = __builtin_object_size(nested->fst.snd, 2);661 662 // CIR: cir.const #cir.int<1>663 // LLVM: store i32 1664 // OGCG: store i32 1665 gi = __builtin_object_size(nested->fst.snd, 3);666 667 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i668 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1669 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1670 gi = __builtin_object_size(nested->snd.snd, 0);671 672 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i673 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1674 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1675 gi = __builtin_object_size(nested->snd.snd, 1);676 677 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i678 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1679 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1680 gi = __builtin_object_size(nested->snd.snd, 2);681 682 // CIR: cir.const #cir.int<1>683 // LLVM: store i32 1684 // OGCG: store i32 1685 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> -> !u64i690 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1691 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1692 gi = __builtin_object_size(u->c, 0);693 694 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i695 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1696 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1697 gi = __builtin_object_size(u->c, 1);698 699 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i700 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1701 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1702 gi = __builtin_object_size(u->c, 2);703 704 // CIR: cir.const #cir.int<1>705 // LLVM: store i32 1706 // OGCG: store i32 1707 gi = __builtin_object_size(u->c, 3);708 709 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i710 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1711 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1712 gi = __builtin_object_size(u->d1.snd, 0);713 714 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i715 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1716 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1717 gi = __builtin_object_size(u->d1.snd, 1);718 719 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i720 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1721 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1722 gi = __builtin_object_size(u->d1.snd, 2);723 724 // CIR: cir.const #cir.int<1>725 // LLVM: store i32 1726 // OGCG: store i32 1727 gi = __builtin_object_size(u->d1.snd, 3);728}729 730// CIR-LABEL: @test32731// LLVM-LABEL: define {{.*}} i64 @test32732// OGCG-LABEL: define {{.*}} i64 @test32733static struct DynStructVar D32 = {734 .fst = {},735 .snd = { 0, 1, 2, },736};737unsigned long test32(void) {738 // CIR: cir.const #cir.int<19>739 // LLVM: store i64 19740 // OGCG: ret i64 19741 return __builtin_object_size(&D32, 1);742}743 744// CIR-LABEL: @test33745// LLVM-LABEL: define {{.*}} i64 @test33746// OGCG-LABEL: define {{.*}} i64 @test33747static struct DynStructVar D33 = {748 .fst = {},749 .snd = {},750};751unsigned long test33(void) {752 // CIR: cir.const #cir.int<16>753 // LLVM: store i64 16754 // OGCG: ret i64 16755 return __builtin_object_size(&D33, 1);756}757 758// CIR-LABEL: @test34759// LLVM-LABEL: define {{.*}} i64 @test34760// OGCG-LABEL: define {{.*}} i64 @test34761static struct DynStructVar D34 = {762 .fst = {},763};764unsigned long test34(void) {765 // CIR: cir.const #cir.int<16>766 // LLVM: store i64 16767 // OGCG: ret i64 16768 return __builtin_object_size(&D34, 1);769}770 771// CIR-LABEL: @test35772// LLVM-LABEL: define {{.*}} i64 @test35773// OGCG-LABEL: define {{.*}} i64 @test35774unsigned long test35(void) {775 // CIR: cir.const #cir.int<16>776 // LLVM: store i64 16777 // OGCG: ret i64 16778 return __builtin_object_size(&(struct DynStructVar){}, 1);779}780 781// CIR-LABEL: @test37782// LLVM-LABEL: define {{.*}} i64 @test37783// OGCG-LABEL: define {{.*}} i64 @test37784struct Z { struct A { int x, y[]; } z; int a; int b[]; };785static struct Z my_z = { .b = {1,2,3} };786unsigned long test37(void) {787 // CIR: cir.const #cir.int<4>788 // LLVM: store i64 4789 // OGCG: ret i64 4790 return __builtin_object_size(&my_z.z, 1);791}792 793// CIR-LABEL: @PR30346794// LLVM-LABEL: define {{.*}} void @PR30346795// OGCG-LABEL: define {{.*}} void @PR30346796void 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> -> !u64i806 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1807 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1808 gi = __builtin_object_size(sa->sa_data, 0);809 810 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i811 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1812 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1813 gi = __builtin_object_size(sa->sa_data, 1);814 815 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i816 // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1817 // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1818 gi = __builtin_object_size(sa->sa_data, 2);819 820 // CIR: cir.const #cir.int<14>821 // LLVM: store i32 14822 // OGCG: store i32 14823 gi = __builtin_object_size(sa->sa_data, 3);824}825 826extern char incomplete_char_array[];827 828// CIR-LABEL: @incomplete_and_function_types829// LLVM-LABEL: define {{.*}} void @incomplete_and_function_types830// OGCG-LABEL: define {{.*}} void @incomplete_and_function_types831void incomplete_and_function_types(void) {832 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i833 // LLVM: call i64 @llvm.objectsize.i64.p0834 // OGCG: call i64 @llvm.objectsize.i64.p0835 gi = __builtin_object_size(incomplete_char_array, 0);836 837 // CIR: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i838 // LLVM: call i64 @llvm.objectsize.i64.p0839 // OGCG: call i64 @llvm.objectsize.i64.p0840 gi = __builtin_object_size(incomplete_char_array, 1);841 842 // CIR: cir.objsize min nullunknown {{.*}} : !cir.ptr<!void> -> !u64i843 // LLVM: call i64 @llvm.objectsize.i64.p0844 // OGCG: call i64 @llvm.objectsize.i64.p0845 gi = __builtin_object_size(incomplete_char_array, 2);846 847 // CIR: cir.const #cir.int<0>848 // LLVM: store i32 0849 // OGCG: store i32 0850 gi = __builtin_object_size(incomplete_char_array, 3);851}852 853// CIR-LABEL: @deeply_nested854// LLVM-LABEL: define {{.*}} void @deeply_nested855// OGCG-LABEL: define {{.*}} void @deeply_nested856void 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 4870 // OGCG: store i32 4871 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 4875 // OGCG: store i32 4876 gi = __builtin_object_size(&a->b[1].c[1].d[1].e[1], 3);877}878