-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Always mark rust and rust-call abi's as unwind #65020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 9 commits into
rust-lang:master
from
pnkfelix:targetted-fix-for-always-marking-rust-abi-unwind-issue-64655
Oct 12, 2019
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9fbb2a9
Fix missing calls to drop on unwind with lto=fat; issue 64655.
pnkfelix a371972
Regression tests for issue 64655.
pnkfelix 3adcc3e
fix typo
pnkfelix e7e6dec
Apply suggestions from code review
pnkfelix 5e7e8cd
Update attributes.rs
pnkfelix 71e5f78
Update issue-64655-extern-rust-must-allow-unwind.rs
pnkfelix 08ec3fe
dont run these tests on targets that default to panic=abort.
pnkfelix 63d67fa
ignore-emcscripten as it does not support threads
RalfJung 028f53e
emcscripten: ignore another thread-using test
RalfJung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// run-pass | ||
// ignore-wasm32-bare compiled with panic=abort by default | ||
// ignore-emscripten no threads support | ||
|
||
// rust-lang/rust#64655: with panic=unwind, a panic from a subroutine | ||
// should still run destructors as it unwinds the stack. However, | ||
// 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 | ||
//[thin]compile-flags: -C lto=thin | ||
//[fat]compile-flags: -C lto=fat | ||
|
||
#![feature(core_panic)] | ||
|
||
// (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; | ||
let s = "issue-64655-allow-unwind-when-calling-panic-directly.rs"; | ||
core::panicking::panic(&("???", s, 17, 4)); | ||
}); | ||
|
||
let wait = handle.join(); | ||
|
||
// Reinstate handler to ease observation of assertion failures. | ||
std::panic::set_hook(old_hook); | ||
|
||
assert!(wait.is_err()); | ||
|
||
assert_eq!(SHARED.fetch_add(0, Ordering::SeqCst), 1); | ||
} |
83 changes: 83 additions & 0 deletions
83
src/test/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// run-pass | ||
// ignore-wasm32-bare compiled with panic=abort by default | ||
// ignore-emscripten no threads support | ||
|
||
// rust-lang/rust#64655: with panic=unwind, a panic from a subroutine | ||
// should still run destructors as it unwinds the stack. However, | ||
// bugs with how the nounwind LLVM attribute was applied led to this | ||
// simple case being mishandled *if* you had optimization *and* fat | ||
// LTO turned on. | ||
|
||
// This test is the closest thing to a "regression test" we can do | ||
// without actually spawning subprocesses and comparing stderr | ||
// results. | ||
// | ||
// This test takes the code from the above issue and adapts it to | ||
// better fit our test infrastructure: | ||
// | ||
// * Instead of relying on `println!` to observe whether the destructor | ||
// is run, we instead run the code in a spawned thread and | ||
// communicate the destructor's operation via a synchronous atomic | ||
// in static memory. | ||
// | ||
// * To keep the output from confusing a casual user, we override the | ||
// panic hook to be a no-op (rather than printing a message to | ||
// stderr). | ||
// | ||
// (pnkfelix has confirmed by hand that these additions do not mask | ||
// the underlying bug.) | ||
|
||
// LTO settings cannot be combined with -C prefer-dynamic | ||
// no-prefer-dynamic | ||
|
||
// The revisions combine each lto setting with each optimization | ||
// setting; pnkfelix observed three differing behaviors at opt-levels | ||
// 0/1/2+3 for this test, so it seems prudent to be thorough. | ||
|
||
// revisions: no0 no1 no2 no3 thin0 thin1 thin2 thin3 fat0 fat1 fat2 fat3 | ||
|
||
//[no0]compile-flags: -C opt-level=0 -C lto=no | ||
//[no1]compile-flags: -C opt-level=1 -C lto=no | ||
//[no2]compile-flags: -C opt-level=2 -C lto=no | ||
//[no3]compile-flags: -C opt-level=3 -C lto=no | ||
//[thin0]compile-flags: -C opt-level=0 -C lto=thin | ||
//[thin1]compile-flags: -C opt-level=1 -C lto=thin | ||
//[thin2]compile-flags: -C opt-level=2 -C lto=thin | ||
//[thin3]compile-flags: -C opt-level=3 -C lto=thin | ||
//[fat0]compile-flags: -C opt-level=0 -C lto=fat | ||
//[fat1]compile-flags: -C opt-level=1 -C lto=fat | ||
//[fat2]compile-flags: -C opt-level=2 -C lto=fat | ||
//[fat3]compile-flags: -C opt-level=3 -C lto=fat | ||
|
||
fn main() { | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
|
||
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; | ||
None::<()>.expect("???"); | ||
}); | ||
|
||
let wait = handle.join(); | ||
|
||
// reinstate handler to ease observation of assertion failures. | ||
std::panic::set_hook(old_hook); | ||
|
||
assert!(wait.is_err()); | ||
|
||
assert_eq!(SHARED.fetch_add(0, Ordering::SeqCst), 1); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.