Skip to content

Commit b4bd180

Browse files
committed
fix caller_location intrinsic for Miri
1 parent 5949391 commit b4bd180

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/librustc_mir/interpret/eval_context.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,8 @@ impl<'mir, 'tcx, Tag> Frame<'mir, 'tcx, Tag> {
171171

172172
impl<'mir, 'tcx, Tag, Extra> Frame<'mir, 'tcx, Tag, Extra> {
173173
/// Return the `SourceInfo` of the current instruction.
174-
pub fn current_source_info(&self) -> Option<mir::SourceInfo> {
175-
self.loc.map(|loc| {
176-
let block = &self.body.basic_blocks()[loc.block];
177-
if loc.statement_index < block.statements.len() {
178-
block.statements[loc.statement_index].source_info
179-
} else {
180-
block.terminator().source_info
181-
}
182-
})
174+
pub fn current_source_info(&self) -> Option<&mir::SourceInfo> {
175+
self.loc.map(|loc| self.body.source_info(loc))
183176
}
184177
}
185178

src/librustc_mir/interpret/intrinsics/caller_location.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,25 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
2929
})
3030
// Assert that there is always such a frame.
3131
.unwrap();
32+
// Assert that the frame we look at is actually executing code currently
33+
// (`current_source_info` is None when we are unwinding and the frame does
34+
// not require cleanup).
3235
let loc = frame.loc.unwrap();
36+
// If this is a `Call` terminator, use the `fn_span` instead.
3337
let block = &frame.body.basic_blocks()[loc.block];
34-
assert_eq!(block.statements.len(), loc.statement_index);
35-
debug!(
36-
"find_closest_untracked_caller_location:: got terminator {:?} ({:?})",
37-
block.terminator(),
38-
block.terminator().kind
39-
);
40-
if let TerminatorKind::Call { fn_span, .. } = block.terminator().kind {
41-
return fn_span;
38+
if loc.statement_index == block.statements.len() {
39+
debug!(
40+
"find_closest_untracked_caller_location:: got terminator {:?} ({:?})",
41+
block.terminator(),
42+
block.terminator().kind
43+
);
44+
if let TerminatorKind::Call { fn_span, .. } = block.terminator().kind {
45+
return fn_span;
46+
}
4247
}
43-
unreachable!();
48+
// This is a different terminator (such as `Drop`) or not a terminator at all
49+
// (such as `box`). Use the normal span.
50+
frame.body.source_info(loc).span
4451
}
4552

4653
/// Allocate a `const core::panic::Location` with the provided filename and line/column numbers.

0 commit comments

Comments
 (0)