Skip to content

Commit b2cddd2

Browse files
committed
better span for functions whose frame we push 'manually'
1 parent 4cf8343 commit b2cddd2

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
@@ -221,12 +221,7 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
221221
};
222222
e.print_backtrace();
223223
if let Some(frame) = ecx.stack().last() {
224-
let block = &frame.body.basic_blocks()[frame.block.unwrap()];
225-
let span = if frame.stmt < block.statements.len() {
226-
block.statements[frame.stmt].source_info.span
227-
} else {
228-
block.terminator().source_info.span
229-
};
224+
let span = frame.current_source_info().unwrap().span;
230225

231226
let msg = format!("Miri evaluation error: {}", msg);
232227
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)