|
| 1 | +// Tests that we assign appropriate identifiers to indirect calls and targets |
| 2 | +// specifically for C++ templates. |
| 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 and template classes (check for indirect target metadata) |
| 11 | + |
| 12 | +class Cls1 {}; |
| 13 | + |
| 14 | +// Cls2 is instantiated with T=Cls1 in foo(). Following checks are for this |
| 15 | +// instantiation. |
| 16 | +template <class T> |
| 17 | +class Cls2 { |
| 18 | +public: |
| 19 | + // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f1Ev( |
| 20 | + // FT-SAME: {{.*}} !type [[F_TCLS2F1:![0-9]+]] |
| 21 | + void f1() {} |
| 22 | + |
| 23 | + // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f2ES0_( |
| 24 | + // FT-SAME: {{.*}} !type [[F_TCLS2F2:![0-9]+]] |
| 25 | + void f2(T a) {} |
| 26 | + |
| 27 | + // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f3EPS0_( |
| 28 | + // FT-SAME: {{.*}} !type [[F_TCLS2F3:![0-9]+]] |
| 29 | + void f3(T *a) {} |
| 30 | + |
| 31 | + // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f4EPKS0_( |
| 32 | + // FT-SAME: {{.*}} !type [[F_TCLS2F4:![0-9]+]] |
| 33 | + void f4(const T *a) {} |
| 34 | + |
| 35 | + // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f5ERS0_( |
| 36 | + // FT-SAME: {{.*}} !type [[F_TCLS2F5:![0-9]+]] |
| 37 | + void f5(T &a) {} |
| 38 | + |
| 39 | + // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f6ERKS0_( |
| 40 | + // FT-SAME: {{.*}} !type [[F_TCLS2F6:![0-9]+]] |
| 41 | + void f6(const T &a) {} |
| 42 | + |
| 43 | + // Mixed type function pointer member |
| 44 | + T *(*fp)(T a, T *b, const T *c, T &d, const T &e); |
| 45 | +}; |
| 46 | + |
| 47 | +// FT: [[F_TCLS2F1]] = !{i64 0, !"_ZTSFvvE.generalized"} |
| 48 | +// FT: [[F_TCLS2F2]] = !{i64 0, !"_ZTSFv4Cls1E.generalized"} |
| 49 | +// FT: [[F_TCLS2F3]] = !{i64 0, !"_ZTSFvP4Cls1E.generalized"} |
| 50 | +// FT: [[F_TCLS2F4]] = !{i64 0, !"_ZTSFvPK4Cls1E.generalized"} |
| 51 | +// FT: [[F_TCLS2F5]] = !{i64 0, !"_ZTSFvR4Cls1E.generalized"} |
| 52 | +// FT: [[F_TCLS2F6]] = !{i64 0, !"_ZTSFvRK4Cls1E.generalized"} |
| 53 | + |
| 54 | +//////////////////////////////////////////////////////////////////////////////// |
| 55 | +// Callsites (check for indirect callsite operand bundles) |
| 56 | + |
| 57 | +template <class T> |
| 58 | +T *T_func(T a, T *b, const T *c, T &d, const T &e) { return b; } |
| 59 | + |
| 60 | +// CST-LABEL: define {{.*}} @_Z3foov |
| 61 | +// CST-SAME: {{.*}} !type [[F_TCLS2F1:![0-9]+]] |
| 62 | +void foo() { |
| 63 | + // Methods for Cls2<Cls1> is checked above within the template description. |
| 64 | + Cls2<Cls1> Obj; |
| 65 | + |
| 66 | + Obj.fp = T_func<Cls1>; |
| 67 | + Cls1 Cls1Obj; |
| 68 | + |
| 69 | + // CST: call noundef ptr %{{.*}}, !callee_type [[F_TFUNC_CLS1_CT:![0-9]+]] |
| 70 | + Obj.fp(Cls1Obj, &Cls1Obj, &Cls1Obj, Cls1Obj, Cls1Obj); |
| 71 | + |
| 72 | + // Make indirect calls to Cls2's member methods |
| 73 | + auto fp_f1 = &Cls2<Cls1>::f1; |
| 74 | + auto fp_f2 = &Cls2<Cls1>::f2; |
| 75 | + auto fp_f3 = &Cls2<Cls1>::f3; |
| 76 | + auto fp_f4 = &Cls2<Cls1>::f4; |
| 77 | + auto fp_f5 = &Cls2<Cls1>::f5; |
| 78 | + auto fp_f6 = &Cls2<Cls1>::f6; |
| 79 | + |
| 80 | + auto *Obj2Ptr = &Obj; |
| 81 | + |
| 82 | + // CST: call void %{{.*}}, !callee_type [[F_TCLS2F1_CT:![0-9]+]] |
| 83 | + (Obj2Ptr->*fp_f1)(); |
| 84 | + |
| 85 | + // CST: call void %{{.*}}, !callee_type [[F_TCLS2F2_CT:![0-9]+]] |
| 86 | + (Obj2Ptr->*fp_f2)(Cls1Obj); |
| 87 | + |
| 88 | + // CST: call void %{{.*}}, !callee_type [[F_TCLS2F3_CT:![0-9]+]] |
| 89 | + (Obj2Ptr->*fp_f3)(&Cls1Obj); |
| 90 | + |
| 91 | + // CST: call void %{{.*}}, !callee_type [[F_TCLS2F4_CT:![0-9]+]] |
| 92 | + (Obj2Ptr->*fp_f4)(&Cls1Obj); |
| 93 | + |
| 94 | + // CST: call void %{{.*}}, !callee_type [[F_TCLS2F5_CT:![0-9]+]] |
| 95 | + (Obj2Ptr->*fp_f5)(Cls1Obj); |
| 96 | + |
| 97 | + // CST: call void %{{.*}}, !callee_type [[F_TCLS2F6_CT:![0-9]+]] |
| 98 | + (Obj2Ptr->*fp_f6)(Cls1Obj); |
| 99 | +} |
| 100 | + |
| 101 | +// CST-LABEL: define {{.*}} @_Z6T_funcI4Cls1EPT_S1_S2_PKS1_RS1_RS3_( |
| 102 | +// CST-SAME: {{.*}} !type [[F_TFUNC_CLS1:![0-9]+]] |
| 103 | + |
| 104 | +// CST: [[F_TCLS2F1]] = !{i64 0, !"_ZTSFvvE.generalized"} |
| 105 | +// CST: [[F_TFUNC_CLS1_CT]] = !{[[F_TFUNC_CLS1:![0-9]+]]} |
| 106 | +// CST: [[F_TFUNC_CLS1]] = !{i64 0, !"_ZTSFP4Cls1S_S0_PKS_RS_RS1_E.generalized"} |
| 107 | +// CST: [[F_TCLS2F1_CT]] = !{[[F_TCLS2F1:![0-9]+]]} |
| 108 | +// CST: [[F_TCLS2F2_CT]] = !{[[F_TCLS2F2:![0-9]+]]} |
| 109 | +// CST: [[F_TCLS2F2]] = !{i64 0, !"_ZTSFv4Cls1E.generalized"} |
| 110 | +// CST: [[F_TCLS2F3_CT]] = !{[[F_TCLS2F3:![0-9]+]]} |
| 111 | +// CST: [[F_TCLS2F3]] = !{i64 0, !"_ZTSFvP4Cls1E.generalized"} |
| 112 | +// CST: [[F_TCLS2F4_CT]] = !{[[F_TCLS2F4:![0-9]+]]} |
| 113 | +// CST: [[F_TCLS2F4]] = !{i64 0, !"_ZTSFvPK4Cls1E.generalized"} |
| 114 | +// CST: [[F_TCLS2F5_CT]] = !{[[F_TCLS2F5:![0-9]+]]} |
| 115 | +// CST: [[F_TCLS2F5]] = !{i64 0, !"_ZTSFvR4Cls1E.generalized"} |
| 116 | +// CST: [[F_TCLS2F6_CT]] = !{[[F_TCLS2F6:![0-9]+]]} |
| 117 | +// CST: [[F_TCLS2F6]] = !{i64 0, !"_ZTSFvRK4Cls1E.generalized"} |
0 commit comments