Skip to content

Commit 135824e

Browse files
committed
better span for functions whose frame we push 'manually'
1 parent c639622 commit 135824e

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/eval.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,7 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
207207
};
208208
e.print_backtrace();
209209
if let Some(frame) = ecx.stack().last() {
210-
let block = &frame.body.basic_blocks()[frame.block.unwrap()];
211-
let span = if frame.stmt < block.statements.len() {
212-
block.statements[frame.stmt].source_info.span
213-
} else {
214-
block.terminator().source_info.span
215-
};
210+
let span = frame.current_source_info().unwrap().span;
216211

217212
let msg = format!("Miri evaluation error: {}", msg);
218213
let mut err = ecx.tcx.sess.struct_span_err(span, msg.as_str());

src/helpers.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
132132

133133
// Push frame.
134134
let mir = this.load_mir(f.def, None)?;
135+
let span = this.stack().last()
136+
.and_then(Frame::current_source_info)
137+
.map(|si| si.span)
138+
.unwrap_or(DUMMY_SP);
135139
this.push_stack_frame(
136140
f,
137-
DUMMY_SP, // There is no call site.
141+
span,
138142
mir,
139143
dest,
140144
stack_pop,

src/shims/panic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
166166
// Forward to `panic_bounds_check` lang item.
167167

168168
// First arg: Caller location.
169-
let location = this.alloc_caller_location_for_span(span)?;
169+
let location = this.alloc_caller_location_for_span(span);
170170
// Second arg: index.
171171
let index = this.read_scalar(this.eval_operand(index, None)?)?;
172172
// Third arg: len.
@@ -190,7 +190,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
190190
let msg = this.allocate_str(msg, MiriMemoryKind::Static.into());
191191

192192
// Second arg: Caller location.
193-
let location = this.alloc_caller_location_for_span(span)?;
193+
let location = this.alloc_caller_location_for_span(span);
194194

195195
// Call the lang item.
196196
let panic = this.tcx.lang_items().panic_fn().unwrap();

0 commit comments

Comments
 (0)