Skip to content

Commit

Permalink
Prevent __rust_begin_short_backtrace frames from being tail-call op…
Browse files Browse the repository at this point in the history
…timised away
  • Loading branch information
eggyal committed Aug 2, 2020
1 parent 1e99138 commit cd53efc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion library/std/src/sys_common/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ where
F: Send,
T: Send,
{
f()
let result = f();

// prevent this frame from being tail-call optimised away
crate::hint::black_box(());

result
}

pub enum RustBacktrace {
Expand Down
5 changes: 4 additions & 1 deletion library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,10 @@ pub fn run_test(
/// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`.
#[inline(never)]
fn __rust_begin_short_backtrace<F: FnOnce()>(f: F) {
f()
f();

// prevent this frame from being tail-call optimised away
black_box(());
}

fn run_test_in_process(
Expand Down

0 comments on commit cd53efc

Please sign in to comment.