blob: e3b5456f4d4a4619726dddabda50990294440542 [file] [log] [blame]
Anders Carlssone8820a82009-12-17 04:57:25 +00001// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s
Anders Carlsson0a4f1862009-12-17 04:41:05 +00002#include <typeinfo>
3
Anders Carlssonf64531a2009-12-30 01:00:12 +00004// vtables.
5extern "C" {
6 const void *_ZTVN10__cxxabiv123__fundamental_type_infoE;
7 const void *_ZTVN10__cxxabiv117__class_type_infoE;
8 const void *_ZTVN10__cxxabiv120__si_class_type_infoE;
9 const void *_ZTVN10__cxxabiv119__pointer_type_infoE;
10 const void *_ZTVN10__cxxabiv129__pointer_to_member_type_infoE;
11};
12#define fundamental_type_info_vtable _ZTVN10__cxxabiv123__fundamental_type_infoE
13#define class_type_info_vtable _ZTVN10__cxxabiv117__class_type_infoE
14#define si_class_type_info_vtable _ZTVN10__cxxabiv120__si_class_type_infoE
15#define pointer_type_info_vtable _ZTVN10__cxxabiv119__pointer_type_infoE
16#define pointer_to_member_type_info_vtable _ZTVN10__cxxabiv129__pointer_to_member_type_infoE
17
Anders Carlsson0a4f1862009-12-17 04:41:05 +000018class __pbase_type_info : public std::type_info {
19public:
20 unsigned int __flags;
21 const std::type_info *__pointee;
22
23 enum __masks {
24 __const_mask = 0x1,
25 __volatile_mask = 0x2,
26 __restrict_mask = 0x4,
27 __incomplete_mask = 0x8,
28 __incomplete_class_mask = 0x10
29 };
30};
31
32template<typename T> const T& to(const std::type_info &info) {
33return static_cast<const T&>(info);
34}
35struct Incomplete;
36
Anders Carlsson17fa6f92009-12-20 23:37:55 +000037struct A { };
38
Anders Carlssonf64531a2009-12-30 01:00:12 +000039#define CHECK(x) if (!(x)) return __LINE__
40#define CHECK_VTABLE(type, vtable) if (&vtable##_type_info_vtable + 2 != (((void **)&(typeid(type)))[0])) return __LINE__
Anders Carlsson8d145152009-12-20 22:30:54 +000041
Anders Carlsson0a4f1862009-12-17 04:41:05 +000042// CHECK: define i32 @_Z1fv()
43int f() {
Anders Carlssonf64531a2009-12-30 01:00:12 +000044 // Vectors should be treated as fundamental types.
45 typedef short __v4hi __attribute__ ((__vector_size__ (8)));
46 CHECK_VTABLE(__v4hi, fundamental);
47
Anders Carlsson8d145152009-12-20 22:30:54 +000048 // Pointers to incomplete classes.
Anders Carlssonf64531a2009-12-30 01:00:12 +000049 CHECK_VTABLE(Incomplete *, pointer);
Anders Carlsson17fa6f92009-12-20 23:37:55 +000050 CHECK(to<__pbase_type_info>(typeid(Incomplete *)).__flags == __pbase_type_info::__incomplete_mask);
51 CHECK(to<__pbase_type_info>(typeid(Incomplete **)).__flags == __pbase_type_info::__incomplete_mask);
52 CHECK(to<__pbase_type_info>(typeid(Incomplete ***)).__flags == __pbase_type_info::__incomplete_mask);
Anders Carlsson8d145152009-12-20 22:30:54 +000053
54 // Member pointers.
Anders Carlssonf64531a2009-12-30 01:00:12 +000055 CHECK_VTABLE(int Incomplete::*, pointer_to_member);
Anders Carlsson17fa6f92009-12-20 23:37:55 +000056 CHECK(to<__pbase_type_info>(typeid(int Incomplete::*)).__flags == __pbase_type_info::__incomplete_class_mask);
57 CHECK(to<__pbase_type_info>(typeid(Incomplete Incomplete::*)).__flags == (__pbase_type_info::__incomplete_class_mask | __pbase_type_info::__incomplete_mask));
58 CHECK(to<__pbase_type_info>(typeid(Incomplete A::*)).__flags == (__pbase_type_info::__incomplete_mask));
Anders Carlsson8d145152009-12-20 22:30:54 +000059
Anders Carlsson0a4f1862009-12-17 04:41:05 +000060 // Success!
Anders Carlsson8d145152009-12-20 22:30:54 +000061 // CHECK: ret i32 0
Anders Carlsson0a4f1862009-12-17 04:41:05 +000062 return 0;
63}
64
65#ifdef HARNESS
66extern "C" void printf(const char *, ...);
67
68int main() {
69 int result = f();
70
71 if (result == 0)
72 printf("success!\n");
73 else
Anders Carlsson8d145152009-12-20 22:30:54 +000074 printf("test on line %d failed!\n", result);
Anders Carlsson0a4f1862009-12-17 04:41:05 +000075
76 return result;
77}
78#endif
79
80