aboutsummaryrefslogtreecommitdiff
path: root/clang/test/CodeGen/call-graph-section-2.cpp
blob: 4187faea495beeed2dbaa4aa5a33764187d2673a (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Tests that we assign appropriate identifiers to indirect calls and targets
// specifically for C++ templates.

// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section -S \
// RUN: -emit-llvm -o %t %s
// RUN: FileCheck --check-prefix=FT    %s < %t
// RUN: FileCheck --check-prefix=CST   %s < %t
// RUN: FileCheck --check-prefix=CHECK %s < %t

////////////////////////////////////////////////////////////////////////////////
// Class definitions and template classes (check for indirect target metadata)

class Cls1 {};

// Cls2 is instantiated with T=Cls1 in foo(). Following checks are for this
// instantiation.
template <class T>
class Cls2 {
public:
  // FT: define {{.*}} void @_ZN4Cls2I4Cls1E2f1Ev({{.*}} !type [[F_TCLS2F1:![0-9]+]]
  void f1() {}

  // FT: define {{.*}} void @_ZN4Cls2I4Cls1E2f2ES0_({{.*}} !type [[F_TCLS2F2:![0-9]+]]
  void f2(T a) {}

  // FT: define {{.*}} void @_ZN4Cls2I4Cls1E2f3EPS0_({{.*}} !type [[F_TCLS2F3:![0-9]+]]
  void f3(T *a) {}

  // FT: define {{.*}} void @_ZN4Cls2I4Cls1E2f4EPKS0_({{.*}} !type [[F_TCLS2F4:![0-9]+]]
  void f4(const T *a) {}

  // FT: define {{.*}} void @_ZN4Cls2I4Cls1E2f5ERS0_({{.*}} !type [[F_TCLS2F5:![0-9]+]]
  void f5(T &a) {}

  // FT: define {{.*}} void @_ZN4Cls2I4Cls1E2f6ERKS0_({{.*}} !type [[F_TCLS2F6:![0-9]+]]
  void f6(const T &a) {}

  // Mixed type function pointer member
  T *(*fp)(T a, T *b, const T *c, T &d, const T &e);
};

// FT-DAG: [[F_TCLS2F1]] = !{i64 0, !"_ZTSFvvE.generalized"}
// FT-DAG: [[F_TCLS2F2]] = !{i64 0, !"_ZTSFv4Cls1E.generalized"}
// FT-DAG: [[F_TCLS2F3]] = !{i64 0, !"_ZTSFvPvE.generalized"}
// FT-DAG: [[F_TCLS2F4]] = !{i64 0, !"_ZTSFvPKvE.generalized"}
// FT-DAG: [[F_TCLS2F5]] = !{i64 0, !"_ZTSFvR4Cls1E.generalized"}
// FT-DAG: [[F_TCLS2F6]] = !{i64 0, !"_ZTSFvRK4Cls1E.generalized"}

////////////////////////////////////////////////////////////////////////////////
// Callsites (check for indirect callsite operand bundles)

template <class T>
T *T_func(T a, T *b, const T *c, T &d, const T &e) { return b; }

// CST-LABEL: define {{.*}} @_Z3foov
void foo() {
  // Methods for Cls2<Cls1> is checked above within the template description.
  Cls2<Cls1> Obj;

  // CHECK-DAG: define {{.*}} @_Z6T_funcI4Cls1EPT_S1_S2_PKS1_RS1_RS3_({{.*}} !type [[F_TFUNC_CLS1:![0-9]+]]
  // CHECK-DAG: [[F_TFUNC_CLS1]] = !{i64 0, !"_ZTSFPv4Cls1S_PKvRS0_RKS0_E.generalized"}
  Obj.fp = T_func<Cls1>;
  Cls1 Cls1Obj;

  // CST: call noundef ptr %{{.*}} [ "type"(metadata !"_ZTSFPv4Cls1S_PKvRS0_RKS0_E.generalized") ]
  Obj.fp(Cls1Obj, &Cls1Obj, &Cls1Obj, Cls1Obj, Cls1Obj);

  // Make indirect calls to Cls2's member methods
  auto fp_f1 = &Cls2<Cls1>::f1;
  auto fp_f2 = &Cls2<Cls1>::f2;
  auto fp_f3 = &Cls2<Cls1>::f3;
  auto fp_f4 = &Cls2<Cls1>::f4;
  auto fp_f5 = &Cls2<Cls1>::f5;
  auto fp_f6 = &Cls2<Cls1>::f6;

  auto *Obj2Ptr = &Obj;

  // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvvE.generalized") ]
  (Obj2Ptr->*fp_f1)();

  // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFv4Cls1E.generalized") ]
  (Obj2Ptr->*fp_f2)(Cls1Obj);

  // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvPvE.generalized") ]
  (Obj2Ptr->*fp_f3)(&Cls1Obj);

  // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvPKvE.generalized") ]
  (Obj2Ptr->*fp_f4)(&Cls1Obj);

  // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvR4Cls1E.generalized") ]
  (Obj2Ptr->*fp_f5)(Cls1Obj);

  // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvRK4Cls1E.generalized") ]
  (Obj2Ptr->*fp_f6)(Cls1Obj);
}