rtti-layout.cpp revision 8d1451535524cb21a6f8347bad9fed371b9d9ecb
1// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s 2#include <typeinfo> 3 4class __pbase_type_info : public std::type_info { 5public: 6 unsigned int __flags; 7 const std::type_info *__pointee; 8 9 enum __masks { 10 __const_mask = 0x1, 11 __volatile_mask = 0x2, 12 __restrict_mask = 0x4, 13 __incomplete_mask = 0x8, 14 __incomplete_class_mask = 0x10 15 }; 16}; 17 18template<typename T> const T& to(const std::type_info &info) { 19return static_cast<const T&>(info); 20} 21struct Incomplete; 22 23#define CHECK(x) if ((x)) return __LINE__; 24 25// CHECK: define i32 @_Z1fv() 26int f() { 27 // Pointers to incomplete classes. 28 CHECK(to<__pbase_type_info>(typeid(Incomplete *)).__flags != __pbase_type_info::__incomplete_mask); 29 CHECK(to<__pbase_type_info>(typeid(Incomplete **)).__flags != __pbase_type_info::__incomplete_mask); 30 CHECK(to<__pbase_type_info>(typeid(Incomplete ***)).__flags != __pbase_type_info::__incomplete_mask); 31 32 // Member pointers. 33 CHECK(to<__pbase_type_info>(typeid(int Incomplete::*)).__flags != __pbase_type_info::__incomplete_class_mask); 34 35 // Success! 36 // CHECK: ret i32 0 37 return 0; 38} 39 40#ifdef HARNESS 41extern "C" void printf(const char *, ...); 42 43int main() { 44 int result = f(); 45 46 if (result == 0) 47 printf("success!\n"); 48 else 49 printf("test on line %d failed!\n", result); 50 51 return result; 52} 53#endif 54 55 56