150
|
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s
|
|
2
|
|
3 // C++-specific tests for __builtin_object_size
|
|
4
|
|
5 int gi;
|
|
6
|
207
|
7 // CHECK-LABEL: define{{.*}} void @_Z5test1v()
|
150
|
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 {};
|
|
14
|
|
15 C c;
|
|
16
|
|
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);
|
|
23
|
|
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);
|
|
30 }
|
|
31
|
207
|
32 // CHECK-LABEL: define{{.*}} void @_Z5test2v()
|
150
|
33 void test2() {
|
|
34 struct A { char buf[16]; };
|
|
35 struct B : A {};
|
|
36 struct C { int i; B bs[1]; } *c;
|
|
37
|
|
38 // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false, i1 true, i1 false)
|
|
39 gi = __builtin_object_size(&c->bs[0], 0);
|
|
40 // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false, i1 true, i1 false)
|
|
41 gi = __builtin_object_size(&c->bs[0], 1);
|
|
42 // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, 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);
|
|
46
|
|
47 // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, 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.p0i8(i8* %{{.*}}, 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);
|
|
55
|
|
56 // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, 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.p0i8(i8* %{{.*}}, 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);
|
|
64 }
|