-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[clang] callee_type metadata for indirect calls #117036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from 2 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
08d0dc1
[𝘀𝗽𝗿] initial version
Prabhuk feeeeff
Reorder commits. Fix clang codegen tests.
Prabhuk 2ece26f
Update OB name from `type` to `callee_type`.
Prabhuk 96c1d4e
Fix EOF newlines.
Prabhuk bfb4b1a
Add requested tests part 1.
Prabhuk 5bfc9de
Update comments in tests.
Prabhuk ccf13f2
Updated the test as reviewers suggested.
Prabhuk 158babd
Scoped enum. Simplify test.
Prabhuk fc860ab
Remove unnecessary cast.
Prabhuk 7847eb0
Remove unnecessary asserts. Remove autos for better readability.
Prabhuk ba49de6
Reorder IR metadata and rename temporary var names in test.
Prabhuk 1aba048
Add RISC-V support. Clean up test files.
Prabhuk c6d8515
Clean up test files.
Prabhuk c8154ed
Address review comments.
Prabhuk 3e00a85
Emit callee_type metadata instead of operand bundle.
Prabhuk 7228076
Address review comments.
Prabhuk 2cb23b7
Rebase on top of llvm stack.
Prabhuk 11c0913
Address review comments.
Prabhuk b7fbe09
Address review comments.
Prabhuk 3eb7a45
Address review comments.
Prabhuk ffa1779
Address review comments.
Prabhuk f10586e
Rebase on parent.
Prabhuk 5ddaf26
Rebase on parent.
Prabhuk 346e5b3
Rebase on parent.
Prabhuk 2d30d64
Rebase on parent.
Prabhuk bdc76a9
Rebase on parent.
Prabhuk e5157f6
Rebase on parent.
Prabhuk 02b2b3f
Rebase on parent change.
Prabhuk 67eab8a
Rebase on parent changes.
Prabhuk c183666
Rebase on parent.
Prabhuk 083270f
Rebase on parent
Prabhuk fac07fd
Rebase on main.
Prabhuk e193a40
Rebase on parent.
Prabhuk 599b585
Rebase change.
Prabhuk e41d689
Rebase.
Prabhuk 397fd64
Rebase on parent
Prabhuk 842f976
Rebase on top of main.
Prabhuk 13c0ffa
Rebase on parent.
Prabhuk 8ee6932
Rebase on parent
Prabhuk e179dc9
Rebase on top of parent change.
Prabhuk cb81b8a
Rebase on parent.
Prabhuk ad6905d
Rebase on parent.
Prabhuk d892b83
Address review comments.
Prabhuk fcb1497
Rebase on parent.
Prabhuk dfb1dc4
Simplify MD exists check.
Prabhuk b902d6e
Rebase.
Prabhuk 7c4b302
Rebase on parent change.
Prabhuk aa0c1d1
Rebase on main.
Prabhuk 985522c
Rebase.
Prabhuk 0382f0f
Rebase on parent.
Prabhuk e4c653f
Rebase on llvm changes.
Prabhuk 6195f97
Rebase on main.
Prabhuk 6b8eb94
Rebase on parent.
Prabhuk 3788ce7
Rebase on parent.
Prabhuk 0ca9184
Rebase on main.
Prabhuk 1f16b6a
Make Driver flag experimental.
Prabhuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Tests that we assign appropriate identifiers to indirect calls and targets | ||
// specifically for C++ class and instance methods. | ||
|
||
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section \ | ||
// RUN: -emit-llvm -o %t %s | ||
// RUN: FileCheck --check-prefix=FT %s < %t | ||
// RUN: FileCheck --check-prefix=CST %s < %t | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Class definitions (check for indirect target metadata) | ||
|
||
class Cls1 { | ||
public: | ||
// FT-DAG: define {{.*}} ptr @_ZN4Cls18receiverEPcPf({{.*}} !type [[F_TCLS1RECEIVER:![0-9]+]] | ||
static int *receiver(char *a, float *b) { return 0; } | ||
}; | ||
|
||
class Cls2 { | ||
public: | ||
int *(*fp)(char *, float *); | ||
|
||
// FT-DAG: define {{.*}} i32 @_ZN4Cls22f1Ecfd({{.*}} !type [[F_TCLS2F1:![0-9]+]] | ||
int f1(char a, float b, double c) { return 0; } | ||
|
||
// FT-DAG: define {{.*}} ptr @_ZN4Cls22f2EPcPfPd({{.*}} !type [[F_TCLS2F2:![0-9]+]] | ||
int *f2(char *a, float *b, double *c) { return 0; } | ||
|
||
// FT-DAG: define {{.*}} void @_ZN4Cls22f3E4Cls1({{.*}} !type [[F_TCLS2F3F4:![0-9]+]] | ||
void f3(Cls1 a) {} | ||
|
||
// FT-DAG: define {{.*}} void @_ZN4Cls22f4E4Cls1({{.*}} !type [[F_TCLS2F3F4]] | ||
void f4(const Cls1 a) {} | ||
|
||
// FT-DAG: define {{.*}} void @_ZN4Cls22f5EP4Cls1({{.*}} !type [[F_TCLS2F5:![0-9]+]] | ||
void f5(Cls1 *a) {} | ||
|
||
// FT-DAG: define {{.*}} void @_ZN4Cls22f6EPK4Cls1({{.*}} !type [[F_TCLS2F6:![0-9]+]] | ||
void f6(const Cls1 *a) {} | ||
|
||
// FT-DAG: define {{.*}} void @_ZN4Cls22f7ER4Cls1({{.*}} !type [[F_TCLS2F7:![0-9]+]] | ||
void f7(Cls1 &a) {} | ||
|
||
// FT-DAG: define {{.*}} void @_ZN4Cls22f8ERK4Cls1({{.*}} !type [[F_TCLS2F8:![0-9]+]] | ||
void f8(const Cls1 &a) {} | ||
|
||
// FT-DAG: define {{.*}} void @_ZNK4Cls22f9Ev({{.*}} !type [[F_TCLS2F9:![0-9]+]] | ||
void f9() const {} | ||
}; | ||
|
||
// FT-DAG: [[F_TCLS1RECEIVER]] = !{i64 0, !"_ZTSFPvS_S_E.generalized"} | ||
// FT-DAG: [[F_TCLS2F2]] = !{i64 0, !"_ZTSFPvS_S_S_E.generalized"} | ||
// FT-DAG: [[F_TCLS2F1]] = !{i64 0, !"_ZTSFicfdE.generalized"} | ||
// FT-DAG: [[F_TCLS2F3F4]] = !{i64 0, !"_ZTSFv4Cls1E.generalized"} | ||
// FT-DAG: [[F_TCLS2F5]] = !{i64 0, !"_ZTSFvPvE.generalized"} | ||
// FT-DAG: [[F_TCLS2F6]] = !{i64 0, !"_ZTSFvPKvE.generalized"} | ||
// FT-DAG: [[F_TCLS2F7]] = !{i64 0, !"_ZTSFvR4Cls1E.generalized"} | ||
// FT-DAG: [[F_TCLS2F8]] = !{i64 0, !"_ZTSFvRK4Cls1E.generalized"} | ||
// FT-DAG: [[F_TCLS2F9]] = !{i64 0, !"_ZTSKFvvE.generalized"} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Callsites (check for indirect callsite operand bundles) | ||
|
||
// CST-LABEL: define {{.*}} @_Z3foov | ||
void foo() { | ||
Cls2 ObjCls2; | ||
ObjCls2.fp = &Cls1::receiver; | ||
|
||
// CST: call noundef ptr %{{.*}} [ "type"(metadata !"_ZTSFPvS_S_E.generalized") ] | ||
ObjCls2.fp(0, 0); | ||
|
||
auto fp_f1 = &Cls2::f1; | ||
auto fp_f2 = &Cls2::f2; | ||
auto fp_f3 = &Cls2::f3; | ||
auto fp_f4 = &Cls2::f4; | ||
auto fp_f5 = &Cls2::f5; | ||
auto fp_f6 = &Cls2::f6; | ||
auto fp_f7 = &Cls2::f7; | ||
auto fp_f8 = &Cls2::f8; | ||
auto fp_f9 = &Cls2::f9; | ||
|
||
Cls2 *ObjCls2Ptr = &ObjCls2; | ||
Cls1 Cls1Param; | ||
|
||
// CST: call noundef i32 %{{.*}} [ "type"(metadata !"_ZTSFicfdE.generalized") ] | ||
(ObjCls2Ptr->*fp_f1)(0, 0, 0); | ||
|
||
// CST: call noundef ptr %{{.*}} [ "type"(metadata !"_ZTSFPvS_S_S_E.generalized") ] | ||
(ObjCls2Ptr->*fp_f2)(0, 0, 0); | ||
|
||
// CST: call void %{{.*}} [ "type"(metadata !"_ZTSFv4Cls1E.generalized") ] | ||
(ObjCls2Ptr->*fp_f3)(Cls1Param); | ||
|
||
// CST: call void %{{.*}} [ "type"(metadata !"_ZTSFv4Cls1E.generalized") ] | ||
(ObjCls2Ptr->*fp_f4)(Cls1Param); | ||
|
||
// CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvPvE.generalized") ] | ||
(ObjCls2Ptr->*fp_f5)(&Cls1Param); | ||
|
||
// CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvPKvE.generalized") ] | ||
(ObjCls2Ptr->*fp_f6)(&Cls1Param); | ||
|
||
// CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvR4Cls1E.generalized") ] | ||
(ObjCls2Ptr->*fp_f7)(Cls1Param); | ||
|
||
// CST: call void %{{.*}} [ "type"(metadata !"_ZTSFvRK4Cls1E.generalized") ] | ||
(ObjCls2Ptr->*fp_f8)(Cls1Param); | ||
|
||
// CST: call void %{{.*}} [ "type"(metadata !"_ZTSKFvvE.generalized") ] | ||
(ObjCls2Ptr->*fp_f9)(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Tests that we assign appropriate identifiers to indirect calls and targets | ||
Prabhuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// specifically for C++ templates. | ||
|
||
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section \ | ||
// 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); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.