From d6c988b3a74ff769d742a1ee16442a56579cf53b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 11 Aug 2020 12:38:40 +0200 Subject: [PATCH] miri: fall back to whole-function span when loc==None --- src/librustc_mir/interpret/eval_context.rs | 17 ++++++++--------- .../interpret/intrinsics/caller_location.rs | 3 +-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 669aecc27ca..32018ddb13f 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -16,7 +16,7 @@ use rustc_middle::ty::{ self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, }; -use rustc_span::{source_map::DUMMY_SP, Pos, Span}; +use rustc_span::{Pos, Span}; use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size, TargetDataLayout}; use super::{ @@ -191,6 +191,10 @@ impl<'mir, 'tcx, Tag, Extra> Frame<'mir, 'tcx, Tag, Extra> { pub fn current_source_info(&self) -> Option<&mir::SourceInfo> { self.loc.map(|loc| self.body.source_info(loc)) } + + pub fn current_span(&self) -> Span { + self.current_source_info().map(|si| si.span).unwrap_or(self.body.span) + } } impl<'tcx> fmt::Display for FrameInfo<'tcx> { @@ -324,11 +328,7 @@ pub fn new( #[inline(always)] pub fn cur_span(&self) -> Span { - self.stack() - .last() - .and_then(|f| f.current_source_info()) - .map(|si| si.span) - .unwrap_or(self.tcx.span) + self.stack().last().map(|f| f.current_span()).unwrap_or(self.tcx.span) } #[inline(always)] @@ -921,14 +921,13 @@ pub fn dump_place(&'a self, place: Place) -> PlacePrinter<'a, 'mi pub fn generate_stacktrace(&self) -> Vec> { let mut frames = Vec::new(); for frame in self.stack().iter().rev() { - let source_info = frame.current_source_info(); - let lint_root = source_info.and_then(|source_info| { + let lint_root = frame.current_source_info().and_then(|source_info| { match &frame.body.source_scopes[source_info.scope].local_data { mir::ClearCrossCrate::Set(data) => Some(data.lint_root), mir::ClearCrossCrate::Clear => None, } }); - let span = source_info.map_or(DUMMY_SP, |source_info| source_info.span); + let span = frame.current_span(); frames.push(FrameInfo { span, instance: frame.instance, lint_root }); } diff --git a/src/librustc_mir/interpret/intrinsics/caller_location.rs b/src/librustc_mir/interpret/intrinsics/caller_location.rs index 9adef8c43c7..74cb7f6fc5f 100644 --- a/src/librustc_mir/interpret/intrinsics/caller_location.rs +++ b/src/librustc_mir/interpret/intrinsics/caller_location.rs @@ -30,8 +30,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Assert that there is always such a frame. .unwrap(); // Assert that the frame we look at is actually executing code currently - // (`current_source_info` is None when we are unwinding and the frame does - // not require cleanup). + // (`loc` is None when we are unwinding and the frame does not require cleanup). let loc = frame.loc.unwrap(); // If this is a `Call` terminator, use the `fn_span` instead. let block = &frame.body.basic_blocks()[loc.block];