Skip to content

Commit 2f16030

Browse files
Rollup merge of #154200 - resrever:enable-dwarf-call-sites, r=dingxiangfei2009
debuginfo: emit DW_TAG_call_site entries Set `FlagAllCallsDescribed` on function definition DIEs so LLVM emits DW_TAG_call_site entries, letting debuggers and analysis tools track tail calls.
2 parents 6e3c174 + 9677d7a commit 2f16030

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

‎compiler/rustc_codegen_llvm/src/debuginfo/mod.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
471471
// FIXME(eddyb) does this need to be separate from `loc.line` for some reason?
472472
let scope_line = loc.line;
473473

474-
let mut flags = DIFlags::FlagPrototyped;
474+
let mut flags = DIFlags::FlagPrototyped | DIFlags::FlagAllCallsDescribed;
475475

476476
if fn_abi.ret.layout.is_uninhabited() {
477477
flags |= DIFlags::FlagNoReturn;
@@ -494,6 +494,9 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
494494
// LLVM LTO can't unify type definitions when a child DIE is a full subprogram definition.
495495
// When we use this `decl` below, the subprogram definition gets created at the CU level
496496
// with a DW_AT_specification pointing back to the type's declaration.
497+
// FlagAllCallsDescribed cannot appear on the method declaration DIE
498+
// because it has no body, which LLVM's verifier rejects.
499+
let decl_flags = flags & !DIFlags::FlagAllCallsDescribed;
497500
let decl = is_method.then(|| unsafe {
498501
llvm::LLVMRustDIBuilderCreateMethod(
499502
DIB(self),
@@ -505,7 +508,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
505508
file_metadata,
506509
loc.line,
507510
function_type_metadata,
508-
flags,
511+
decl_flags,
509512
spflags & !DISPFlags::SPFlagDefinition,
510513
template_parameters,
511514
)

‎compiler/rustc_codegen_llvm/src/llvm/ffi.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ pub(crate) mod debuginfo {
781781
const FlagNonTrivial = (1 << 26);
782782
const FlagBigEndian = (1 << 27);
783783
const FlagLittleEndian = (1 << 28);
784+
const FlagAllCallsDescribed = (1 << 29);
784785
}
785786
}
786787

‎compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ ASSERT_DIFLAG_VALUE(FlagThunk, 1 << 25);
779779
ASSERT_DIFLAG_VALUE(FlagNonTrivial, 1 << 26);
780780
ASSERT_DIFLAG_VALUE(FlagBigEndian, 1 << 27);
781781
ASSERT_DIFLAG_VALUE(FlagLittleEndian, 1 << 28);
782+
static_assert(DINode::DIFlags::FlagAllCallsDescribed == (1 << 29));
782783
ASSERT_DIFLAG_VALUE(FlagIndirectVirtualBase, (1 << 2) | (1 << 5));
783784
#undef ASSERT_DIFLAG_VALUE
784785

@@ -791,7 +792,7 @@ ASSERT_DIFLAG_VALUE(FlagIndirectVirtualBase, (1 << 2) | (1 << 5));
791792
// to copying each bit/subvalue.
792793
static DINode::DIFlags fromRust(LLVMDIFlags Flags) {
793794
// Check that all set bits are covered by the static assertions above.
794-
const unsigned UNKNOWN_BITS = (1 << 31) | (1 << 30) | (1 << 29) | (1 << 21);
795+
const unsigned UNKNOWN_BITS = (1 << 31) | (1 << 30) | (1 << 21);
795796
if (Flags & UNKNOWN_BITS) {
796797
report_fatal_error("bad LLVMDIFlags");
797798
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Check that DIFlagAllCallsDescribed is set on subprogram definitions.
2+
3+
//@ ignore-msvc (CodeView does not use DIFlagAllCallsDescribed)
4+
//@ compile-flags: -C debuginfo=2 -C opt-level=1 -C no-prepopulate-passes
5+
6+
// CHECK: {{.*}}DISubprogram{{.*}}name: "foo"{{.*}}DIFlagAllCallsDescribed{{.*}}
7+
8+
#[no_mangle]
9+
#[inline(never)]
10+
pub fn foo(x: i32) -> i32 {
11+
bar(x + 1)
12+
}
13+
14+
#[no_mangle]
15+
#[inline(never)]
16+
pub fn bar(x: i32) -> i32 {
17+
x * 2
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)