|
| 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 -fcall-graph-section -S \ |
| 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-DAG: define {{.*}} ptr @_ZN4Cls18receiverEPcPf({{.*}} !type [[F_TCLS1RECEIVER:![0-9]+]] |
| 15 | + static int *receiver(char *a, float *b) { return 0; } |
| 16 | +}; |
| 17 | + |
| 18 | +class Cls2 { |
| 19 | +public: |
| 20 | + int *(*fp)(char *, float *); |
| 21 | + |
| 22 | + // FT-DAG: define {{.*}} i32 @_ZN4Cls22f1Ecfd({{.*}} !type [[F_TCLS2F1:![0-9]+]] |
| 23 | + int f1(char a, float b, double c) { return 0; } |
| 24 | + |
| 25 | + // FT-DAG: define {{.*}} ptr @_ZN4Cls22f2EPcPfPd({{.*}} !type [[F_TCLS2F2:![0-9]+]] |
| 26 | + int *f2(char *a, float *b, double *c) { return 0; } |
| 27 | + |
| 28 | + // FT-DAG: define {{.*}} void @_ZN4Cls22f3E4Cls1({{.*}} !type [[F_TCLS2F3F4:![0-9]+]] |
| 29 | + void f3(Cls1 a) {} |
| 30 | + |
| 31 | + // FT-DAG: define {{.*}} void @_ZN4Cls22f4E4Cls1({{.*}} !type [[F_TCLS2F3F4]] |
| 32 | + void f4(const Cls1 a) {} |
| 33 | + |
| 34 | + // FT-DAG: define {{.*}} void @_ZN4Cls22f5EP4Cls1({{.*}} !type [[F_TCLS2F5:![0-9]+]] |
| 35 | + void f5(Cls1 *a) {} |
| 36 | + |
| 37 | + // FT-DAG: define {{.*}} void @_ZN4Cls22f6EPK4Cls1({{.*}} !type [[F_TCLS2F6:![0-9]+]] |
| 38 | + void f6(const Cls1 *a) {} |
| 39 | + |
| 40 | + // FT-DAG: define {{.*}} void @_ZN4Cls22f7ER4Cls1({{.*}} !type [[F_TCLS2F7:![0-9]+]] |
| 41 | + void f7(Cls1 &a) {} |
| 42 | + |
| 43 | + // FT-DAG: define {{.*}} void @_ZN4Cls22f8ERK4Cls1({{.*}} !type [[F_TCLS2F8:![0-9]+]] |
| 44 | + void f8(const Cls1 &a) {} |
| 45 | + |
| 46 | + // FT-DAG: define {{.*}} void @_ZNK4Cls22f9Ev({{.*}} !type [[F_TCLS2F9:![0-9]+]] |
| 47 | + void f9() const {} |
| 48 | +}; |
| 49 | + |
| 50 | +// FT-DAG: [[F_TCLS1RECEIVER]] = !{i64 0, !"_ZTSFPvS_S_E.generalized"} |
| 51 | +// FT-DAG: [[F_TCLS2F2]] = !{i64 0, !"_ZTSFPvS_S_S_E.generalized"} |
| 52 | +// FT-DAG: [[F_TCLS2F1]] = !{i64 0, !"_ZTSFicfdE.generalized"} |
| 53 | +// FT-DAG: [[F_TCLS2F3F4]] = !{i64 0, !"_ZTSFv4Cls1E.generalized"} |
| 54 | +// FT-DAG: [[F_TCLS2F5]] = !{i64 0, !"_ZTSFvPvE.generalized"} |
| 55 | +// FT-DAG: [[F_TCLS2F6]] = !{i64 0, !"_ZTSFvPKvE.generalized"} |
| 56 | +// FT-DAG: [[F_TCLS2F7]] = !{i64 0, !"_ZTSFvR4Cls1E.generalized"} |
| 57 | +// FT-DAG: [[F_TCLS2F8]] = !{i64 0, !"_ZTSFvRK4Cls1E.generalized"} |
| 58 | +// FT-DAG: [[F_TCLS2F9]] = !{i64 0, !"_ZTSKFvvE.generalized"} |
| 59 | + |
| 60 | +//////////////////////////////////////////////////////////////////////////////// |
| 61 | +// Callsites (check for indirect callsite operand bundles) |
| 62 | + |
| 63 | +// CST-LABEL: define {{.*}} @_Z3foov |
| 64 | +void foo() { |
| 65 | + Cls2 ObjCls2; |
| 66 | + ObjCls2.fp = &Cls1::receiver; |
| 67 | + |
| 68 | + // CST: call noundef ptr %{{.*}} [ "type"(metadata !"_ZTSFPvS_S_E.generalized") ] |
| 69 | + ObjCls2.fp(0, 0); |
| 70 | + |
| 71 | + auto fp_f1 = &Cls2::f1; |
| 72 | + auto fp_f2 = &Cls2::f2; |
| 73 | + auto fp_f3 = &Cls2::f3; |
| 74 | + auto fp_f4 = &Cls2::f4; |
| 75 | + auto fp_f5 = &Cls2::f5; |
| 76 | + auto fp_f6 = &Cls2::f6; |
| 77 | + auto fp_f7 = &Cls2::f7; |
| 78 | + auto fp_f8 = &Cls2::f8; |
| 79 | + auto fp_f9 = &Cls2::f9; |
| 80 | + |
| 81 | + Cls2 *ObjCls2Ptr = &ObjCls2; |
| 82 | + Cls1 Cls1Param; |
| 83 | + |
| 84 | + // CST: call noundef i32 %{{.*}} [ "type"(metadata !"_ZTSFicfdE.generalized") ] |
| 85 | + (ObjCls2Ptr->*fp_f1)(0, 0, 0); |
| 86 | + |
| 87 | + // CST: call noundef ptr %{{.*}} [ "type"(metadata !"_ZTSFPvS_S_S_E.generalized") ] |
| 88 | + (ObjCls2Ptr->*fp_f2)(0, 0, 0); |
| 89 | + |
| 90 | + // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFv4Cls1E.generalized") ] |
| 91 | + (ObjCls2Ptr->*fp_f3)(Cls1Param); |
| 92 | + |
| 93 | + // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFv4Cls1E.generalized") ] |
| 94 | + (ObjCls2Ptr->*fp_f4)(Cls1Param); |
| 95 | + |
| 96 | + // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvPvE.generalized") ] |
| 97 | + (ObjCls2Ptr->*fp_f5)(&Cls1Param); |
| 98 | + |
| 99 | + // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvPKvE.generalized") ] |
| 100 | + (ObjCls2Ptr->*fp_f6)(&Cls1Param); |
| 101 | + |
| 102 | + // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvR4Cls1E.generalized") ] |
| 103 | + (ObjCls2Ptr->*fp_f7)(Cls1Param); |
| 104 | + |
| 105 | + // CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvRK4Cls1E.generalized") ] |
| 106 | + (ObjCls2Ptr->*fp_f8)(Cls1Param); |
| 107 | + |
| 108 | + // CST: call void %{{.*}} [ "type"(metadata !"_ZTSKFvvE.generalized") ] |
| 109 | + (ObjCls2Ptr->*fp_f9)(); |
| 110 | +} |
0 commit comments