miri: fall back to whole-function span when loc==None

This commit is contained in:
Ralf Jung 2020-08-11 12:38:40 +02:00
parent 5154b66586
commit d6c988b3a7
2 changed files with 9 additions and 11 deletions

View File

@ -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<M::PointerTag>) -> PlacePrinter<'a, 'mi
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
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 });
}

View File

@ -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];