-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[DebugInfo][DWARF] Add heapallocsite information #132073
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
+60
−18
Merged
Changes from all commits
Commits
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,34 @@ | ||
; RUN: llc -O3 -o %t -filetype=obj %s | ||
; RUN: llvm-dwarfdump %t | FileCheck %s | ||
|
||
; based on clang++ output for `int *alloc_int() { return new int; }` | ||
|
||
|
||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
define dso_local ptr @alloc_int() !dbg !3 { | ||
; CHECK: DW_TAG_subprogram | ||
entry: | ||
%call = call ptr @alloc(i64 noundef 4), !heapallocsite !7 | ||
; CHECK: DW_TAG_call_site | ||
; CHECK: DW_AT_LLVM_alloc_type ([[ALLOCSITE:.*]]) | ||
ret ptr %call | ||
} | ||
|
||
; CHECK: {{.*}}[[ALLOCSITE]]: DW_TAG_base_type | ||
; CHECK: DW_AT_name ("int") | ||
|
||
declare dso_local ptr @alloc(i64 noundef) | ||
|
||
!llvm.dbg.cu = !{!0} | ||
!llvm.module.flags = !{!2,!8} | ||
|
||
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, emissionKind: FullDebug) | ||
!1 = !DIFile(filename: "a.cpp", directory: "/") | ||
!2 = !{i32 2, !"Debug Info Version", i32 3} | ||
!3 = distinct !DISubprogram(name: "alloc_int", scope: !1, file: !1, line: 1, type: !4, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition, unit: !0) | ||
!4 = !DISubroutineType(types: !5) | ||
!5 = !{!6} | ||
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64) | ||
!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) | ||
!8 = !{i32 2, !"Dwarf Version", i32 5} |
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.
Are these conditions tested?
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.
The four cases that could be tested here are basically:
DW_TAG_call_site
DW_TAG_call_site
DW_TAG_call_site
call [rax]
on X86 in Intel syntax) has noDW_TAG_call_site
Case 1 is covered by tests like
./llvm/test/DebugInfo/X86/dwarf-callsite-related-attrs.ll
, for example in function_Z3foov
.Case 2 is (bogusly) covered by the same file, function
main
(with theindirect_target
call); pull request #151378 adds a proper test.Case 3 is covered by the test I added.
Case 4 is a size optimization that only happens when LLVM gives up on emitting DWARF for complex calls. It is not currently tested, from what I can tell; pull request #151378 adds a proper test. Most ways that should end up in case 4 have been very broken at least on X86 for years. The main thing I noticed is that when LLVM is generating something like
call [rax]
, it emits debuginfo claiming that the target address is stored in RAX because the only difference at the MIR level betweencall rax
andcall [rax]
is which call opcode is used (CALL64r
vsCALL64m
), and the generic MIR code considers both of these to have akRegister
operand even though the X86 code treats them differently (OperandType::TYPE_R64
vsOperandType::TYPE_M
). On top of that, another bug is that offsets are also ignored (#70949). Due to these bugs, we probably almost never actually hit thiscontinue
- the only way I managed to make that happen on x86 is by compiling this with-m32
, to generate a call with unknown destination that has no registers involved:I think if we want to have nice tests for cases 2 and 4, it would make sense to fix the handling of
call [rax]
first, so that we can for now test thatcall rax
has callsite info whilecall [rax]
doesn't (until someone comes along and adds support for that, then I guess we'd have to come up with a new way to test it). (Or I guess alternatively one could make an argument that we should remove this branch entirely and accept that we're generating useless callsite tags sometimes.)I have created PR #151378 to remove the broken DWARF for
call [rax]
.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.
(And once that PR lands, I'll have to rebase this change.)