• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
test0_typeid()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 
test1_typeid()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 
test2_typeid()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 
test3_typeid()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:%.*]] = getelementptr inbounds %struct.A, %struct.A* [[CALL]], i32 0, i32 0
35 // CHECK-NEXT:   [[VBTBL:%.*]] = load i32*, i32** [[VBTBLP]], align 4
36 // CHECK-NEXT:   [[VBSLOT:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1
37 // CHECK-NEXT:   [[VBASE_OFFS:%.*]] = load i32, i32* [[VBSLOT]], align 4
38 // CHECK-NEXT:   [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[THIS]], i32 [[VBASE_OFFS]]
39 // CHECK-NEXT:   [[RT:%.*]] = tail call i8* @__RTtypeid(i8* [[ADJ]])
40 // CHECK-NEXT:   [[RET:%.*]] = bitcast i8* [[RT]] to %struct.type_info*
41 // CHECK-NEXT:   ret %struct.type_info* [[RET]]
42 
test4_typeid()43 const std::type_info* test4_typeid() { return &typeid(b); }
44 // CHECK: define %struct.type_info* @"\01?test4_typeid@@YAPBUtype_info@@XZ"()
45 // CHECK:   ret %struct.type_info* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to %struct.type_info*)
46 
test5_typeid()47 const std::type_info* test5_typeid() { return &typeid(v); }
48 // CHECK: define %struct.type_info* @"\01?test5_typeid@@YAPBUtype_info@@XZ"()
49 // CHECK:        [[RT:%.*]] = tail call i8* @__RTtypeid(i8* bitcast (%struct.V* @"\01?v@@3UV@@A" to i8*))
50 // CHECK-NEXT:   [[RET:%.*]] = bitcast i8* [[RT]] to %struct.type_info*
51 // CHECK-NEXT:   ret %struct.type_info* [[RET]]
52