Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / object-size.cpp
blobe6ae3aefac2f8500eb64a04c3a763936d20508d1
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s
3 // C++-specific tests for __builtin_object_size
5 int gi;
7 // CHECK-LABEL: define{{.*}} void @_Z5test1v()
8 void test1() {
9 // Guaranteeing that our cast removal logic doesn't break more interesting
10 // cases.
11 struct A { int a; };
12 struct B { int b; };
13 struct C: public A, public B {};
15 C c;
17 // CHECK: store i32 8
18 gi = __builtin_object_size(&c, 0);
19 // CHECK: store i32 8
20 gi = __builtin_object_size((A*)&c, 0);
21 // CHECK: store i32 4
22 gi = __builtin_object_size((B*)&c, 0);
24 // CHECK: store i32 8
25 gi = __builtin_object_size((char*)&c, 0);
26 // CHECK: store i32 8
27 gi = __builtin_object_size((char*)(A*)&c, 0);
28 // CHECK: store i32 4
29 gi = __builtin_object_size((char*)(B*)&c, 0);
32 // CHECK-LABEL: define{{.*}} void @_Z5test2v()
33 void test2() {
34 struct A { char buf[16]; };
35 struct B : A {};
36 struct C { int i; B bs[1]; } *c;
38 // CHECK: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1 false)
39 gi = __builtin_object_size(&c->bs[0], 0);
40 // CHECK: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1 false)
41 gi = __builtin_object_size(&c->bs[0], 1);
42 // CHECK: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1 false)
43 gi = __builtin_object_size(&c->bs[0], 2);
44 // CHECK: store i32 16
45 gi = __builtin_object_size(&c->bs[0], 3);
47 // CHECK: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1 false)
48 gi = __builtin_object_size((A*)&c->bs[0], 0);
49 // CHECK: store i32 16
50 gi = __builtin_object_size((A*)&c->bs[0], 1);
51 // CHECK: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1 false)
52 gi = __builtin_object_size((A*)&c->bs[0], 2);
53 // CHECK: store i32 16
54 gi = __builtin_object_size((A*)&c->bs[0], 3);
56 // CHECK: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 false, i1 true, i1 false)
57 gi = __builtin_object_size(&c->bs[0].buf[0], 0);
58 // CHECK: store i32 16
59 gi = __builtin_object_size(&c->bs[0].buf[0], 1);
60 // CHECK: call i64 @llvm.objectsize.i64.p0(ptr %{{.*}}, i1 true, i1 true, i1 false)
61 gi = __builtin_object_size(&c->bs[0].buf[0], 2);
62 // CHECK: store i32 16
63 gi = __builtin_object_size(&c->bs[0].buf[0], 3);