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 int b;
11 A* fn();
12 
13 const std::type_info* test0_typeid() { return &typeid(int); }
14 // CHECK-LABEL: define %struct.type_info* @"\01?test0_typeid@@YAPBUtype_info@@XZ"()
15 // CHECK:   ret %struct.type_info* bitcast (%"MSRTTITypeDescriptor\02"* @"\01??_R0H@8" to %struct.type_info*)
16 
17 const std::type_info* test1_typeid() { return &typeid(A); }
18 // CHECK-LABEL: define %struct.type_info* @"\01?test1_typeid@@YAPBUtype_info@@XZ"()
19 // CHECK:   ret %struct.type_info* bitcast (%"MSRTTITypeDescriptor\07"* @"\01??_R0?AUA@@@8" to %struct.type_info*)
20 
21 const std::type_info* test2_typeid() { return &typeid(&a); }
22 // CHECK-LABEL: define %struct.type_info* @"\01?test2_typeid@@YAPBUtype_info@@XZ"()
23 // CHECK:   ret %struct.type_info* bitcast (%"MSRTTITypeDescriptor\07"* @"\01??_R0PAUA@@@8" to %struct.type_info*)
24 
25 const std::type_info* test3_typeid() { return &typeid(*fn()); }
26 // CHECK-LABEL: define %struct.type_info* @"\01?test3_typeid@@YAPBUtype_info@@XZ"()
27 // CHECK:        [[CALL:%.*]] = tail call %struct.A* @"\01?fn@@YAPAUA@@XZ"()
28 // CHECK-NEXT:   [[CMP:%.*]] = icmp eq %struct.A* [[CALL]], null
29 // CHECK-NEXT:   br i1 [[CMP]]
30 // CHECK:        tail call i8* @__RTtypeid(i8* null)
31 // CHECK-NEXT:   unreachable
32 // CHECK:        [[THIS:%.*]] = bitcast %struct.A* [[CALL]] to i8*
33 // CHECK-NEXT:   [[VBTBLP:%.*]] = bitcast %struct.A* [[CALL]] to i8**
34 // CHECK-NEXT:   [[VBTBL:%.*]] = load i8** [[VBTBLP]], align 4
35 // CHECK-NEXT:   [[VBSLOT:%.*]] = getelementptr inbounds i8* [[VBTBL]], i32 4
36 // CHECK-NEXT:   [[VBITCST:%.*]] = bitcast i8* [[VBSLOT]] to i32*
37 // CHECK-NEXT:   [[VBASE_OFFS:%.*]] = load i32* [[VBITCST]], align 4
38 // CHECK-NEXT:   [[ADJ:%.*]] = getelementptr inbounds 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 
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 (%"MSRTTITypeDescriptor\02"* @"\01??_R0H@8" to %struct.type_info*)
46