| 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 noundef nonnull ptr @"?test0_typeid@@YAPBUtype_info@@XZ"() |
| 16 |
// CHECK: ret ptr @"??_R0H@8" |
| 17 |
|
| 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" |
| 21 |
|
| 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" |
| 25 |
|
| 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 nuw 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]] |
| 39 |
|
| 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" |
| 43 |
|
| 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" |
| 47 |
|
| 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" |
| 51 |
|
| 52 |
namespace PR26329 { |
| 53 |
struct Polymorphic { |
| 54 |
virtual ~Polymorphic(); |
| 55 |
}; |
| 56 |
|
| 57 |
void f(const Polymorphic &poly) { |
| 58 |
try { |
| 59 |
throw; |
| 60 |
} catch (...) { |
| 61 |
Polymorphic cleanup; |
| 62 |
typeid(poly); |
| 63 |
} |
| 64 |
} |
| 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]]) ] |
| 69 |
} |