Auto merge of #1283 - RalfJung:backtrace, r=RalfJung
Make backtrace function names and spans match up This is the Miri side of https://github.com/rust-lang/rust/pull/70590. Fixes https://github.com/rust-lang/miri/issues/521
This commit is contained in:
commit
ed1432862a
@ -1 +1 @@
|
||||
235938d1acdd93d6641a741c81f64e415b786751
|
||||
b793f403bdfbcc0ff3e15ed8177a81d79ba4a29b
|
||||
|
@ -129,15 +129,12 @@ fn report_msg<'tcx, 'mir>(
|
||||
err.help(help);
|
||||
}
|
||||
// Add backtrace
|
||||
let frames = ecx.generate_stacktrace(None);
|
||||
// We iterate with indices because we need to look at the next frame (the caller).
|
||||
for idx in 0..frames.len() {
|
||||
let frame_info = &frames[idx];
|
||||
let call_site_is_local = frames
|
||||
.get(idx + 1)
|
||||
.map_or(false, |caller_info| caller_info.instance.def_id().is_local());
|
||||
if call_site_is_local {
|
||||
err.span_note(frame_info.call_site, &frame_info.to_string());
|
||||
let frames = ecx.generate_stacktrace();
|
||||
for (idx, frame_info) in frames.iter().enumerate() {
|
||||
let is_local = frame_info.instance.def_id().is_local();
|
||||
// No span for non-local frames and the first frame (which is the error site).
|
||||
if is_local && idx > 0 {
|
||||
err.span_note(frame_info.span, &frame_info.to_string());
|
||||
} else {
|
||||
err.note(&frame_info.to_string());
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ use rustc_middle::ty::{
|
||||
List, TyCtxt,
|
||||
};
|
||||
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
|
||||
use rand::RngCore;
|
||||
|
||||
@ -170,13 +169,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
|
||||
// Push frame.
|
||||
let mir = &*this.load_mir(f.def, None)?;
|
||||
let span = this
|
||||
.stack()
|
||||
.last()
|
||||
.and_then(Frame::current_source_info)
|
||||
.map(|si| si.span)
|
||||
.unwrap_or(DUMMY_SP);
|
||||
this.push_stack_frame(f, span, mir, dest, stack_pop)?;
|
||||
this.push_stack_frame(f, mir, dest, stack_pop)?;
|
||||
|
||||
// Initialize arguments.
|
||||
let mut callee_args = this.frame().body.args_iter();
|
||||
@ -331,19 +324,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
fields: impl Iterator<Item = InterpResult<'tcx, MPlaceTy<'tcx, Tag>>>,
|
||||
) -> InterpResult<'tcx> {
|
||||
match place.layout.fields {
|
||||
layout::FieldPlacement::Array { .. } => {
|
||||
layout::FieldsShape::Array { .. } => {
|
||||
// For the array layout, we know the iterator will yield sorted elements so
|
||||
// we can avoid the allocation.
|
||||
self.walk_aggregate(place, fields)
|
||||
}
|
||||
layout::FieldPlacement::Arbitrary { .. } => {
|
||||
layout::FieldsShape::Arbitrary { .. } => {
|
||||
// Gather the subplaces and sort them before visiting.
|
||||
let mut places =
|
||||
fields.collect::<InterpResult<'tcx, Vec<MPlaceTy<'tcx, Tag>>>>()?;
|
||||
places.sort_by_key(|place| place.ptr.assert_ptr().offset);
|
||||
self.walk_aggregate(place, places.into_iter().map(Ok))
|
||||
}
|
||||
layout::FieldPlacement::Union { .. } => {
|
||||
layout::FieldsShape::Union { .. } => {
|
||||
// Uh, what?
|
||||
bug!("a union is not an aggregate we should ever visit")
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ use rustc_middle::ty::{
|
||||
Ty,
|
||||
};
|
||||
use rustc_ast::attr;
|
||||
use rustc_span::{source_map::Span, symbol::{sym, Symbol}};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
|
||||
use crate::*;
|
||||
|
||||
@ -253,7 +253,6 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
|
||||
#[inline(always)]
|
||||
fn find_mir_or_eval_fn(
|
||||
ecx: &mut InterpCx<'mir, 'tcx, Self>,
|
||||
_span: Span,
|
||||
instance: ty::Instance<'tcx>,
|
||||
args: &[OpTy<'tcx, Tag>],
|
||||
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
|
||||
@ -276,13 +275,12 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
|
||||
#[inline(always)]
|
||||
fn call_intrinsic(
|
||||
ecx: &mut rustc_mir::interpret::InterpCx<'mir, 'tcx, Self>,
|
||||
span: Span,
|
||||
instance: ty::Instance<'tcx>,
|
||||
args: &[OpTy<'tcx, Tag>],
|
||||
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
|
||||
unwind: Option<mir::BasicBlock>,
|
||||
) -> InterpResult<'tcx> {
|
||||
ecx.call_intrinsic(span, instance, args, ret, unwind)
|
||||
ecx.call_intrinsic(instance, args, ret, unwind)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -5,7 +5,6 @@ use rustc_middle::mir;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::layout::{Align, LayoutOf};
|
||||
use rustc_apfloat::Float;
|
||||
use rustc_span::source_map::Span;
|
||||
|
||||
use crate::*;
|
||||
|
||||
@ -13,14 +12,13 @@ impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tc
|
||||
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
|
||||
fn call_intrinsic(
|
||||
&mut self,
|
||||
span: Span,
|
||||
instance: ty::Instance<'tcx>,
|
||||
args: &[OpTy<'tcx, Tag>],
|
||||
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
|
||||
unwind: Option<mir::BasicBlock>,
|
||||
) -> InterpResult<'tcx> {
|
||||
let this = self.eval_context_mut();
|
||||
if this.emulate_intrinsic(span, instance, args, ret)? {
|
||||
if this.emulate_intrinsic(instance, args, ret)? {
|
||||
return Ok(());
|
||||
}
|
||||
let substs = instance.substs;
|
||||
|
@ -51,7 +51,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
) -> InterpResult<'tcx> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
trace!("miri_start_panic: {:?}", this.frame().span);
|
||||
trace!("miri_start_panic: {:?}", this.frame().instance);
|
||||
|
||||
// Get the raw pointer stored in arg[0] (the panic payload).
|
||||
let payload = this.read_scalar(args[0])?.not_undef()?;
|
||||
@ -133,7 +133,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
if let (true, Some(catch_unwind)) = (unwinding, extra.catch_unwind.take()) {
|
||||
// We've just popped a frame that was pushed by `try`,
|
||||
// and we are unwinding, so we should catch that.
|
||||
trace!("unwinding: found catch_panic frame during unwinding: {:?}", this.frame().span);
|
||||
trace!("unwinding: found catch_panic frame during unwinding: {:?}", this.frame().instance);
|
||||
|
||||
// We set the return value of `try` to 1, since there was a panic.
|
||||
this.write_scalar(Scalar::from_i32(1), catch_unwind.dest)?;
|
||||
|
@ -7,12 +7,12 @@
|
||||
enum Void {}
|
||||
|
||||
fn f(v: Void) -> ! {
|
||||
match v {} //~ ERROR entering unreachable code
|
||||
match v {} //~ ERROR entering unreachable code
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let v: Void = unsafe {
|
||||
std::mem::transmute::<(), Void>(())
|
||||
};
|
||||
f(v); //~ inside call to `f`
|
||||
f(v); //~ inside `main`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user