1 // Check typeid() + type_info
3 // RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -O3 -S -o - -emit-llvm -fcxx-exceptions -fexceptions | FileCheck %s
5 // CHECK: %"class.std::type_info" = type { ptr, ptr }
7 // CHECK: $_ZTI1A.rtti_proxy = comdat any
8 // CHECK: $_ZTI1B.rtti_proxy = comdat any
10 // CHECK: @_ZTVN10__cxxabiv117__class_type_infoE = external global [0 x ptr]
11 // CHECK: @_ZTS1A ={{.*}} constant [3 x i8] c"1A\00", align 1
12 // CHECK: @_ZTI1A ={{.*}} constant { ptr, ptr } { ptr getelementptr inbounds (i8, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i32 8), ptr @_ZTS1A }, align 8
13 // CHECK: @_ZTVN10__cxxabiv120__si_class_type_infoE = external global [0 x ptr]
14 // CHECK: @_ZTS1B ={{.*}} constant [3 x i8] c"1B\00", align 1
15 // CHECK: @_ZTI1B ={{.*}} constant { ptr, ptr, ptr } { ptr getelementptr inbounds (i8, ptr @_ZTVN10__cxxabiv120__si_class_type_infoE, i32 8), ptr @_ZTS1B, ptr @_ZTI1A }, align 8
16 // CHECK: @_ZTI1A.rtti_proxy = linkonce_odr hidden unnamed_addr constant ptr @_ZTI1A, comdat
17 // CHECK: @_ZTI1B.rtti_proxy = linkonce_odr hidden unnamed_addr constant ptr @_ZTI1B, comdat
19 // CHECK: define {{.*}}ptr @_Z11getTypeInfov() local_unnamed_addr
21 // CHECK-NEXT: ret ptr @_ZTI1A
24 // CHECK: define{{.*}} ptr @_Z7getNamev() local_unnamed_addr
26 // CHECK-NEXT: ret ptr @_ZTS1A
29 // CHECK: define{{.*}} i1 @_Z5equalP1A(ptr noundef readonly %a) local_unnamed_addr
31 // CHECK-NEXT: [[isnull:%[0-9]+]] = icmp eq ptr %a, null
32 // CHECK-NEXT: br i1 [[isnull]], label %[[bad_typeid:[a-z0-9._]+]], label %[[end:[a-z0-9.+]+]]
33 // CHECK: [[bad_typeid]]:
34 // CHECK-NEXT: tail call void @__cxa_bad_typeid()
35 // CHECK-NEXT: unreachable
37 // CHECK-NEXT: [[vtable:%[a-z0-9]+]] = load ptr, ptr %a
38 // CHECK-NEXT: [[type_info_ptr:%[0-9]+]] = tail call ptr @llvm.load.relative.i32(ptr [[vtable]], i32 -4)
39 // CHECK-NEXT: [[type_info_ptr2:%[0-9]+]] = load ptr, ptr [[type_info_ptr]], align 8
40 // CHECK-NEXT: [[name_ptr:%[a-z0-9._]+]] = getelementptr inbounds %"class.std::type_info", ptr [[type_info_ptr2]], i64 0, i32 1
41 // CHECK-NEXT: [[name:%[0-9]+]] = load ptr, ptr [[name_ptr]], align 8
42 // CHECK-NEXT: [[eq:%[a-z0-9.]+]] = icmp eq ptr [[name]], @_ZTS1B
43 // CHECK-NEXT: ret i1 [[eq]]
46 #include "../typeinfo"
61 const auto &getTypeInfo() {
65 const char *getName() {
66 return typeid(A
).name();
70 return typeid(B
) == typeid(*a
);