]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/out-of-stack.rs
Imported Upstream version 1.1.0+dfsg1
[rustc.git] / src / test / run-pass / out-of-stack.rs
CommitLineData
1a4d82fc
JJ
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// ignore-android: FIXME (#20004)
d9579d0f 12// ignore-musl
1a4d82fc 13
9346a6ac 14#![feature(asm)]
1a4d82fc 15
9346a6ac 16use std::process::Command;
85aaf69f 17use std::env;
1a4d82fc
JJ
18
19// lifted from the test module
20// Inlining to avoid llvm turning the recursive functions into tail calls,
21// which doesn't consume stack.
22#[inline(always)]
23pub fn black_box<T>(dummy: T) { unsafe { asm!("" : : "r"(&dummy)) } }
24
25fn silent_recurse() {
85aaf69f 26 let buf = [0; 1000];
1a4d82fc
JJ
27 black_box(buf);
28 silent_recurse();
29}
30
31fn loud_recurse() {
32 println!("hello!");
33 loud_recurse();
34 black_box(()); // don't optimize this into a tail call. please.
35}
36
37fn main() {
85aaf69f
SL
38 let args: Vec<String> = env::args().collect();
39 if args.len() > 1 && args[1] == "silent" {
1a4d82fc 40 silent_recurse();
85aaf69f 41 } else if args.len() > 1 && args[1] == "loud" {
1a4d82fc
JJ
42 loud_recurse();
43 } else {
85aaf69f 44 let silent = Command::new(&args[0]).arg("silent").output().unwrap();
1a4d82fc 45 assert!(!silent.status.success());
9346a6ac 46 let error = String::from_utf8_lossy(&silent.stderr);
85aaf69f 47 assert!(error.contains("has overflowed its stack"));
1a4d82fc 48
85aaf69f 49 let loud = Command::new(&args[0]).arg("loud").output().unwrap();
1a4d82fc 50 assert!(!loud.status.success());
9346a6ac 51 let error = String::from_utf8_lossy(&silent.stderr);
85aaf69f 52 assert!(error.contains("has overflowed its stack"));
1a4d82fc
JJ
53 }
54}