File: microsoft-abi-typeid.cpp

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (69 lines) | stat: -rw-r--r-- 2,708 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// RUN: %clang_cc1 -emit-llvm -O1 -o - -triple=i386-pc-win32 %s -fexceptions -fcxx-exceptions | FileCheck %s

struct type_info;
namespace std { using ::type_info; }

struct V { virtual void f(); };
struct A : virtual V { A(); };

extern A a;
extern V v;
extern int b;
A* fn();

const std::type_info* test0_typeid() { return &typeid(int); }
// CHECK-LABEL: define dso_local noundef nonnull ptr @"?test0_typeid@@YAPBUtype_info@@XZ"()
// CHECK:   ret ptr @"??_R0H@8"

const std::type_info* test1_typeid() { return &typeid(A); }
// CHECK-LABEL: define dso_local noundef nonnull ptr @"?test1_typeid@@YAPBUtype_info@@XZ"()
// CHECK:   ret ptr @"??_R0?AUA@@@8"

const std::type_info* test2_typeid() { return &typeid(&a); }
// CHECK-LABEL: define dso_local noundef nonnull ptr @"?test2_typeid@@YAPBUtype_info@@XZ"()
// CHECK:   ret ptr @"??_R0PAUA@@@8"

const std::type_info* test3_typeid() { return &typeid(*fn()); }
// CHECK-LABEL: define dso_local noundef ptr @"?test3_typeid@@YAPBUtype_info@@XZ"()
// CHECK:        [[CALL:%.*]] = tail call noundef ptr @"?fn@@YAPAUA@@XZ"()
// CHECK-NEXT:   [[CMP:%.*]] = icmp eq ptr [[CALL]], null
// CHECK-NEXT:   br i1 [[CMP]]
// CHECK:        call ptr @__RTtypeid(ptr null)
// CHECK-NEXT:   unreachable
// CHECK:        [[VBTBL:%.*]] = load ptr, ptr [[CALL]], align 4
// CHECK-NEXT:   [[VBSLOT:%.*]] = getelementptr inbounds i32, ptr [[VBTBL]], i32 1
// CHECK-NEXT:   [[VBASE_OFFS:%.*]] = load i32, ptr [[VBSLOT]], align 4
// CHECK-NEXT:   [[ADJ:%.*]] = getelementptr inbounds i8, ptr [[CALL]], i32 [[VBASE_OFFS]]
// CHECK-NEXT:   [[RT:%.*]] = tail call ptr @__RTtypeid(ptr nonnull [[ADJ]])
// CHECK-NEXT:   ret ptr [[RT]]

const std::type_info* test4_typeid() { return &typeid(b); }
// CHECK: define dso_local noundef nonnull ptr @"?test4_typeid@@YAPBUtype_info@@XZ"()
// CHECK:   ret ptr @"??_R0H@8"

const std::type_info* test5_typeid() { return &typeid(v); }
// CHECK: define dso_local noundef nonnull ptr @"?test5_typeid@@YAPBUtype_info@@XZ"()
// CHECK:   ret ptr @"??_R0?AUV@@@8"

const std::type_info *test6_typeid() { return &typeid((V &)v); }
// CHECK: define dso_local noundef nonnull ptr @"?test6_typeid@@YAPBUtype_info@@XZ"()
// CHECK:   ret ptr @"??_R0?AUV@@@8"

namespace PR26329 {
struct Polymorphic {
  virtual ~Polymorphic();
};

void f(const Polymorphic &poly) {
  try {
    throw;
  } catch (...) {
    Polymorphic cleanup;
    typeid(poly);
  }
}
// CHECK-LABEL: define dso_local void @"?f@PR26329@@YAXABUPolymorphic@1@@Z"(
// CHECK: %[[cs:.*]] = catchswitch within none [label %{{.*}}] unwind to caller
// CHECK: %[[cp:.*]] = catchpad within %[[cs]] [ptr null, i32 64, ptr null]
// CHECK: invoke ptr @__RTtypeid(ptr {{.*}}) [ "funclet"(token %[[cp]]) ]
}