Skip to content

Commit 3a423c3

Browse files
committed
Manually add inlined frames in the interpreter stacktrace.
1 parent 0919ec3 commit 3a423c3

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
949949
// This deliberately does *not* honor `requires_caller_location` since it is used for much
950950
// more than just panics.
951951
for frame in stack.iter().rev() {
952-
let span = frame.current_span();
952+
let span = match frame.loc {
953+
Left(loc) => {
954+
// If the stacktrace passes through MIR-inlined source scopes, add them.
955+
let mir::SourceInfo { mut span, scope } = *frame.body.source_info(loc);
956+
let mut scope_data = &frame.body.source_scopes[scope];
957+
while let Some((instance, call_span)) = scope_data.inlined {
958+
frames.push(FrameInfo { span, instance });
959+
span = call_span;
960+
scope_data = &frame.body.source_scopes[scope_data.parent_scope.unwrap()];
961+
}
962+
span
963+
}
964+
Right(span) => span,
965+
};
953966
frames.push(FrameInfo { span, instance: frame.instance });
954967
}
955968
trace!("generate stacktrace: {:#?}", frames);

src/tools/miri/tests/fail/terminate-terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ impl Drop for Foo {
1212

1313
#[inline(always)]
1414
fn has_cleanup() {
15+
//~^ ERROR: panic in a function that cannot unwind
1516
let _f = Foo;
1617
panic!();
1718
}
1819

1920
extern "C" fn panic_abort() {
2021
has_cleanup();
21-
//~^ ERROR: panic in a function that cannot unwind
2222
}
2323

2424
fn main() {

src/tools/miri/tests/fail/terminate-terminator.stderr

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ error: abnormal termination: panic in a function that cannot unwind
66
--> $DIR/terminate-terminator.rs:LL:CC
77
|
88
LL | / fn has_cleanup() {
9+
LL | |
910
LL | | let _f = Foo;
1011
LL | | panic!();
1112
LL | | }
1213
| |_^ panic in a function that cannot unwind
13-
...
14-
LL | has_cleanup();
15-
| ------------- in this inlined function call
1614
|
17-
= note: inside `panic_abort` at $DIR/terminate-terminator.rs:LL:CC
15+
= note: inside `has_cleanup` at $DIR/terminate-terminator.rs:LL:CC
16+
note: inside `panic_abort`
17+
--> $DIR/terminate-terminator.rs:LL:CC
18+
|
19+
LL | has_cleanup();
20+
| ^^^^^^^^^^^^^
1821
note: inside `main`
1922
--> $DIR/terminate-terminator.rs:LL:CC
2023
|

0 commit comments

Comments
 (0)