Skip to content

Commit

Permalink
test: avoid infinite loop in out-of-stack.rs
Browse files Browse the repository at this point in the history
This fixes rust-lang#13238. It avoids an infinite loop when compiling
the tests with `-g`. Without this change, the debuginfo on
`black_box` prevents the method from being inlined, which
allows llvm to convert `silent_recurse` into a tail-call. This
then loops forever instead of consuming all the stack like it
is supposed to. This patch forces inlining `black_box`, which
triggers the right error.
  • Loading branch information
erickt authored and ckendell committed Apr 4, 2014
1 parent 400f409 commit 3111a29
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/test/run-pass/out-of-stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use std::os;
use std::str;

// lifted from the test module
// Inlining to avoid llvm turning the recursive functions into tail calls,
// which doesn't consume stack.
#[inline(always)]
pub fn black_box<T>(dummy: T) { unsafe { asm!("" : : "r"(&dummy)) } }

fn silent_recurse() {
Expand Down

0 comments on commit 3111a29

Please sign in to comment.