Skip to content

Commit cd53efc

Browse files
committed
Prevent __rust_begin_short_backtrace frames from being tail-call optimised away
1 parent 1e99138 commit cd53efc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

library/std/src/sys_common/backtrace.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ where
126126
F: Send,
127127
T: Send,
128128
{
129-
f()
129+
let result = f();
130+
131+
// prevent this frame from being tail-call optimised away
132+
crate::hint::black_box(());
133+
134+
result
130135
}
131136

132137
pub enum RustBacktrace {

library/test/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,10 @@ pub fn run_test(
514514
/// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`.
515515
#[inline(never)]
516516
fn __rust_begin_short_backtrace<F: FnOnce()>(f: F) {
517-
f()
517+
f();
518+
519+
// prevent this frame from being tail-call optimised away
520+
black_box(());
518521
}
519522

520523
fn run_test_in_process(

0 commit comments

Comments
 (0)