Skip to content

Commit

Permalink
Do a volatile read in stack_overflow test to avoid tail recursion
Browse files Browse the repository at this point in the history
This prevents the compiler from transforming the tail recursive function into a loop, which does not lead to a stack overflow. It also avoids the LLVM bug where functions with side-effect-free endless loops are removed. Thus, the test now also works in `--release` mode.
  • Loading branch information
phil-opp committed Jun 8, 2020
1 parent 12d94fd commit 5735cb8
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions tests/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub extern "C" fn _start() -> ! {
#[allow(unconditional_recursion)]
fn stack_overflow() {
stack_overflow(); // for each recursion, the return address is pushed
volatile::Volatile::new(0).read(); // prevent tail recursion optimizations
}

lazy_static! {
Expand Down

0 comments on commit 5735cb8

Please sign in to comment.