[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / CodeGenCXX / microsoft-abi-typeid.cpp
blob45c7dd9a6f1aca0db478ec1520c9091d990dc466
1 // RUN: %clang_cc1 -emit-llvm -O1 -o - -triple=i386-pc-win32 %s -fexceptions -fcxx-exceptions | FileCheck %s
3 struct type_info;
4 namespace std { using ::type_info; }
6 struct V { virtual void f(); };
7 struct A : virtual V { A(); };
9 extern A a;
10 extern V v;
11 extern int b;
12 A* fn();
14 const std::type_info* test0_typeid() { return &typeid(int); }
15 // CHECK-LABEL: define dso_local noundef %struct.type_info* @"?test0_typeid@@YAPBUtype_info@@XZ"()
16 // CHECK: ret %struct.type_info* bitcast (%rtti.TypeDescriptor2* @"??_R0H@8" to %struct.type_info*)
18 const std::type_info* test1_typeid() { return &typeid(A); }
19 // CHECK-LABEL: define dso_local noundef %struct.type_info* @"?test1_typeid@@YAPBUtype_info@@XZ"()
20 // CHECK: ret %struct.type_info* bitcast (%rtti.TypeDescriptor7* @"??_R0?AUA@@@8" to %struct.type_info*)
22 const std::type_info* test2_typeid() { return &typeid(&a); }
23 // CHECK-LABEL: define dso_local noundef %struct.type_info* @"?test2_typeid@@YAPBUtype_info@@XZ"()
24 // CHECK: ret %struct.type_info* bitcast (%rtti.TypeDescriptor7* @"??_R0PAUA@@@8" to %struct.type_info*)
26 const std::type_info* test3_typeid() { return &typeid(*fn()); }
27 // CHECK-LABEL: define dso_local noundef %struct.type_info* @"?test3_typeid@@YAPBUtype_info@@XZ"()
28 // CHECK: [[CALL:%.*]] = call noundef %struct.A* @"?fn@@YAPAUA@@XZ"()
29 // CHECK-NEXT: [[CMP:%.*]] = icmp eq %struct.A* [[CALL]], null
30 // CHECK-NEXT: br i1 [[CMP]]
31 // CHECK: call i8* @__RTtypeid(i8* null)
32 // CHECK-NEXT: unreachable
33 // CHECK: [[THIS:%.*]] = bitcast %struct.A* [[CALL]] to i8*
34 // CHECK-NEXT: [[VBTBLP:%.*]] = getelementptr %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:%.*]] = 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]]
43 const std::type_info* test4_typeid() { return &typeid(b); }
44 // CHECK: define dso_local noundef %struct.type_info* @"?test4_typeid@@YAPBUtype_info@@XZ"()
45 // CHECK: ret %struct.type_info* bitcast (%rtti.TypeDescriptor2* @"??_R0H@8" to %struct.type_info*)
47 const std::type_info* test5_typeid() { return &typeid(v); }
48 // CHECK: define dso_local noundef %struct.type_info* @"?test5_typeid@@YAPBUtype_info@@XZ"()
49 // CHECK: ret %struct.type_info* bitcast (%rtti.TypeDescriptor7* @"??_R0?AUV@@@8" to %struct.type_info*)
51 const std::type_info *test6_typeid() { return &typeid((V &)v); }
52 // CHECK: define dso_local noundef %struct.type_info* @"?test6_typeid@@YAPBUtype_info@@XZ"()
53 // CHECK: ret %struct.type_info* bitcast (%rtti.TypeDescriptor7* @"??_R0?AUV@@@8" to %struct.type_info*)
55 namespace PR26329 {
56 struct Polymorphic {
57 virtual ~Polymorphic();
60 void f(const Polymorphic &poly) {
61 try {
62 throw;
63 } catch (...) {
64 Polymorphic cleanup;
65 typeid(poly);
68 // CHECK-LABEL: define dso_local void @"?f@PR26329@@YAXABUPolymorphic@1@@Z"(
69 // CHECK: %[[cs:.*]] = catchswitch within none [label %{{.*}}] unwind to caller
70 // CHECK: %[[cp:.*]] = catchpad within %[[cs]] [i8* null, i32 64, i8* null]
71 // CHECK: invoke i8* @__RTtypeid(i8* {{.*}}) [ "funclet"(token %[[cp]]) ]