Skip to content

Commit ed14328

Browse files
committedApr 2, 2020
Auto merge of #1283 - RalfJung:backtrace, r=RalfJung
Make backtrace function names and spans match up This is the Miri side of rust-lang/rust#70590. Fixes #521
2 parents 77a307f + 5ce2466 commit ed14328

File tree

7 files changed

+18
-32
lines changed

7 files changed

+18
-32
lines changed
 

‎rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
235938d1acdd93d6641a741c81f64e415b786751
1+
b793f403bdfbcc0ff3e15ed8177a81d79ba4a29b

‎src/diagnostics.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,12 @@ fn report_msg<'tcx, 'mir>(
129129
err.help(help);
130130
}
131131
// Add backtrace
132-
let frames = ecx.generate_stacktrace(None);
133-
// We iterate with indices because we need to look at the next frame (the caller).
134-
for idx in 0..frames.len() {
135-
let frame_info = &frames[idx];
136-
let call_site_is_local = frames
137-
.get(idx + 1)
138-
.map_or(false, |caller_info| caller_info.instance.def_id().is_local());
139-
if call_site_is_local {
140-
err.span_note(frame_info.call_site, &frame_info.to_string());
132+
let frames = ecx.generate_stacktrace();
133+
for (idx, frame_info) in frames.iter().enumerate() {
134+
let is_local = frame_info.instance.def_id().is_local();
135+
// No span for non-local frames and the first frame (which is the error site).
136+
if is_local && idx > 0 {
137+
err.span_note(frame_info.span, &frame_info.to_string());
141138
} else {
142139
err.note(&frame_info.to_string());
143140
}

‎src/helpers.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_middle::ty::{
1010
List, TyCtxt,
1111
};
1212
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
13-
use rustc_span::source_map::DUMMY_SP;
1413

1514
use rand::RngCore;
1615

@@ -170,13 +169,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
170169

171170
// Push frame.
172171
let mir = &*this.load_mir(f.def, None)?;
173-
let span = this
174-
.stack()
175-
.last()
176-
.and_then(Frame::current_source_info)
177-
.map(|si| si.span)
178-
.unwrap_or(DUMMY_SP);
179-
this.push_stack_frame(f, span, mir, dest, stack_pop)?;
172+
this.push_stack_frame(f, mir, dest, stack_pop)?;
180173

181174
// Initialize arguments.
182175
let mut callee_args = this.frame().body.args_iter();
@@ -331,19 +324,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
331324
fields: impl Iterator<Item = InterpResult<'tcx, MPlaceTy<'tcx, Tag>>>,
332325
) -> InterpResult<'tcx> {
333326
match place.layout.fields {
334-
layout::FieldPlacement::Array { .. } => {
327+
layout::FieldsShape::Array { .. } => {
335328
// For the array layout, we know the iterator will yield sorted elements so
336329
// we can avoid the allocation.
337330
self.walk_aggregate(place, fields)
338331
}
339-
layout::FieldPlacement::Arbitrary { .. } => {
332+
layout::FieldsShape::Arbitrary { .. } => {
340333
// Gather the subplaces and sort them before visiting.
341334
let mut places =
342335
fields.collect::<InterpResult<'tcx, Vec<MPlaceTy<'tcx, Tag>>>>()?;
343336
places.sort_by_key(|place| place.ptr.assert_ptr().offset);
344337
self.walk_aggregate(place, places.into_iter().map(Ok))
345338
}
346-
layout::FieldPlacement::Union { .. } => {
339+
layout::FieldsShape::Union { .. } => {
347340
// Uh, what?
348341
bug!("a union is not an aggregate we should ever visit")
349342
}

‎src/machine.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::ty::{
1818
Ty,
1919
};
2020
use rustc_ast::attr;
21-
use rustc_span::{source_map::Span, symbol::{sym, Symbol}};
21+
use rustc_span::symbol::{sym, Symbol};
2222

2323
use crate::*;
2424

@@ -253,7 +253,6 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
253253
#[inline(always)]
254254
fn find_mir_or_eval_fn(
255255
ecx: &mut InterpCx<'mir, 'tcx, Self>,
256-
_span: Span,
257256
instance: ty::Instance<'tcx>,
258257
args: &[OpTy<'tcx, Tag>],
259258
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
@@ -276,13 +275,12 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
276275
#[inline(always)]
277276
fn call_intrinsic(
278277
ecx: &mut rustc_mir::interpret::InterpCx<'mir, 'tcx, Self>,
279-
span: Span,
280278
instance: ty::Instance<'tcx>,
281279
args: &[OpTy<'tcx, Tag>],
282280
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
283281
unwind: Option<mir::BasicBlock>,
284282
) -> InterpResult<'tcx> {
285-
ecx.call_intrinsic(span, instance, args, ret, unwind)
283+
ecx.call_intrinsic(instance, args, ret, unwind)
286284
}
287285

288286
#[inline(always)]

‎src/shims/intrinsics.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ use rustc_middle::mir;
55
use rustc_middle::ty;
66
use rustc_middle::ty::layout::{Align, LayoutOf};
77
use rustc_apfloat::Float;
8-
use rustc_span::source_map::Span;
98

109
use crate::*;
1110

1211
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
1312
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
1413
fn call_intrinsic(
1514
&mut self,
16-
span: Span,
1715
instance: ty::Instance<'tcx>,
1816
args: &[OpTy<'tcx, Tag>],
1917
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
2018
unwind: Option<mir::BasicBlock>,
2119
) -> InterpResult<'tcx> {
2220
let this = self.eval_context_mut();
23-
if this.emulate_intrinsic(span, instance, args, ret)? {
21+
if this.emulate_intrinsic(instance, args, ret)? {
2422
return Ok(());
2523
}
2624
let substs = instance.substs;

‎src/shims/panic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5151
) -> InterpResult<'tcx> {
5252
let this = self.eval_context_mut();
5353

54-
trace!("miri_start_panic: {:?}", this.frame().span);
54+
trace!("miri_start_panic: {:?}", this.frame().instance);
5555

5656
// Get the raw pointer stored in arg[0] (the panic payload).
5757
let payload = this.read_scalar(args[0])?.not_undef()?;
@@ -133,7 +133,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
133133
if let (true, Some(catch_unwind)) = (unwinding, extra.catch_unwind.take()) {
134134
// We've just popped a frame that was pushed by `try`,
135135
// and we are unwinding, so we should catch that.
136-
trace!("unwinding: found catch_panic frame during unwinding: {:?}", this.frame().span);
136+
trace!("unwinding: found catch_panic frame during unwinding: {:?}", this.frame().instance);
137137

138138
// We set the return value of `try` to 1, since there was a panic.
139139
this.write_scalar(Scalar::from_i32(1), catch_unwind.dest)?;

‎tests/compile-fail/never_transmute_void.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
enum Void {}
88

99
fn f(v: Void) -> ! {
10-
match v {} //~ ERROR entering unreachable code
10+
match v {} //~ ERROR entering unreachable code
1111
}
1212

1313
fn main() {
1414
let v: Void = unsafe {
1515
std::mem::transmute::<(), Void>(())
1616
};
17-
f(v); //~ inside call to `f`
17+
f(v); //~ inside `main`
1818
}

0 commit comments

Comments
 (0)
Please sign in to comment.