Skip to content

Commit

Permalink
Rollup merge of #73277 - RalfJung:miri-caller-location, r=oli-obk
Browse files Browse the repository at this point in the history
fix caller_location intrinsic for Miri

Fixes #73272

r? @oli-obk Cc @Aaron1011
  • Loading branch information
Dylan-DPC authored Jun 12, 2020
2 parents 77404e5 + b4bd180 commit f6bb405
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
11 changes: 2 additions & 9 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,8 @@ impl<'mir, 'tcx, Tag> Frame<'mir, 'tcx, Tag> {

impl<'mir, 'tcx, Tag, Extra> Frame<'mir, 'tcx, Tag, Extra> {
/// Return the `SourceInfo` of the current instruction.
pub fn current_source_info(&self) -> Option<mir::SourceInfo> {
self.loc.map(|loc| {
let block = &self.body.basic_blocks()[loc.block];
if loc.statement_index < block.statements.len() {
block.statements[loc.statement_index].source_info
} else {
block.terminator().source_info
}
})
pub fn current_source_info(&self) -> Option<&mir::SourceInfo> {
self.loc.map(|loc| self.body.source_info(loc))
}
}

Expand Down
25 changes: 16 additions & 9 deletions src/librustc_mir/interpret/intrinsics/caller_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,25 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
})
// Assert that there is always such a frame.
.unwrap();
// Assert that the frame we look at is actually executing code currently
// (`current_source_info` is None when we are unwinding and the frame does
// not require cleanup).
let loc = frame.loc.unwrap();
// If this is a `Call` terminator, use the `fn_span` instead.
let block = &frame.body.basic_blocks()[loc.block];
assert_eq!(block.statements.len(), loc.statement_index);
debug!(
"find_closest_untracked_caller_location:: got terminator {:?} ({:?})",
block.terminator(),
block.terminator().kind
);
if let TerminatorKind::Call { fn_span, .. } = block.terminator().kind {
return fn_span;
if loc.statement_index == block.statements.len() {
debug!(
"find_closest_untracked_caller_location:: got terminator {:?} ({:?})",
block.terminator(),
block.terminator().kind
);
if let TerminatorKind::Call { fn_span, .. } = block.terminator().kind {
return fn_span;
}
}
unreachable!();
// This is a different terminator (such as `Drop`) or not a terminator at all
// (such as `box`). Use the normal span.
frame.body.source_info(loc).span
}

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

0 comments on commit f6bb405

Please sign in to comment.