Skip to content

Commit 1af0e6e

Browse files
authored
Rollup merge of #126365 - Dirbaio:collapse-debuginfo-statics, r=workingjubilee
Honor collapse_debuginfo for statics. fixes #126363 <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> -->
2 parents a033dab + b89a0a7 commit 1af0e6e

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_middle::ty::{
3636
};
3737
use rustc_session::config::{self, DebugInfo, Lto};
3838
use rustc_span::symbol::Symbol;
39-
use rustc_span::FileName;
39+
use rustc_span::{hygiene, FileName, DUMMY_SP};
4040
use rustc_span::{FileNameDisplayPreference, SourceFile};
4141
use rustc_symbol_mangling::typeid_for_trait_ref;
4242
use rustc_target::abi::{Align, Size};
@@ -1306,7 +1306,7 @@ pub fn build_global_var_di_node<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId, glo
13061306
// We may want to remove the namespace scope if we're in an extern block (see
13071307
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952).
13081308
let var_scope = get_namespace_for_item(cx, def_id);
1309-
let span = tcx.def_span(def_id);
1309+
let span = hygiene::walk_chain_collapsed(tcx.def_span(def_id), DUMMY_SP);
13101310

13111311
let (file_metadata, line_number) = if !span.is_dummy() {
13121312
let loc = cx.lookup_debug_loc(span.lo());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ ignore-lldb
2+
3+
// Test that static debug info is not collapsed with #[collapse_debuginfo(external)]
4+
5+
//@ compile-flags:-g
6+
7+
// === GDB TESTS ===================================================================================
8+
9+
// gdb-command:info line collapse_debuginfo_static_external::FOO
10+
// gdb-check:[...]Line 15[...]
11+
12+
#[collapse_debuginfo(external)]
13+
macro_rules! decl_foo {
14+
() => {
15+
static FOO: u32 = 0;
16+
};
17+
}
18+
19+
decl_foo!();
20+
21+
fn main() {
22+
// prevent FOO from getting optimized out
23+
std::hint::black_box(&FOO);
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ ignore-lldb
2+
3+
// Test that static debug info is collapsed with #[collapse_debuginfo(yes)]
4+
5+
//@ compile-flags:-g
6+
7+
// === GDB TESTS ===================================================================================
8+
9+
// gdb-command:info line collapse_debuginfo_static::FOO
10+
// gdb-check:[...]Line 19[...]
11+
12+
#[collapse_debuginfo(yes)]
13+
macro_rules! decl_foo {
14+
() => {
15+
static FOO: u32 = 0;
16+
};
17+
}
18+
19+
decl_foo!();
20+
21+
fn main() {
22+
// prevent FOO from getting optimized out
23+
std::hint::black_box(&FOO);
24+
}

0 commit comments

Comments
 (0)