Skip to content

Commit 8c3a8f8

Browse files
committed
Keep inlined var_debug_info only when full debug info is used
1 parent 34d24ec commit 8c3a8f8

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
1515
use rustc_middle::mir::visit::*;
1616
use rustc_middle::mir::*;
1717
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt, TypeFlags, TypeVisitableExt};
18-
use rustc_session::config::{DebugInfo, OptLevel};
18+
use rustc_session::config::OptLevel;
1919
use rustc_span::source_map::Spanned;
2020
use tracing::{debug, instrument, trace, trace_span};
2121

@@ -982,16 +982,7 @@ 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-
if tcx
986-
.sess
987-
.opts
988-
.unstable_opts
989-
.inline_mir_preserve_debug
990-
.unwrap_or(tcx.sess.opts.debuginfo != DebugInfo::None)
991-
{
992-
// Note that we need to preserve these in the standard library so that
993-
// people working on rust can build with or without debuginfo while
994-
// still getting consistent results from the mir-opt tests.
985+
if tcx.sess.keep_var_debug_info() {
995986
caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
996987
}
997988
caller_body.basic_blocks_mut().append(callee_body.basic_blocks_mut());

compiler/rustc_session/src/session.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,18 @@ impl Session {
765765
.unwrap_or(self.target.default_dwarf_version)
766766
}
767767

768+
/// Whether to maintain `Body.var_debug_info` that keeps track where variables were declared
769+
pub fn keep_var_debug_info(&self) -> bool {
770+
// -Zinline-mir-preserve-debug is enabled when building the standard library, so that
771+
// people working on rust can build with or without debuginfo while
772+
// still getting consistent results from the mir-opt tests.
773+
self.opts
774+
.unstable_opts
775+
.inline_mir_preserve_debug
776+
// only "full" promises any variable-level information
777+
.unwrap_or(self.opts.debuginfo == DebugInfo::Full)
778+
}
779+
768780
pub fn stack_protector(&self) -> StackProtector {
769781
if self.target.options.supports_stack_protector {
770782
self.opts.unstable_opts.stack_protector

0 commit comments

Comments
 (0)