Skip to content

Commit

Permalink
Manually add inlined frames in the interpreter stacktrace.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed May 25, 2023
1 parent 0919ec3 commit 3a423c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
15 changes: 14 additions & 1 deletion compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// This deliberately does *not* honor `requires_caller_location` since it is used for much
// more than just panics.
for frame in stack.iter().rev() {
let span = frame.current_span();
let span = match frame.loc {
Left(loc) => {
// If the stacktrace passes through MIR-inlined source scopes, add them.
let mir::SourceInfo { mut span, scope } = *frame.body.source_info(loc);
let mut scope_data = &frame.body.source_scopes[scope];
while let Some((instance, call_span)) = scope_data.inlined {
frames.push(FrameInfo { span, instance });
span = call_span;
scope_data = &frame.body.source_scopes[scope_data.parent_scope.unwrap()];
}
span
}
Right(span) => span,
};
frames.push(FrameInfo { span, instance: frame.instance });
}
trace!("generate stacktrace: {:#?}", frames);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/tests/fail/terminate-terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ impl Drop for Foo {

#[inline(always)]
fn has_cleanup() {
//~^ ERROR: panic in a function that cannot unwind
let _f = Foo;
panic!();
}

extern "C" fn panic_abort() {
has_cleanup();
//~^ ERROR: panic in a function that cannot unwind
}

fn main() {
Expand Down
11 changes: 7 additions & 4 deletions src/tools/miri/tests/fail/terminate-terminator.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ error: abnormal termination: panic in a function that cannot unwind
--> $DIR/terminate-terminator.rs:LL:CC
|
LL | / fn has_cleanup() {
LL | |
LL | | let _f = Foo;
LL | | panic!();
LL | | }
| |_^ panic in a function that cannot unwind
...
LL | has_cleanup();
| ------------- in this inlined function call
|
= note: inside `panic_abort` at $DIR/terminate-terminator.rs:LL:CC
= note: inside `has_cleanup` at $DIR/terminate-terminator.rs:LL:CC
note: inside `panic_abort`
--> $DIR/terminate-terminator.rs:LL:CC
|
LL | has_cleanup();
| ^^^^^^^^^^^^^
note: inside `main`
--> $DIR/terminate-terminator.rs:LL:CC
|
Expand Down

0 comments on commit 3a423c3

Please sign in to comment.