2019-10-02 14:43:40 -05:00
|
|
|
//@ run-pass
|
2021-12-03 09:32:51 -06:00
|
|
|
//@ needs-unwind
|
2019-10-11 07:58:05 -05:00
|
|
|
//@ ignore-emscripten no threads support
|
2019-10-02 14:43:40 -05:00
|
|
|
|
|
|
|
// rust-lang/rust#64655: with panic=unwind, a panic from a subroutine
|
2019-10-03 03:46:01 -05:00
|
|
|
// should still run destructors as it unwinds the stack. However,
|
2019-10-02 14:43:40 -05:00
|
|
|
// bugs with how the nounwind LLVM attribute was applied led to this
|
|
|
|
// simple case being mishandled *if* you had fat LTO turned on.
|
|
|
|
|
|
|
|
// Unlike issue-64655-extern-rust-must-allow-unwind.rs, the issue
|
|
|
|
// embodied in this test cropped up regardless of optimization level.
|
|
|
|
// Therefore it seemed worthy of being enshrined as a dedicated unit
|
|
|
|
// test.
|
|
|
|
|
|
|
|
// LTO settings cannot be combined with -C prefer-dynamic
|
|
|
|
//@ no-prefer-dynamic
|
|
|
|
|
|
|
|
// The revisions just enumerate lto settings (the opt-level appeared irrelevant in practice)
|
|
|
|
|
|
|
|
//@ revisions: no thin fat
|
|
|
|
//@[no]compile-flags: -C lto=no
|
2021-07-29 19:22:59 -05:00
|
|
|
//@[thin]compile-flags: -C lto=thin
|
2019-10-02 14:43:40 -05:00
|
|
|
//@[fat]compile-flags: -C lto=fat
|
|
|
|
|
2023-12-09 07:36:34 -06:00
|
|
|
#![feature(panic_internals)]
|
2019-10-02 14:43:40 -05:00
|
|
|
|
|
|
|
// (For some reason, reproducing the LTO issue requires pulling in std
|
|
|
|
// explicitly this way.)
|
|
|
|
#![no_std]
|
|
|
|
extern crate std;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
use std::boxed::Box;
|
|
|
|
|
|
|
|
static SHARED: AtomicUsize = AtomicUsize::new(0);
|
|
|
|
|
|
|
|
assert_eq!(SHARED.fetch_add(0, Ordering::SeqCst), 0);
|
|
|
|
|
|
|
|
let old_hook = std::panic::take_hook();
|
|
|
|
|
|
|
|
std::panic::set_hook(Box::new(|_| { } )); // no-op on panic.
|
|
|
|
|
|
|
|
let handle = std::thread::spawn(|| {
|
|
|
|
struct Droppable;
|
|
|
|
impl Drop for Droppable {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
SHARED.fetch_add(1, Ordering::SeqCst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let _guard = Droppable;
|
2019-12-08 06:51:55 -06:00
|
|
|
core::panicking::panic("???");
|
2019-10-02 14:43:40 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
let wait = handle.join();
|
|
|
|
|
2019-10-03 03:46:01 -05:00
|
|
|
// Reinstate handler to ease observation of assertion failures.
|
2019-10-02 14:43:40 -05:00
|
|
|
std::panic::set_hook(old_hook);
|
|
|
|
|
|
|
|
assert!(wait.is_err());
|
|
|
|
|
|
|
|
assert_eq!(SHARED.fetch_add(0, Ordering::SeqCst), 1);
|
|
|
|
}
|