brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · b60e245 Raw
109 lines · cpp
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 8// C++-specific tests for __builtin_object_size9 10int gi;11 12// CIR-LABEL: @_Z5test1v13// LLVM-LABEL: define{{.*}} void @_Z5test1v()14// OGCG-LABEL: define{{.*}} void @_Z5test1v()15void test1() {16  // Guaranteeing that our cast removal logic doesn't break more interesting17  // cases.18  struct A { int a; };19  struct B { int b; };20  struct C: public A, public B {};21 22  C c;23 24  // CIR: cir.const #cir.int<8>25  // LLVM: store i32 826  // OGCG: store i32 827  gi = __builtin_object_size(&c, 0);28  // CIR: cir.const #cir.int<8>29  // LLVM: store i32 830  // OGCG: store i32 831  gi = __builtin_object_size((A*)&c, 0);32  // CIR: cir.const #cir.int<4>33  // LLVM: store i32 434  // OGCG: store i32 435  gi = __builtin_object_size((B*)&c, 0);36 37  // CIR: cir.const #cir.int<8>38  // LLVM: store i32 839  // OGCG: store i32 840  gi = __builtin_object_size((char*)&c, 0);41  // CIR: cir.const #cir.int<8>42  // LLVM: store i32 843  // OGCG: store i32 844  gi = __builtin_object_size((char*)(A*)&c, 0);45  // CIR: cir.const #cir.int<4>46  // LLVM: store i32 447  // OGCG: store i32 448  gi = __builtin_object_size((char*)(B*)&c, 0);49}50 51// CIR-LABEL: @_Z5test2v()52// LLVM-LABEL: define{{.*}} void @_Z5test2v()53// OGCG-LABEL: define{{.*}} void @_Z5test2v()54void test2() {55  struct A { char buf[16]; };56  struct B : A {};57  struct C { int i; B bs[1]; } *c;58 59  // CIR: cir.objsize max nullunknown %{{.+}} : !cir.ptr<!void> -> !u64i60  // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1 false)61  // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1 false)62  gi = __builtin_object_size(&c->bs[0], 0);63  // CIR: cir.objsize max nullunknown %{{.+}} : !cir.ptr<!void> -> !u64i64  // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1 false)65  // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1 false)66  gi = __builtin_object_size(&c->bs[0], 1);67  // CIR: cir.objsize min nullunknown %{{.+}} : !cir.ptr<!void> -> !u64i68  // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1 false)69  // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1 false)70  gi = __builtin_object_size(&c->bs[0], 2);71  // CIR: cir.const #cir.int<16>72  // LLVM: store i32 1673  // OGCG: store i32 1674  gi = __builtin_object_size(&c->bs[0], 3);75 76  // NYI: DerivedToBase cast77  // gi = __builtin_object_size((A*)&c->bs[0], 0);78 79  // CIR: cir.const #cir.int<16>80  // LLVM: store i32 1681  // OGCG: store i32 1682  gi = __builtin_object_size((A*)&c->bs[0], 1);83 84  // NYI: DerivedToBase cast 85  // gi = __builtin_object_size((A*)&c->bs[0], 2);86 87  // CIR: cir.const #cir.int<16>88  // LLVM: store i32 1689  // OGCG: store i32 1690  gi = __builtin_object_size((A*)&c->bs[0], 3);91 92  // CIR: cir.objsize max nullunknown %{{.+}} : !cir.ptr<!void> -> !u64i93  // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1 false)94  // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1 false)95  gi = __builtin_object_size(&c->bs[0].buf[0], 0);96  // CIR: cir.const #cir.int<16>97  // LLVM: store i32 1698  // OGCG: store i32 1699  gi = __builtin_object_size(&c->bs[0].buf[0], 1);100  // CIR: cir.objsize min nullunknown %{{.+}} : !cir.ptr<!void> -> !u64i101  // LLVM: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1 false)102  // OGCG: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1 false)103  gi = __builtin_object_size(&c->bs[0].buf[0], 2);104  // CIR: cir.const #cir.int<16>105  // LLVM: store i32 16106  // OGCG: store i32 16107  gi = __builtin_object_size(&c->bs[0].buf[0], 3);108}109