Skip to content

Commit 837c5dd

Browse files
committed
Auto merge of #142890 - kornelski:unused-var-debug, r=saethlin
MIR inliner maintains unused var_debug_info Only `full` debuginfo level promises variable-level debug information, but the MIR inline pass needlessly preserved the local variable debug info for the `limited` level too.
2 parents da58c05 + c9ef116 commit 837c5dd

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,14 +982,16 @@ fn inline_call<'tcx, I: Inliner<'tcx>>(
982982
// Insert all of the (mapped) parts of the callee body into the caller.
983983
caller_body.local_decls.extend(callee_body.drain_vars_and_temps());
984984
caller_body.source_scopes.append(&mut callee_body.source_scopes);
985+
986+
// only "full" debug promises any variable-level information
985987
if tcx
986988
.sess
987989
.opts
988990
.unstable_opts
989991
.inline_mir_preserve_debug
990-
.unwrap_or(tcx.sess.opts.debuginfo != DebugInfo::None)
992+
.unwrap_or(tcx.sess.opts.debuginfo == DebugInfo::Full)
991993
{
992-
// Note that we need to preserve these in the standard library so that
994+
// -Zinline-mir-preserve-debug is enabled when building the standard library, so that
993995
// people working on rust can build with or without debuginfo while
994996
// still getting consistent results from the mir-opt tests.
995997
caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//@ test-mir-pass: Inline
2+
//@ revisions: PRESERVE FULL NONE LIMITED
3+
//@ [PRESERVE]compile-flags: -O -C debuginfo=0 -Zinline-mir-preserve-debug
4+
//@ [FULL]compile-flags: -O -C debuginfo=2
5+
//@ [NONE]compile-flags: -O -C debuginfo=0
6+
//@ [LIMITED]compile-flags: -O -C debuginfo=1
7+
8+
#[inline(always)]
9+
fn inline_fn1(arg1: i32) -> i32 {
10+
let local1 = arg1 + 1;
11+
let _local2 = 10;
12+
arg1 + local1
13+
}
14+
15+
#[inline(always)]
16+
fn inline_fn2(binding: i32) -> i32 {
17+
{
18+
let binding = inline_fn1(binding);
19+
binding
20+
}
21+
}
22+
23+
#[inline(never)]
24+
fn test() -> i32 {
25+
// CHECK-LABEL: fn test
26+
inline_fn2(1)
27+
// CHECK-LABEL: (inlined inline_fn2)
28+
29+
// PRESERVE: debug binding =>
30+
// FULL: debug binding =>
31+
// NONE-NOT: debug binding =>
32+
// LIMITED-NOT: debug binding =>
33+
34+
// CHECK-LABEL: (inlined inline_fn1)
35+
36+
// PRESERVE: debug arg1 =>
37+
// FULL: debug arg1 =>
38+
// NONE-NOT: debug arg1 =>
39+
// LIMITED-NOT: debug arg1 =>
40+
41+
// PRESERVE: debug local1 =>
42+
// FULL: debug local1 =>
43+
// NONE-NOT: debug local1 =>
44+
// LIMITED-NOT: debug local1 =>
45+
46+
// PRESERVE: debug _local2 =>
47+
// FULL: debug _local2 =>
48+
// NONE-NOT: debug _local2 =>
49+
// LIMITED-NOT: debug _local2 =>
50+
}

0 commit comments

Comments
 (0)