Debian Codegraph @

clang/test/CodeGen/call-graph-section.cpp

raw
1 // Tests that we assign appropriate identifiers to indirect calls and targets
2 // specifically for C++ class and instance methods.
3
4 // RUN: %clang_cc1 -triple x86_64-unknown-linux -fexperimental-call-graph-section \
5 // RUN: -emit-llvm -o %t %s
6 // RUN: FileCheck --check-prefix=FT %s < %t
7 // RUN: FileCheck --check-prefix=CST %s < %t
8
9 ////////////////////////////////////////////////////////////////////////////////
10 // Class definitions (check for indirect target metadata)
11
12 class Cls1 {
13 public:
14 // FT-LABEL: define {{.*}} ptr @_ZN4Cls18receiverEPcPf(
15 // FT-SAME: {{.*}} !type [[F_TCLS1RECEIVER:![0-9]+]]
16 static int *receiver(char *a, float *b) { return 0; }
17 };
18
19 class Cls2 {
20 public:
21 int *(*fp)(char *, float *);
22
23 // FT-LABEL: define {{.*}} i32 @_ZN4Cls22f1Ecfd(
24 // FT-SAME: {{.*}} !type [[F_TCLS2F1:![0-9]+]]
25 int f1(char a, float b, double c) { return 0; }
26
27 // FT-LABEL: define {{.*}} ptr @_ZN4Cls22f2EPcPfPd(
28 // FT-SAME: {{.*}} !type [[F_TCLS2F2:![0-9]+]]
29 int *f2(char *a, float *b, double *c) { return 0; }
30
31 // FT-LABEL: define {{.*}} void @_ZN4Cls22f3E4Cls1(
32 // FT-SAME: {{.*}} !type [[F_TCLS2F3F4:![0-9]+]]
33 void f3(Cls1 a) {}
34
35 // FT-LABEL: define {{.*}} void @_ZN4Cls22f4E4Cls1(
36 // FT-SAME: {{.*}} !type [[F_TCLS2F3F4]]
37 void f4(const Cls1 a) {}
38
39 // FT-LABEL: define {{.*}} void @_ZN4Cls22f5EP4Cls1(
40 // FT-SAME: {{.*}} !type [[F_TCLS2F5:![0-9]+]]
41 void f5(Cls1 *a) {}
42
43 // FT-LABEL: define {{.*}} void @_ZN4Cls22f6EPK4Cls1(
44 // FT-SAME: {{.*}} !type [[F_TCLS2F6:![0-9]+]]
45 void f6(const Cls1 *a) {}
46
47 // FT-LABEL: define {{.*}} void @_ZN4Cls22f7ER4Cls1(
48 // FT-SAME: {{.*}} !type [[F_TCLS2F7:![0-9]+]]
49 void f7(Cls1 &a) {}
50
51 // FT-LABEL: define {{.*}} void @_ZN4Cls22f8ERK4Cls1(
52 // FT-SAME: {{.*}} !type [[F_TCLS2F8:![0-9]+]]
53 void f8(const Cls1 &a) {}
54
55 // FT-LABEL: define {{.*}} void @_ZNK4Cls22f9Ev(
56 // FT-SAME: {{.*}} !type [[F_TCLS2F9:![0-9]+]]
57 void f9() const {}
58 };
59
60 // FT: [[F_TCLS1RECEIVER]] = !{i64 0, !"_ZTSFPiPcPfE.generalized"}
61 // FT: [[F_TCLS2F1]] = !{i64 0, !"_ZTSFicfdE.generalized"}
62 // FT: [[F_TCLS2F2]] = !{i64 0, !"_ZTSFPiPcPfPdE.generalized"}
63 // FT: [[F_TCLS2F3F4]] = !{i64 0, !"_ZTSFv4Cls1E.generalized"}
64 // FT: [[F_TCLS2F5]] = !{i64 0, !"_ZTSFvP4Cls1E.generalized"}
65 // FT: [[F_TCLS2F6]] = !{i64 0, !"_ZTSFvPK4Cls1E.generalized"}
66 // FT: [[F_TCLS2F7]] = !{i64 0, !"_ZTSFvR4Cls1E.generalized"}
67 // FT: [[F_TCLS2F8]] = !{i64 0, !"_ZTSFvRK4Cls1E.generalized"}
68 // FT: [[F_TCLS2F9]] = !{i64 0, !"_ZTSKFvvE.generalized"}
69
70 ////////////////////////////////////////////////////////////////////////////////
71 // Callsites (check for indirect callsites' callee_type metadata )
72
73 // CST-LABEL: define {{.*}} @_Z3foov
74 void foo() {
75 Cls2 ObjCls2;
76 ObjCls2.fp = &Cls1::receiver;
77
78 // CST: call noundef ptr %{{.*}}, !callee_type [[F_TCLS1RECEIVER_CT:![0-9]+]]
79 ObjCls2.fp(0, 0);
80
81 auto fp_f1 = &Cls2::f1;
82 auto fp_f2 = &Cls2::f2;
83 auto fp_f3 = &Cls2::f3;
84 auto fp_f4 = &Cls2::f4;
85 auto fp_f5 = &Cls2::f5;
86 auto fp_f6 = &Cls2::f6;
87 auto fp_f7 = &Cls2::f7;
88 auto fp_f8 = &Cls2::f8;
89 auto fp_f9 = &Cls2::f9;
90
91 Cls2 *ObjCls2Ptr = &ObjCls2;
92 Cls1 Cls1Param;
93
94 // CST: call noundef i32 %{{.*}}, !callee_type [[F_TCLS2F1_CT:![0-9]+]]
95 (ObjCls2Ptr->*fp_f1)(0, 0, 0);
96
97 // CST: call noundef ptr %{{.*}}, !callee_type [[F_TCLS2F2_CT:![0-9]+]]
98 (ObjCls2Ptr->*fp_f2)(0, 0, 0);
99
100 // CST: call void %{{.*}}, !callee_type [[F_TCLS2F3F4_CT:![0-9]+]]
101 (ObjCls2Ptr->*fp_f3)(Cls1Param);
102
103 // CST: call void %{{.*}}, !callee_type [[F_TCLS2F3F4_CT:![0-9]+]]
104 (ObjCls2Ptr->*fp_f4)(Cls1Param);
105
106 // CST: call void %{{.*}}, !callee_type [[F_TCLS2F5_CT:![0-9]+]]
107 (ObjCls2Ptr->*fp_f5)(&Cls1Param);
108
109 // CST: call void %{{.*}}, !callee_type [[F_TCLS2F6_CT:![0-9]+]]
110 (ObjCls2Ptr->*fp_f6)(&Cls1Param);
111
112 // CST: call void %{{.*}}, !callee_type [[F_TCLS2F7_CT:![0-9]+]]
113 (ObjCls2Ptr->*fp_f7)(Cls1Param);
114
115 // CST: call void %{{.*}}, !callee_type [[F_TCLS2F8_CT:![0-9]+]]
116 (ObjCls2Ptr->*fp_f8)(Cls1Param);
117
118 // CST: call void %{{.*}}, !callee_type [[F_TCLS2F9_CT:![0-9]+]]
119 (ObjCls2Ptr->*fp_f9)();
120 }
121
122 // CST: [[F_TCLS1RECEIVER_CT]] = !{[[F_TCLS1RECEIVER:![0-9]+]]}
123 // CST: [[F_TCLS1RECEIVER]] = !{i64 0, !"_ZTSFPiPcPfE.generalized"}
124
125 // CST: [[F_TCLS2F1_CT]] = !{[[F_TCLS2F1:![0-9]+]]}
126 // CST: [[F_TCLS2F1]] = !{i64 0, !"_ZTSFicfdE.generalized"}
127
128 // CST: [[F_TCLS2F2_CT]] = !{[[F_TCLS2F2:![0-9]+]]}
129 // CST: [[F_TCLS2F2]] = !{i64 0, !"_ZTSFPiPcPfPdE.generalized"}
130
131 // CST: [[F_TCLS2F3F4_CT]] = !{[[F_TCLS2F3F4:![0-9]+]]}
132 // CST: [[F_TCLS2F3F4]] = !{i64 0, !"_ZTSFv4Cls1E.generalized"}
133
134 // CST: [[F_TCLS2F5_CT]] = !{[[F_TCLS2F5:![0-9]+]]}
135 // CST: [[F_TCLS2F5]] = !{i64 0, !"_ZTSFvP4Cls1E.generalized"}
136
137 // CST: [[F_TCLS2F6_CT]] = !{[[F_TCLS2F6:![0-9]+]]}
138 // CST: [[F_TCLS2F6]] = !{i64 0, !"_ZTSFvPK4Cls1E.generalized"}
139
140 // CST: [[F_TCLS2F7_CT]] = !{[[F_TCLS2F7:![0-9]+]]}
141 // CST: [[F_TCLS2F7]] = !{i64 0, !"_ZTSFvR4Cls1E.generalized"}
142
143 // CST: [[F_TCLS2F8_CT]] = !{[[F_TCLS2F8:![0-9]+]]}
144 // CST: [[F_TCLS2F8]] = !{i64 0, !"_ZTSFvRK4Cls1E.generalized"}
145
146 // CST: [[F_TCLS2F9_CT]] = !{[[F_TCLS2F9:![0-9]+]]}
147 // CST: [[F_TCLS2F9]] = !{i64 0, !"_ZTSKFvvE.generalized"}