]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/out-of-stack.rs
auto merge of #17654 : gereeter/rust/no-unnecessary-cell, r=alexcrichton
[rust.git] / src / test / run-pass / out-of-stack.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(asm)]
12
13 use std::io::process::Command;
14 use std::os;
15
16 // lifted from the test module
17 // Inlining to avoid llvm turning the recursive functions into tail calls,
18 // which doesn't consume stack.
19 #[inline(always)]
20 pub fn black_box<T>(dummy: T) { unsafe { asm!("" : : "r"(&dummy)) } }
21
22 fn silent_recurse() {
23     let buf = [0i, ..1000];
24     black_box(buf);
25     silent_recurse();
26 }
27
28 fn loud_recurse() {
29     println!("hello!");
30     loud_recurse();
31     black_box(()); // don't optimize this into a tail call. please.
32 }
33
34 fn main() {
35     let args = os::args();
36     let args = args.as_slice();
37     if args.len() > 1 && args[1].as_slice() == "silent" {
38         silent_recurse();
39     } else if args.len() > 1 && args[1].as_slice() == "loud" {
40         loud_recurse();
41     } else {
42         let silent = Command::new(args[0].as_slice()).arg("silent").output().unwrap();
43         assert!(!silent.status.success());
44         let error = String::from_utf8_lossy(silent.error.as_slice());
45         // FIXME #17562: Windows is using stack probes and isn't wired up to print an error
46         if !cfg!(windows) {
47             assert!(error.as_slice().contains("has overflowed its stack"));
48         }
49
50         let loud = Command::new(args[0].as_slice()).arg("loud").output().unwrap();
51         assert!(!loud.status.success());
52         let error = String::from_utf8_lossy(silent.error.as_slice());
53         // FIXME #17562: Windows is using stack probes and isn't wired up to print an error
54         if !cfg!(windows) {
55             assert!(error.as_slice().contains("has overflowed its stack"));
56         }
57     }
58 }