Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 -emit-llvm -O1 -o - -triple=i386-pc-win32 %s | FileCheck %s
      2 
      3 struct type_info;
      4 namespace std { using ::type_info; }
      5 
      6 struct V { virtual void f(); };
      7 struct A : virtual V { A(); };
      8 
      9 extern A a;
     10 extern V v;
     11 extern int b;
     12 A* fn();
     13 
     14 const std::type_info* test0_typeid() { return &typeid(int); }
     15 // CHECK-LABEL: define %struct.type_info* @"\01?test0_typeid@@YAPBUtype_info@@XZ"()
     16 // CHECK:   ret %struct.type_info* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to %struct.type_info*)
     17 
     18 const std::type_info* test1_typeid() { return &typeid(A); }
     19 // CHECK-LABEL: define %struct.type_info* @"\01?test1_typeid@@YAPBUtype_info@@XZ"()
     20 // CHECK:   ret %struct.type_info* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUA@@@8" to %struct.type_info*)
     21 
     22 const std::type_info* test2_typeid() { return &typeid(&a); }
     23 // CHECK-LABEL: define %struct.type_info* @"\01?test2_typeid@@YAPBUtype_info@@XZ"()
     24 // CHECK:   ret %struct.type_info* bitcast (%rtti.TypeDescriptor7* @"\01??_R0PAUA@@@8" to %struct.type_info*)
     25 
     26 const std::type_info* test3_typeid() { return &typeid(*fn()); }
     27 // CHECK-LABEL: define %struct.type_info* @"\01?test3_typeid@@YAPBUtype_info@@XZ"()
     28 // CHECK:        [[CALL:%.*]] = tail call %struct.A* @"\01?fn@@YAPAUA@@XZ"()
     29 // CHECK-NEXT:   [[CMP:%.*]] = icmp eq %struct.A* [[CALL]], null
     30 // CHECK-NEXT:   br i1 [[CMP]]
     31 // CHECK:        tail call i8* @__RTtypeid(i8* null)
     32 // CHECK-NEXT:   unreachable
     33 // CHECK:        [[THIS:%.*]] = bitcast %struct.A* [[CALL]] to i8*
     34 // CHECK-NEXT:   [[VBTBLP:%.*]] = bitcast %struct.A* [[CALL]] to i8**
     35 // CHECK-NEXT:   [[VBTBL:%.*]] = load i8** [[VBTBLP]], align 4
     36 // CHECK-NEXT:   [[VBSLOT:%.*]] = getelementptr inbounds i8* [[VBTBL]], i32 4
     37 // CHECK-NEXT:   [[VBITCST:%.*]] = bitcast i8* [[VBSLOT]] to i32*
     38 // CHECK-NEXT:   [[VBASE_OFFS:%.*]] = load i32* [[VBITCST]], align 4
     39 // CHECK-NEXT:   [[ADJ:%.*]] = getelementptr inbounds i8* [[THIS]], i32 [[VBASE_OFFS]]
     40 // CHECK-NEXT:   [[RT:%.*]] = tail call i8* @__RTtypeid(i8* [[ADJ]])
     41 // CHECK-NEXT:   [[RET:%.*]] = bitcast i8* [[RT]] to %struct.type_info*
     42 // CHECK-NEXT:   ret %struct.type_info* [[RET]]
     43 
     44 const std::type_info* test4_typeid() { return &typeid(b); }
     45 // CHECK: define %struct.type_info* @"\01?test4_typeid@@YAPBUtype_info@@XZ"()
     46 // CHECK:   ret %struct.type_info* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to %struct.type_info*)
     47 
     48 const std::type_info* test5_typeid() { return &typeid(v); }
     49 // CHECK: define %struct.type_info* @"\01?test5_typeid@@YAPBUtype_info@@XZ"()
     50 // CHECK:        [[RT:%.*]] = tail call i8* @__RTtypeid(i8* bitcast (%struct.V* @"\01?v@@3UV@@A" to i8*))
     51 // CHECK-NEXT:   [[RET:%.*]] = bitcast i8* [[RT]] to %struct.type_info*
     52 // CHECK-NEXT:   ret %struct.type_info* [[RET]]
     53