Auto merge of #32900 - alexcrichton:panic2abort, r=nikomatsakis
rustc: Implement custom panic runtimes This commit is an implementation of [RFC 1513] which allows applications to alter the behavior of panics at compile time. A new compiler flag, `-C panic`, is added and accepts the values `unwind` or `panic`, with the default being `unwind`. This model affects how code is generated for the local crate, skipping generation of landing pads with `-C panic=abort`. [RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md Panic implementations are then provided by crates tagged with `#![panic_runtime]` and lazily required by crates with `#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic runtime must match the final product, and if the panic strategy is not `abort` then the entire DAG must have the same panic strategy. With the `-C panic=abort` strategy, users can expect a stable method to disable generation of landing pads, improving optimization in niche scenarios, decreasing compile time, and decreasing output binary size. With the `-C panic=unwind` strategy users can expect the existing ability to isolate failure in Rust code from the outside world. Organizationally, this commit dismantles the `sys_common::unwind` module in favor of some bits moving part of it to `libpanic_unwind` and the rest into the `panicking` module in libstd. The custom panic runtime support is pretty similar to the custom allocator support with the only major difference being how the panic runtime is injected (takes the `-C panic` flag into account). Closes #32837
This commit is contained in:
commit
72ed7e7894
81 changed files with 2323 additions and 932 deletions
31
src/test/codegen/lto-removes-invokes.rs
Normal file
31
src/test/codegen/lto-removes-invokes.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: -C lto -C panic=abort -O
|
||||
// no-prefer-dynamic
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[inline(never)]
|
||||
fn foo() {
|
||||
let _a = Box::new(3);
|
||||
bar();
|
||||
// CHECK-LABEL: foo
|
||||
// CHECK: call {{.*}} void @bar
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
#[no_mangle]
|
||||
fn bar() {
|
||||
println!("hello!");
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C panic=abort -C prefer-dynamic
|
||||
// ignore-musl - no dylibs here
|
||||
// error-pattern:`panic_unwind` is not compiled with this crate's panic strategy
|
||||
|
||||
// This is a test where the local crate, compiled with `panic=abort`, links to
|
||||
// the standard library **dynamically** which is already linked against
|
||||
// `panic=unwind`. We should fail because the linked panic runtime does not
|
||||
// correspond with our `-C panic` option.
|
||||
//
|
||||
// Note that this test assumes that the dynamic version of the standard library
|
||||
// is linked to `panic_unwind`, which is currently the case.
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(needs_panic_runtime)]
|
||||
#![crate_type = "rlib"]
|
||||
#![needs_panic_runtime]
|
||||
#![no_std]
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C panic=abort
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(panic_runtime)]
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#![no_std]
|
||||
#![panic_runtime]
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn __rust_maybe_catch_panic() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn __rust_start_panic() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn rust_eh_personality() {}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#![no_std]
|
||||
#![feature(lang_items)]
|
||||
|
||||
#[lang = "panic_fmt"]
|
||||
fn panic_fmt() {}
|
||||
#[lang = "eh_personality"]
|
||||
fn eh_personality() {}
|
||||
#[lang = "eh_unwind_resume"]
|
||||
fn eh_unwind_resume() {}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C panic=unwind
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(panic_runtime)]
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#![no_std]
|
||||
#![panic_runtime]
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn __rust_maybe_catch_panic() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn __rust_start_panic() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn rust_eh_personality() {}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C panic=unwind
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(panic_runtime)]
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#![no_std]
|
||||
#![panic_runtime]
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn __rust_maybe_catch_panic() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn __rust_start_panic() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn rust_eh_personality() {}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(panic_runtime)]
|
||||
#![crate_type = "rlib"]
|
||||
#![panic_runtime]
|
||||
#![no_std]
|
||||
|
||||
extern crate needs_panic_runtime;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C panic=abort
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "rlib"]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_runtime_abort;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "rlib"]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_runtime_unwind;
|
||||
14
src/test/compile-fail/panic-runtime/bad-panic-flag1.rs
Normal file
14
src/test/compile-fail/panic-runtime/bad-panic-flag1.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C panic=foo
|
||||
// error-pattern:either `panic` or `abort` was expected
|
||||
|
||||
fn main() {}
|
||||
14
src/test/compile-fail/panic-runtime/bad-panic-flag2.rs
Normal file
14
src/test/compile-fail/panic-runtime/bad-panic-flag2.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C panic
|
||||
// error-pattern:requires either `panic` or `abort`
|
||||
|
||||
fn main() {}
|
||||
20
src/test/compile-fail/panic-runtime/libtest-unwinds.rs
Normal file
20
src/test/compile-fail/panic-runtime/libtest-unwinds.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:is not compiled with this crate's panic strategy `abort`
|
||||
// compile-flags:-C panic=abort
|
||||
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
||||
14
src/test/compile-fail/panic-runtime/needs-gate.rs
Normal file
14
src/test/compile-fail/panic-runtime/needs-gate.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![panic_runtime] //~ ERROR: is an experimental feature
|
||||
#![needs_panic_runtime] //~ ERROR: is an experimental feature
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// aux-build:needs-panic-runtime.rs
|
||||
// aux-build:runtime-depending-on-panic-runtime.rs
|
||||
// error-pattern:cannot depend on a crate that needs a panic runtime
|
||||
|
||||
extern crate runtime_depending_on_panic_runtime;
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// aux-build:panic-runtime-unwind.rs
|
||||
// aux-build:panic-runtime-abort.rs
|
||||
// aux-build:wants-panic-runtime-unwind.rs
|
||||
// aux-build:wants-panic-runtime-abort.rs
|
||||
// aux-build:panic-runtime-lang-items.rs
|
||||
// error-pattern: is not compiled with this crate's panic strategy `unwind`
|
||||
|
||||
#![no_std]
|
||||
|
||||
extern crate wants_panic_runtime_unwind;
|
||||
extern crate wants_panic_runtime_abort;
|
||||
extern crate panic_runtime_lang_items;
|
||||
|
||||
fn main() {}
|
||||
23
src/test/compile-fail/panic-runtime/two-panic-runtimes.rs
Normal file
23
src/test/compile-fail/panic-runtime/two-panic-runtimes.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:cannot link together two panic runtimes: panic_runtime_unwind and panic_runtime_unwind2
|
||||
// ignore-tidy-linelength
|
||||
// aux-build:panic-runtime-unwind.rs
|
||||
// aux-build:panic-runtime-unwind2.rs
|
||||
// aux-build:panic-runtime-lang-items.rs
|
||||
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_runtime_unwind;
|
||||
extern crate panic_runtime_unwind2;
|
||||
extern crate panic_runtime_lang_items;
|
||||
|
||||
fn main() {}
|
||||
17
src/test/compile-fail/panic-runtime/want-abort-got-unwind.rs
Normal file
17
src/test/compile-fail/panic-runtime/want-abort-got-unwind.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:is not compiled with this crate's panic strategy `abort`
|
||||
// aux-build:panic-runtime-unwind.rs
|
||||
// compile-flags:-C panic=abort
|
||||
|
||||
extern crate panic_runtime_unwind;
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:is not compiled with this crate's panic strategy `abort`
|
||||
// aux-build:panic-runtime-unwind.rs
|
||||
// aux-build:wants-panic-runtime-unwind.rs
|
||||
// compile-flags:-C panic=abort
|
||||
|
||||
extern crate wants_panic_runtime_unwind;
|
||||
|
||||
fn main() {}
|
||||
20
src/test/compile-fail/panic-runtime/want-unwind-got-abort.rs
Normal file
20
src/test/compile-fail/panic-runtime/want-unwind-got-abort.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:is incompatible with this crate's strategy of `unwind`
|
||||
// aux-build:panic-runtime-abort.rs
|
||||
// aux-build:panic-runtime-lang-items.rs
|
||||
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_runtime_abort;
|
||||
extern crate panic_runtime_lang_items;
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:is incompatible with this crate's strategy of `unwind`
|
||||
// aux-build:panic-runtime-abort.rs
|
||||
// aux-build:wants-panic-runtime-abort.rs
|
||||
// aux-build:panic-runtime-lang-items.rs
|
||||
|
||||
#![no_std]
|
||||
|
||||
extern crate wants_panic_runtime_abort;
|
||||
extern crate panic_runtime_lang_items;
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C panic=abort
|
||||
// aux-build:exit-success-if-unwind.rs
|
||||
// no-prefer-dynamic
|
||||
|
||||
extern crate exit_success_if_unwind;
|
||||
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
let mut args = env::args_os();
|
||||
let me = args.next().unwrap();
|
||||
|
||||
if let Some(s) = args.next() {
|
||||
if &*s == "foo" {
|
||||
exit_success_if_unwind::bar(do_panic);
|
||||
}
|
||||
}
|
||||
let s = Command::new(env::args_os().next().unwrap()).arg("foo").status();
|
||||
assert!(s.unwrap().code() != Some(0));
|
||||
}
|
||||
|
||||
fn do_panic() {
|
||||
panic!("try to catch me");
|
||||
}
|
||||
39
src/test/run-pass/panic-runtime/abort.rs
Normal file
39
src/test/run-pass/panic-runtime/abort.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C panic=abort
|
||||
// no-prefer-dynamic
|
||||
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
|
||||
struct Bomb;
|
||||
|
||||
impl Drop for Bomb {
|
||||
fn drop(&mut self) {
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut args = env::args_os();
|
||||
let me = args.next().unwrap();
|
||||
|
||||
if let Some(s) = args.next() {
|
||||
if &*s == "foo" {
|
||||
|
||||
let _bomb = Bomb;
|
||||
|
||||
panic!("try to catch me");
|
||||
}
|
||||
}
|
||||
let s = Command::new(env::args_os().next().unwrap()).arg("foo").status();
|
||||
assert!(s.unwrap().code() != Some(0));
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
struct Bomb;
|
||||
|
||||
impl Drop for Bomb {
|
||||
fn drop(&mut self) {
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bar(f: fn()) {
|
||||
let _bomb = Bomb;
|
||||
f();
|
||||
}
|
||||
19
src/test/run-pass/panic-runtime/link-to-abort.rs
Normal file
19
src/test/run-pass/panic-runtime/link-to-abort.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C panic=abort
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(panic_abort)]
|
||||
|
||||
extern crate panic_abort;
|
||||
|
||||
fn main() {
|
||||
}
|
||||
18
src/test/run-pass/panic-runtime/link-to-unwind.rs
Normal file
18
src/test/run-pass/panic-runtime/link-to-unwind.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(panic_unwind)]
|
||||
|
||||
extern crate panic_unwind;
|
||||
|
||||
fn main() {
|
||||
}
|
||||
39
src/test/run-pass/panic-runtime/lto-abort.rs
Normal file
39
src/test/run-pass/panic-runtime/lto-abort.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C lto -C panic=abort
|
||||
// no-prefer-dynamic
|
||||
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
|
||||
struct Bomb;
|
||||
|
||||
impl Drop for Bomb {
|
||||
fn drop(&mut self) {
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut args = env::args_os();
|
||||
let me = args.next().unwrap();
|
||||
|
||||
if let Some(s) = args.next() {
|
||||
if &*s == "foo" {
|
||||
|
||||
let _bomb = Bomb;
|
||||
|
||||
panic!("try to catch me");
|
||||
}
|
||||
}
|
||||
let s = Command::new(env::args_os().next().unwrap()).arg("foo").status();
|
||||
assert!(s.unwrap().code() != Some(0));
|
||||
}
|
||||
41
src/test/run-pass/panic-runtime/lto-unwind.rs
Normal file
41
src/test/run-pass/panic-runtime/lto-unwind.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:-C lto -C panic=unwind
|
||||
// no-prefer-dynamic
|
||||
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
|
||||
struct Bomb;
|
||||
|
||||
impl Drop for Bomb {
|
||||
fn drop(&mut self) {
|
||||
println!("hurray you ran me");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut args = env::args_os();
|
||||
let me = args.next().unwrap();
|
||||
|
||||
if let Some(s) = args.next() {
|
||||
if &*s == "foo" {
|
||||
|
||||
let _bomb = Bomb;
|
||||
|
||||
panic!("try to catch me");
|
||||
}
|
||||
}
|
||||
let s = Command::new(env::args_os().next().unwrap()).arg("foo").output();
|
||||
let s = s.unwrap();
|
||||
assert!(!s.status.success());
|
||||
assert!(String::from_utf8_lossy(&s.stdout).contains("hurray you ran me"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue