[Clang] replace 'bitfield' with 'bit-field' for consistency (#117881)
[llvm-project.git] / clang / test / CodeGenCXX / microsoft-abi-typeid.cpp
blob31d7d23fd6fc5c93939bf0352e487df4f90cea63
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 nonnull ptr @"?test0_typeid@@YAPBUtype_info@@XZ"()
16 // CHECK: ret ptr @"??_R0H@8"
18 const std::type_info* test1_typeid() { return &typeid(A); }
19 // CHECK-LABEL: define dso_local noundef nonnull ptr @"?test1_typeid@@YAPBUtype_info@@XZ"()
20 // CHECK: ret ptr @"??_R0?AUA@@@8"
22 const std::type_info* test2_typeid() { return &typeid(&a); }
23 // CHECK-LABEL: define dso_local noundef nonnull ptr @"?test2_typeid@@YAPBUtype_info@@XZ"()
24 // CHECK: ret ptr @"??_R0PAUA@@@8"
26 const std::type_info* test3_typeid() { return &typeid(*fn()); }
27 // CHECK-LABEL: define dso_local noundef ptr @"?test3_typeid@@YAPBUtype_info@@XZ"()
28 // CHECK: [[CALL:%.*]] = tail call noundef ptr @"?fn@@YAPAUA@@XZ"()
29 // CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[CALL]], null
30 // CHECK-NEXT: br i1 [[CMP]]
31 // CHECK: call ptr @__RTtypeid(ptr null)
32 // CHECK-NEXT: unreachable
33 // CHECK: [[VBTBL:%.*]] = load ptr, ptr [[CALL]], align 4
34 // CHECK-NEXT: [[VBSLOT:%.*]] = getelementptr inbounds i8, ptr [[VBTBL]], i32 4
35 // CHECK-NEXT: [[VBASE_OFFS:%.*]] = load i32, ptr [[VBSLOT]], align 4
36 // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, ptr [[CALL]], i32 [[VBASE_OFFS]]
37 // CHECK-NEXT: [[RT:%.*]] = tail call ptr @__RTtypeid(ptr nonnull [[ADJ]])
38 // CHECK-NEXT: ret ptr [[RT]]
40 const std::type_info* test4_typeid() { return &typeid(b); }
41 // CHECK: define dso_local noundef nonnull ptr @"?test4_typeid@@YAPBUtype_info@@XZ"()
42 // CHECK: ret ptr @"??_R0H@8"
44 const std::type_info* test5_typeid() { return &typeid(v); }
45 // CHECK: define dso_local noundef nonnull ptr @"?test5_typeid@@YAPBUtype_info@@XZ"()
46 // CHECK: ret ptr @"??_R0?AUV@@@8"
48 const std::type_info *test6_typeid() { return &typeid((V &)v); }
49 // CHECK: define dso_local noundef nonnull ptr @"?test6_typeid@@YAPBUtype_info@@XZ"()
50 // CHECK: ret ptr @"??_R0?AUV@@@8"
52 namespace PR26329 {
53 struct Polymorphic {
54 virtual ~Polymorphic();
57 void f(const Polymorphic &poly) {
58 try {
59 throw;
60 } catch (...) {
61 Polymorphic cleanup;
62 typeid(poly);
65 // CHECK-LABEL: define dso_local void @"?f@PR26329@@YAXABUPolymorphic@1@@Z"(
66 // CHECK: %[[cs:.*]] = catchswitch within none [label %{{.*}}] unwind to caller
67 // CHECK: %[[cp:.*]] = catchpad within %[[cs]] [ptr null, i32 64, ptr null]
68 // CHECK: invoke ptr @__RTtypeid(ptr {{.*}}) [ "funclet"(token %[[cp]]) ]