From e43a00e6759ed81edc488dbfd08406a1e8190011 Mon Sep 17 00:00:00 2001 From: Kornel Date: Sun, 22 Jun 2025 21:31:22 +0100 Subject: [PATCH 1/2] Test MIR inlined var debug info --- tests/mir-opt/inline_var_debug_info_kept.rs | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/mir-opt/inline_var_debug_info_kept.rs diff --git a/tests/mir-opt/inline_var_debug_info_kept.rs b/tests/mir-opt/inline_var_debug_info_kept.rs new file mode 100644 index 0000000000000..e2f00fc6ee929 --- /dev/null +++ b/tests/mir-opt/inline_var_debug_info_kept.rs @@ -0,0 +1,50 @@ +//@ test-mir-pass: Inline +//@ revisions: PRESERVE FULL NONE LIMITED +//@ [PRESERVE]compile-flags: -O -C debuginfo=0 -Zinline-mir-preserve-debug +//@ [FULL]compile-flags: -O -C debuginfo=2 +//@ [NONE]compile-flags: -O -C debuginfo=0 +//@ [LIMITED]compile-flags: -O -C debuginfo=1 + +#[inline(always)] +fn inline_fn1(arg1: i32) -> i32 { + let local1 = arg1 + 1; + let _local2 = 10; + arg1 + local1 +} + +#[inline(always)] +fn inline_fn2(binding: i32) -> i32 { + { + let binding = inline_fn1(binding); + binding + } +} + +#[inline(never)] +fn test() -> i32 { + // CHECK-LABEL: fn test + inline_fn2(1) + // CHECK-LABEL: (inlined inline_fn2) + + // PRESERVE: debug binding => + // FULL: debug binding => + // NONE-NOT: debug binding => + // LIMITED-NOT: debug binding => + + // CHECK-LABEL: (inlined inline_fn1) + + // PRESERVE: debug arg1 => + // FULL: debug arg1 => + // NONE-NOT: debug arg1 => + // LIMITED-NOT: debug arg1 => + + // PRESERVE: debug local1 => + // FULL: debug local1 => + // NONE-NOT: debug local1 => + // LIMITED-NOT: debug local1 => + + // PRESERVE: debug _local2 => + // FULL: debug _local2 => + // NONE-NOT: debug _local2 => + // LIMITED-NOT: debug _local2 => +} From b7eaae1d5175b8b7b2d7bbca6c85469f2d546a6f Mon Sep 17 00:00:00 2001 From: Kornel Date: Sat, 8 Feb 2025 01:33:38 +0000 Subject: [PATCH 2/2] Keep inlined var_debug_info only when full debug info is used --- compiler/rustc_mir_transform/src/inline.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index f48dba9663a52..9e8d5a6bffc7c 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -987,9 +987,10 @@ fn inline_call<'tcx, I: Inliner<'tcx>>( .opts .unstable_opts .inline_mir_preserve_debug - .unwrap_or(tcx.sess.opts.debuginfo != DebugInfo::None) + // only "full" promises any variable-level information + .unwrap_or(self.opts.debuginfo == DebugInfo::Full) { - // Note that we need to preserve these in the standard library so that + // -Zinline-mir-preserve-debug is enabled when building the standard library, so that // people working on rust can build with or without debuginfo while // still getting consistent results from the mir-opt tests. caller_body.var_debug_info.append(&mut callee_body.var_debug_info);