-
Notifications
You must be signed in to change notification settings - Fork 16.3k
[clang][DebugInfo] Add virtuality call-site target information in DWARF. #167666
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
Merged
CarlosAlbertoEnciso
merged 4 commits into
llvm:main
from
CarlosAlbertoEnciso:callsite-indirect-calls
Feb 19, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0bc830e
[clang][DebugInfo] Add call site target information in DWARF.
CarlosAlbertoEnciso db78449
[clang][DebugInfo] Add call site target information in DWARF.
CarlosAlbertoEnciso e5bc24c
[clang][DebugInfo] Add virtuality call-site target information in DWARF.
CarlosAlbertoEnciso a8c4df6
[clang][DebugInfo] Add virtuality call-site target information in DWARF.
CarlosAlbertoEnciso 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // RUN: %clang_cc1 -triple=x86_64-linux -disable-llvm-passes -emit-llvm \ | ||
| // RUN: -debug-info-kind=standalone -dwarf-version=5 -O1 %s \ | ||
| // RUN: -o - | FileCheck %s -check-prefix CHECK-BASE | ||
|
|
||
| // Simple class with only virtual methods: inlined and not-inlined | ||
| // | ||
| // The following three scenarios are considered: | ||
| // - out-of-line defined virtual member function (f1) | ||
| // - declared-but-not-defined virtual member function (f2) | ||
| // - inline defined virtual member function (f3) | ||
| // | ||
| // 1) We check for a generated 'call_target' for: 'f1', 'f2' and 'f3'. | ||
| // 2) Check that the 'CBase' type is defined. | ||
|
|
||
| struct CBase { | ||
| virtual void f1(); | ||
| virtual void f2(); | ||
| virtual void f3() {} | ||
| }; | ||
| void CBase::f1() {} | ||
|
|
||
| void bar(CBase *Base) { | ||
| Base->f1(); | ||
| Base->f2(); | ||
| Base->f3(); | ||
|
|
||
| // Because this will instantiate the ctor, the CBase type should be defined. | ||
| CBase B; | ||
| B.f1(); | ||
| } | ||
|
|
||
| // CHECK-BASE: %struct.CBase = type { ptr } | ||
|
|
||
| // CHECK-BASE: define {{.*}} @_Z3barP5CBase{{.*}} { | ||
| // CHECK-BASE: alloca %struct.CBase | ||
| // CHECK-BASE: call void %1{{.*}} !dbg {{![0-9]+}}, !call_target [[BASE_F1_DCL:![0-9]+]] | ||
| // CHECK-BASE: call void %3{{.*}} !dbg {{![0-9]+}}, !call_target [[BASE_F2_DCL:![0-9]+]] | ||
| // CHECK-BASE: call void %5{{.*}} !dbg {{![0-9]+}}, !call_target [[BASE_F3_DCL:![0-9]+]] | ||
| // CHECK-BASE: call void @_ZN5CBaseC1Ev{{.*}} !dbg {{![0-9]+}} | ||
| // CHECK-BASE: call void @_ZN5CBase2f1Ev{{.*}} !dbg {{![0-9]+}} | ||
| // CHECK-BASE: } | ||
|
|
||
| // CHECK-BASE: [[BASE_F1_DCL]] = {{.*}}!DISubprogram(name: "f1", linkageName: "_ZN5CBase2f1Ev", {{.*}}containingType | ||
| // CHECK-BASE: [[BASE_F2_DCL]] = {{.*}}!DISubprogram(name: "f2", linkageName: "_ZN5CBase2f2Ev", {{.*}}containingType | ||
| // CHECK-BASE: [[BASE_F3_DCL]] = {{.*}}!DISubprogram(name: "f3", linkageName: "_ZN5CBase2f3Ev", {{.*}}containingType | ||
|
|
||
| // CHECK-BASE: [[BASE_F1_DEF:![0-9]+]] = {{.*}}!DISubprogram(name: "f1", linkageName: "_ZN5CBase2f1Ev", {{.*}}DISPFlagDefinition | ||
| // CHECK-BASE: [[BASE_F3_DEF:![0-9]+]] = {{.*}}!DISubprogram(name: "f3", linkageName: "_ZN5CBase2f3Ev", {{.*}}DISPFlagDefinition |
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,58 @@ | ||
| // RUN: %clang_cc1 -triple=x86_64-linux -disable-llvm-passes -emit-llvm \ | ||
| // RUN: -debug-info-kind=constructor -dwarf-version=5 -O1 %s \ | ||
| // RUN: -o - | FileCheck %s -check-prefix CHECK-DERIVED | ||
|
|
||
| // Simple base and derived class with virtual and static methods: | ||
| // We check for: | ||
| // - a generated 'call_target' for 'f1'. | ||
| // - not generated 'call_target' for 'f3'. | ||
|
|
||
| struct CBase { | ||
| virtual void f1() {} | ||
| static void f3(); | ||
| }; | ||
|
|
||
| void CBase::f3() { | ||
| } | ||
|
|
||
| void foo(CBase *Base) { | ||
| CBase::f3(); | ||
| } | ||
|
|
||
| struct CDerived : public CBase { | ||
| void f1() {} | ||
| }; | ||
| void foo(CDerived *Derived); | ||
|
|
||
| int main() { | ||
| CDerived D; | ||
| foo(&D); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| void foo(CDerived *Derived) { | ||
| Derived->f1(); | ||
| } | ||
|
|
||
| // CHECK-DERIVED: define {{.*}} @_Z3fooP5CBase{{.*}} { | ||
| // CHECK-DERIVED: call void @_ZN5CBase2f3Ev{{.*}} !dbg {{![0-9]+}} | ||
| // CHECK-DERIVED: } | ||
|
|
||
| // CHECK-DERIVED: define {{.*}} @main{{.*}} { | ||
| // CHECK-DERIVED: call void @_ZN8CDerivedC1Ev{{.*}} !dbg {{![0-9]+}} | ||
| // CHECK-DERIVED: call void @_Z3fooP8CDerived{{.*}} !dbg {{![0-9]+}} | ||
| // CHECK-DERIVED: } | ||
|
|
||
| // CHECK-DERIVED: define {{.*}} @_ZN8CDerivedC1Ev{{.*}} { | ||
| // CHECK-DERIVED: call void @_ZN8CDerivedC2Ev{{.*}} !dbg {{![0-9]+}} | ||
| // CHECK-DERIVED: } | ||
|
|
||
| // CHECK-DERIVED: define {{.*}} @_Z3fooP8CDerived{{.*}} { | ||
| // CHECK-DERIVED: call void %1{{.*}} !dbg {{![0-9]+}}, !call_target [[DERIVED_F1_DCL:![0-9]+]] | ||
| // CHECK-DERIVED: } | ||
|
|
||
| // CHECK-DERIVED: [[BASE_F1_DCL:![0-9]+]] = {{.*}}!DISubprogram(name: "f1", linkageName: "_ZN5CBase2f1Ev", {{.*}}containingType | ||
| // CHECK-DERIVED: [[DERIVED_F1_DCL]] = {{.*}}!DISubprogram(name: "f1", linkageName: "_ZN8CDerived2f1Ev", {{.*}}containingType | ||
| // CHECK-DERIVED: [[DERIVED_F1_DEF:![0-9]+]] = {{.*}}!DISubprogram(name: "f1", linkageName: "_ZN8CDerived2f1Ev", {{.*}}DISPFlagDefinition | ||
| // CHECK-DERIVED: [[BASE_F1_DEF:![0-9]+]] = {{.*}}!DISubprogram(name: "f1", linkageName: "_ZN5CBase2f1Ev", {{.*}}DISPFlagDefinition |
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,93 @@ | ||
| // RUN: %clang_cc1 -triple=x86_64-linux -disable-llvm-passes -emit-llvm \ | ||
| // RUN: -debug-info-kind=constructor -dwarf-version=5 -O1 %s \ | ||
| // RUN: -o - | FileCheck %s -check-prefix CHECK-EDGES | ||
|
|
||
| // The following are identified edge cases involving the method being called: | ||
| // 1) Method is declared but not defined in current CU. | ||
| // 2) Pure virtual method but not defined in current CU. | ||
| // 3) Virtual method defined in a deeply nested structure hierarchy. | ||
|
|
||
| //--------------------------------------------------------------------- | ||
| // 1) Method is declared but not defined in current CU - Pass. | ||
| // Generate 'call_target' metadata for 'f1' and 'f2'. | ||
| //--------------------------------------------------------------------- | ||
| struct CEmpty { | ||
| virtual void f1(); | ||
| virtual void f2(); | ||
| }; | ||
|
|
||
| void CEmpty::f2() { | ||
| } | ||
|
|
||
| void edge_a(CEmpty *Empty) { | ||
| Empty->f1(); | ||
| Empty->f2(); | ||
| } | ||
|
|
||
| //--------------------------------------------------------------------- | ||
| // 2) Pure virtual method but not defined in current CU - Pass. | ||
| // Generate 'call_target' metadata for 'f1' and 'f2'. | ||
| //--------------------------------------------------------------------- | ||
| struct CBase { | ||
| virtual void f1() = 0; | ||
| virtual void f2(); | ||
| }; | ||
|
|
||
| void CBase::f2() { | ||
| } | ||
|
|
||
| void edge_b(CBase *Base) { | ||
| Base->f1(); | ||
| Base->f2(); | ||
| } | ||
|
|
||
| //--------------------------------------------------------------------- | ||
| // 3) Virtual method defined in a deeply nested structure hierarchy - Pass. | ||
| // Generate 'call_target' metadata for 'd0', 'd1', 'd2' and 'd3'. | ||
| //--------------------------------------------------------------------- | ||
| struct CD0 { | ||
| struct CD1 { | ||
| virtual void d1(); | ||
| }; | ||
|
|
||
| CD1 D1; | ||
| virtual void d0(); | ||
| }; | ||
|
|
||
| void CD0::d0() {} | ||
| void CD0::CD1::d1() {} | ||
|
|
||
| void edge_c(CD0 *D0) { | ||
| D0->d0(); | ||
|
|
||
| CD0::CD1 *D1 = &D0->D1; | ||
| D1->d1(); | ||
| } | ||
|
|
||
| // CHECK-EDGES: define {{.*}} @_Z6edge_aP6CEmpty{{.*}} { | ||
| // CHECK-EDGES: call void %1{{.*}} !dbg {{![0-9]+}}, !call_target [[CEMPTY_F1_DCL:![0-9]+]] | ||
| // CHECK-EDGES: call void %3{{.*}} !dbg {{![0-9]+}}, !call_target [[CEMPTY_F2_DCL:![0-9]+]] | ||
| // CHECK-EDGES: } | ||
|
|
||
| // CHECK-EDGES: define {{.*}} @_Z6edge_bP5CBase{{.*}} { | ||
| // CHECK-EDGES: call void %1{{.*}} !dbg {{![0-9]+}}, !call_target [[CBASE_F1_DCL:![0-9]+]] | ||
| // CHECK-EDGES: call void %3{{.*}} !dbg {{![0-9]+}}, !call_target [[CBASE_F2_DCL:![0-9]+]] | ||
| // CHECK-EDGES: } | ||
|
|
||
| // CHECK-EDGES: define {{.*}} @_Z6edge_cP3CD0{{.*}} { | ||
| // CHECK-EDGES: call void %1{{.*}} !dbg {{![0-9]+}}, !call_target [[CD0_D0_DCL:![0-9]+]] | ||
| // CHECK-EDGES: call void %4{{.*}} !dbg {{![0-9]+}}, !call_target [[CD0_D1_DCL:![0-9]+]] | ||
| // CHECK-EDGES: } | ||
|
|
||
| // CHECK-EDGES: [[CD0_D1_DCL]] = {{.*}}!DISubprogram(name: "d1", linkageName: "_ZN3CD03CD12d1Ev", {{.*}}containingType | ||
| // CHECK-EDGES: [[CD0_D0_DCL]] = {{.*}}!DISubprogram(name: "d0", linkageName: "_ZN3CD02d0Ev", {{.*}}containingType | ||
|
|
||
| // CHECK-EDGES: [[CBASE_F1_DCL]] = {{.*}}!DISubprogram(name: "f1", linkageName: "_ZN5CBase2f1Ev", {{.*}}containingType | ||
| // CHECK-EDGES: [[CBASE_F2_DCL]] = {{.*}}!DISubprogram(name: "f2", linkageName: "_ZN5CBase2f2Ev", {{.*}}containingType | ||
| // CHECK-EDGES: [[CEMPTY_F2_DEF:![0-9]+]] = {{.*}}!DISubprogram(name: "f2", linkageName: "_ZN6CEmpty2f2Ev", {{.*}}DISPFlagDefinition | ||
| // CHECK-EDGES: [[CEMPTY_F2_DCL]] = {{.*}}!DISubprogram(name: "f2", linkageName: "_ZN6CEmpty2f2Ev", {{.*}}containingType | ||
| // CHECK-EDGES: [[CEMPTY_F1_DCL]] = {{.*}}!DISubprogram(name: "f1", linkageName: "_ZN6CEmpty2f1Ev", {{.*}}containingType | ||
| // CHECK-EDGES: [[CBASE_F2_DEF:![0-9]+]] = {{.*}}!DISubprogram(name: "f2", linkageName: "_ZN5CBase2f2Ev", {{.*}}DISPFlagDefinition | ||
|
|
||
| // CHECK-EDGES: [[CD0_D0_DEF:![0-9]+]] = {{.*}}!DISubprogram(name: "d0", linkageName: "_ZN3CD02d0Ev", {{.*}}DISPFlagDefinition | ||
| // CHECK-EDGES: [[CD0_D1_DEF:![0-9]+]] = {{.*}}!DISubprogram(name: "d1", linkageName: "_ZN3CD03CD12d1Ev", {{.*}}DISPFlagDefinition |
71 changes: 71 additions & 0 deletions
71
cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/callsite-dwarf.cpp
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,71 @@ | ||
| // RUN: %clang --target=x86_64-unknown-linux -c -g -O1 %s -o - | \ | ||
| // RUN: llvm-dwarfdump --debug-info - | FileCheck %s --check-prefix=CHECK | ||
|
|
||
| // Simple base and derived class with virtual: | ||
| // We check for a generated 'DW_AT_LLVM_virtual_call_origin' for 'foo', that | ||
| // corresponds to the 'call_target' metadata added to the indirect call | ||
| // instruction. | ||
|
|
||
| // Note: We should add a test case inside LLDB that make use of the | ||
| // virtuality call-site target information in DWARF. | ||
|
|
||
| struct CBaseOne { | ||
| virtual void foo(int &); | ||
| }; | ||
|
|
||
| struct CDerivedOne : CBaseOne { | ||
| void foo(int &); | ||
| }; | ||
|
|
||
| void CDerivedOne::foo(int &) {} | ||
|
|
||
| struct CBaseTwo { | ||
| CDerivedOne *DerivedOne; | ||
| }; | ||
|
|
||
| struct CDerivedTwo : CBaseTwo { | ||
| void bar(int &); | ||
| }; | ||
|
|
||
| void CDerivedTwo::bar(int &j) { DerivedOne->foo(j); } | ||
|
|
||
| // The IR generated looks like: | ||
| // | ||
| // define dso_local void @_ZN11CDerivedTwo3barERi(...) !dbg !40 { | ||
| // entry: | ||
| // .. | ||
| // %vtable = load ptr, ptr %0, align 8 | ||
| // %vfn = getelementptr inbounds ptr, ptr %vtable, i64 0 | ||
| // %2 = load ptr, ptr %vfn, align 8 | ||
| // call void %2(...), !dbg !65, !call_target !25 | ||
| // ret void | ||
| // } | ||
| // | ||
| // !25 = !DISubprogram(name: "foo", linkageName: "_ZN11CDerivedOne3fooERi", ...) | ||
| // !40 = !DISubprogram(name: "bar", linkageName: "_ZN11CDerivedTwo3barERi", ...) | ||
| // !65 = !DILocation(line: 25, column: 15, scope: !40) | ||
|
|
||
| // CHECK: DW_TAG_compile_unit | ||
| // CHECK: DW_TAG_structure_type | ||
| // CHECK: DW_AT_name ("CDerivedOne") | ||
| // CHECK: [[FOO_DCL:0x[a-f0-9]+]]: DW_TAG_subprogram | ||
| // CHECK: DW_AT_name ("foo") | ||
| // CHECK: DW_TAG_structure_type | ||
| // CHECK: DW_AT_name ("CBaseOne") | ||
| // CHECK: [[FOO_DEF:0x[a-f0-9]+]]: DW_TAG_subprogram | ||
| // CHECK: DW_AT_call_all_calls (true) | ||
| // CHECK: DW_AT_specification ([[FOO_DCL]] "{{.*}}foo{{.*}}") | ||
| // CHECK: DW_TAG_structure_type | ||
| // CHECK: DW_AT_name ("CDerivedTwo") | ||
| // CHECK: DW_TAG_subprogram | ||
| // CHECK: DW_AT_name ("bar") | ||
| // CHECK: DW_TAG_structure_type | ||
| // CHECK: DW_AT_name ("CBaseTwo") | ||
| // CHECK: DW_TAG_subprogram | ||
| // CHECK: DW_AT_call_all_calls (true) | ||
| // CHECK: DW_AT_specification (0x{{.*}} "{{.*}}bar{{.*}}") | ||
| // CHECK: DW_TAG_call_site | ||
| // CHECK: DW_AT_call_target_clobbered (DW_OP_reg0 RAX) | ||
| // CHECK: DW_AT_call_tail_call (true) | ||
| // CHECK: DW_AT_call_pc (0x{{.*}}) | ||
| // CHECK: DW_AT_LLVM_virtual_call_origin ([[FOO_DCL]] "{{.*}}foo{{.*}}") | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this feature has sufficient cross-project complexity to justify a cross-project-test for it... but shrug don't feel /super/ strongly about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felipepiovezan Any thoughts on this? Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'd be more interested in seeing a test case later inside LLDB to make use of this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will keep the test case, but added the following note: