1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s
3 // C++-specific tests for __builtin_object_size
7 // CHECK-LABEL: define void @_Z5test1v()
9 // Guaranteeing that our cast removal logic doesn't break more interesting
13 struct C: public A, public B {};
18 gi = __builtin_object_size(&c, 0);
20 gi = __builtin_object_size((A*)&c, 0);
22 gi = __builtin_object_size((B*)&c, 0);
25 gi = __builtin_object_size((char*)&c, 0);
27 gi = __builtin_object_size((char*)(A*)&c, 0);
29 gi = __builtin_object_size((char*)(B*)&c, 0);
32 // CHECK-LABEL: define void @_Z5test2v()
34 struct A { char buf[16]; };
36 struct C { int i; B bs[1]; } *c;
38 // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
39 gi = __builtin_object_size(&c->bs[0], 0);
40 // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
41 gi = __builtin_object_size(&c->bs[0], 1);
42 // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 true)
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.p0i8(i8* %{{.*}}, 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)
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.p0i8(i8* %{{.*}}, 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)
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);