1 // RUN: %clang_cc1 -emit-llvm -O2 -optzns -o - -triple=i386-pc-win32 2>/dev/null %s | FileCheck %s 2 // REQUIRES: asserts 3 4 struct type_info { const char* raw_name() const; }; 5 namespace std { using ::type_info; } 6 7 struct V { virtual void f() {}; }; 8 struct A : virtual V {}; 9 10 A a; 11 int b; 12 A* fn(); 13 14 const std::type_info* test0_typeid() { return &typeid(int); } 15 // CHECK: define %struct.type_info* @"\01?test0_typeid@@YAPBUtype_info@@XZ"() #0 { 16 // CHECK-NEXT: entry: 17 // CHECK-NEXT: ret %struct.type_info* bitcast (%"MSRTTITypeDescriptor\02"* @"\01??_R0H@8" to %struct.type_info*) 18 // CHECK-NEXT: } 19 20 const std::type_info* test1_typeid() { return &typeid(A); } 21 // CHECK: define %struct.type_info* @"\01?test1_typeid@@YAPBUtype_info@@XZ"() #0 { 22 // CHECK-NEXT: entry: 23 // CHECK-NEXT: ret %struct.type_info* bitcast (%"MSRTTITypeDescriptor\07"* @"\01??_R0?AUA@@@8" to %struct.type_info*) 24 // CHECK-NEXT: } 25 26 const std::type_info* test2_typeid() { return &typeid(&a); } 27 // CHECK: define %struct.type_info* @"\01?test2_typeid@@YAPBUtype_info@@XZ"() #0 { 28 // CHECK-NEXT: entry: 29 // CHECK-NEXT: ret %struct.type_info* bitcast (%"MSRTTITypeDescriptor\07"* @"\01??_R0PAUA@@@8" to %struct.type_info*) 30 // CHECK-NEXT: } 31 32 const std::type_info* test3_typeid() { return &typeid(*fn()); } 33 // CHECK: define %struct.type_info* @"\01?test3_typeid@@YAPBUtype_info@@XZ"() #1 { 34 // CHECK-NEXT: entry: 35 // CHECK-NEXT: %call = tail call %struct.A* @"\01?fn@@YAPAUA@@XZ"() #3 36 // CHECK-NEXT: %0 = icmp eq %struct.A* %call, null 37 // CHECK-NEXT: br i1 %0, label %type_id.call, label %type_id.valid 38 // CHECK: type_id.valid: ; preds = %entry 39 // CHECK-NEXT: %1 = bitcast %struct.A* %call to i8* 40 // CHECK-NEXT: %2 = bitcast %struct.A* %call to i8** 41 // CHECK-NEXT: %vbtable = load i8** %2, align 4 42 // CHECK-NEXT: %3 = getelementptr inbounds i8* %vbtable, i32 4 43 // CHECK-NEXT: %4 = bitcast i8* %3 to i32* 44 // CHECK-NEXT: %vbase_offs = load i32* %4, align 4 45 // CHECK-NEXT: %5 = getelementptr inbounds i8* %1, i32 %vbase_offs 46 // CHECK-NEXT: br label %type_id.call 47 // CHECK: type_id.call: ; preds = %type_id.valid, %entry 48 // CHECK-NEXT: %6 = phi i8* [ %5, %type_id.valid ], [ null, %entry ] 49 // CHECK-NEXT: %7 = tail call i8* @__RTtypeid(i8* %6) #3 50 // CHECK-NEXT: %8 = bitcast i8* %7 to %struct.type_info* 51 // CHECK-NEXT: ret %struct.type_info* %8 52 // CHECK-NEXT: } 53 54 const std::type_info* test4_typeid() { return &typeid(b); } 55 // CHECK: define %struct.type_info* @"\01?test4_typeid@@YAPBUtype_info@@XZ"() #0 { 56 // CHECK-NEXT: entry: 57 // CHECK-NEXT: ret %struct.type_info* bitcast (%"MSRTTITypeDescriptor\02"* @"\01??_R0H@8" to %struct.type_info*) 58 // CHECK-NEXT: } 59