1 | // RUN: %clang_cc1 -emit-llvm -O1 -o - -triple=i386-pc-win32 %s -fexceptions -fcxx-exceptions | 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 dso_local %struct.type_info* @"?test0_typeid@@YAPBUtype_info@@XZ"() |
16 | // CHECK: ret %struct.type_info* bitcast (%rtti.TypeDescriptor2* @"??_R0H@8" to %struct.type_info*) |
17 | |
18 | const std::type_info* test1_typeid() { return &typeid(A); } |
19 | // CHECK-LABEL: define dso_local %struct.type_info* @"?test1_typeid@@YAPBUtype_info@@XZ"() |
20 | // CHECK: ret %struct.type_info* bitcast (%rtti.TypeDescriptor7* @"??_R0?AUA@@@8" to %struct.type_info*) |
21 | |
22 | const std::type_info* test2_typeid() { return &typeid(&a); } |
23 | // CHECK-LABEL: define dso_local %struct.type_info* @"?test2_typeid@@YAPBUtype_info@@XZ"() |
24 | // CHECK: ret %struct.type_info* bitcast (%rtti.TypeDescriptor7* @"??_R0PAUA@@@8" to %struct.type_info*) |
25 | |
26 | const std::type_info* test3_typeid() { return &typeid(*fn()); } |
27 | // CHECK-LABEL: define dso_local %struct.type_info* @"?test3_typeid@@YAPBUtype_info@@XZ"() |
28 | // CHECK: [[CALL:%.*]] = tail call %struct.A* @"?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* nonnull [[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 dso_local %struct.type_info* @"?test4_typeid@@YAPBUtype_info@@XZ"() |
45 | // CHECK: ret %struct.type_info* bitcast (%rtti.TypeDescriptor2* @"??_R0H@8" to %struct.type_info*) |
46 | |
47 | const std::type_info* test5_typeid() { return &typeid(v); } |
48 | // CHECK: define dso_local %struct.type_info* @"?test5_typeid@@YAPBUtype_info@@XZ"() |
49 | // CHECK: [[RT:%.*]] = tail call i8* @__RTtypeid(i8* bitcast (%struct.V* @"?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 | |
53 | namespace PR26329 { |
54 | struct Polymorphic { |
55 | virtual ~Polymorphic(); |
56 | }; |
57 | |
58 | void f(const Polymorphic &poly) { |
59 | try { |
60 | throw; |
61 | } catch (...) { |
62 | Polymorphic cleanup; |
63 | typeid(poly); |
64 | } |
65 | } |
66 | // CHECK-LABEL: define dso_local void @"?f@PR26329@@YAXABUPolymorphic@1@@Z"( |
67 | // CHECK: %[[cs:.*]] = catchswitch within none [label %{{.*}}] unwind to caller |
68 | // CHECK: %[[cp:.*]] = catchpad within %[[cs]] [i8* null, i32 64, i8* null] |
69 | // CHECK: invoke i8* @__RTtypeid(i8* {{.*}}) [ "funclet"(token %[[cp]]) ] |
70 | } |
71 | |