Skip to content

Enable -Z panic-in-drop=abort by default #95209

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ fn test_debugging_options_tracking_hash() {

// Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
// This list is in alphabetical order.
untracked!(allow_incompatible_panic_in_drop, true);
untracked!(assert_incr_state, Some(String::from("loaded")));
untracked!(ast_json, true);
untracked!(ast_json_noexpand, true);
Expand Down Expand Up @@ -761,7 +762,7 @@ fn test_debugging_options_tracking_hash() {
tracked!(oom, OomStrategy::Panic);
tracked!(osx_rpath_install_name, true);
tracked!(panic_abort_tests, true);
tracked!(panic_in_drop, PanicStrategy::Abort);
tracked!(panic_in_drop, PanicStrategy::Unwind);
tracked!(pick_stable_methods_before_any_unstable, false);
tracked!(plt, Some(true));
tracked!(polonius, true);
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_metadata/src/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
}

let found_drop_strategy = tcx.panic_in_drop_strategy(cnum);
if tcx.sess.opts.debugging_opts.panic_in_drop != found_drop_strategy {
if !tcx.sess.opts.debugging_opts.allow_incompatible_panic_in_drop
&& tcx.sess.opts.debugging_opts.panic_in_drop != found_drop_strategy
{
sess.err(&format!(
"the crate `{}` is compiled with the \
panic-in-drop strategy `{}` which is \
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,8 @@ options! {

allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
"only allow the listed language features to be enabled in code (space separated)"),
allow_incompatible_panic_in_drop: bool = (false, parse_bool, [UNTRACKED],
"allow linking to crates with an incompatible panic-in-drop strategy"),
always_encode_mir: bool = (false, parse_bool, [TRACKED],
"encode MIR of all functions into the crate metadata (default: no)"),
assume_incomplete_release: bool = (false, parse_bool, [TRACKED],
Expand Down Expand Up @@ -1345,7 +1347,7 @@ options! {
"pass `-install_name @rpath/...` to the macOS linker (default: no)"),
panic_abort_tests: bool = (false, parse_bool, [TRACKED],
"support compiling tests with panic=abort (default: no)"),
panic_in_drop: PanicStrategy = (PanicStrategy::Unwind, parse_panic_strategy, [TRACKED],
panic_in_drop: PanicStrategy = (PanicStrategy::Abort, parse_panic_strategy, [TRACKED],
"panic strategy for panics in drops"),
parse_only: bool = (false, parse_bool, [UNTRACKED],
"parse only; do not compile, assemble, or link (default: no)"),
Expand Down
6 changes: 6 additions & 0 deletions library/alloc/src/collections/btree/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ mod test_drain_filter {
map.check();
}

#[ignore]
#[test]
fn drop_panic_leak() {
let a = CrashTestDummy::new(0);
Expand All @@ -1141,6 +1142,7 @@ mod test_drain_filter {
assert_eq!(c.dropped(), 1);
}

#[ignore]
#[test]
fn pred_panic_leak() {
let a = CrashTestDummy::new(0);
Expand Down Expand Up @@ -1415,6 +1417,7 @@ fn test_clear() {
}
}

#[ignore]
#[test]
fn test_clear_drop_panic_leak() {
let a = CrashTestDummy::new(0);
Expand Down Expand Up @@ -1960,6 +1963,7 @@ create_append_test!(test_append_239, 239);
#[cfg(not(miri))] // Miri is too slow
create_append_test!(test_append_1700, 1700);

#[ignore]
#[test]
fn test_append_drop_leak() {
let a = CrashTestDummy::new(0);
Expand Down Expand Up @@ -2101,6 +2105,7 @@ fn test_split_off_large_random_sorted() {
assert!(right.into_iter().eq(data.into_iter().filter(|x| x.0 >= key)));
}

#[ignore]
#[test]
fn test_into_iter_drop_leak_height_0() {
let a = CrashTestDummy::new(0);
Expand All @@ -2124,6 +2129,7 @@ fn test_into_iter_drop_leak_height_0() {
assert_eq!(e.dropped(), 1);
}

#[ignore]
#[test]
fn test_into_iter_drop_leak_height_1() {
let size = MIN_INSERTS_HEIGHT_1;
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/collections/btree/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ fn test_drain_filter() {
assert_eq!(y.len(), 1);
}

#[ignore]
#[test]
fn test_drain_filter_drop_panic_leak() {
let a = CrashTestDummy::new(0);
Expand All @@ -360,6 +361,7 @@ fn test_drain_filter_drop_panic_leak() {
assert_eq!(c.dropped(), 1);
}

#[ignore]
#[test]
fn test_drain_filter_pred_panic_leak() {
let a = CrashTestDummy::new(0);
Expand Down
1 change: 1 addition & 0 deletions library/alloc/tests/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ fn test_drain_sorted() {
assert!(q.is_empty());
}

#[ignore]
#[test]
fn test_drain_sorted_leak() {
static DROPS: AtomicU32 = AtomicU32::new(0);
Expand Down
3 changes: 3 additions & 0 deletions library/alloc/tests/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ fn drain_filter_complex() {
}
}

#[ignore]
#[test]
fn drain_filter_drop_panic_leak() {
static mut DROPS: i32 = 0;
Expand Down Expand Up @@ -565,6 +566,7 @@ fn drain_filter_drop_panic_leak() {
}

#[test]
#[ignore]
fn drain_filter_pred_panic_leak() {
static mut DROPS: i32 = 0;

Expand Down Expand Up @@ -670,6 +672,7 @@ fn test_drop_clear() {
assert_eq!(unsafe { DROPS }, 4);
}

#[ignore]
#[test]
fn test_drop_panic() {
static mut DROPS: i32 = 0;
Expand Down
7 changes: 7 additions & 0 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ fn test_retain_pred_panic_no_hole() {
assert!(v.iter().all(|r| Rc::strong_count(r) == 1));
}

#[ignore]
#[test]
fn test_retain_drop_panic() {
struct Wrap(Rc<i32>);
Expand Down Expand Up @@ -509,6 +510,7 @@ fn test_vec_truncate_drop() {
assert_eq!(unsafe { DROPS }, 5);
}

#[ignore]
#[test]
#[should_panic]
fn test_vec_truncate_fail() {
Expand Down Expand Up @@ -752,6 +754,7 @@ fn test_drain_end_overflow() {
v.drain((Included(0), Included(usize::MAX)));
}

#[ignore]
#[test]
fn test_drain_leak() {
static mut DROPS: i32 = 0;
Expand Down Expand Up @@ -945,6 +948,7 @@ fn test_into_iter_clone() {
assert_eq!(it.next(), None);
}

#[ignore]
#[test]
fn test_into_iter_leak() {
static mut DROPS: i32 = 0;
Expand Down Expand Up @@ -1071,6 +1075,7 @@ fn test_from_iter_specialization_panic_during_iteration_drops() {
);
}

#[ignore]
#[test]
fn test_from_iter_specialization_panic_during_drop_leaks() {
static mut DROP_COUNTER: usize = 0;
Expand Down Expand Up @@ -1392,6 +1397,7 @@ fn drain_filter_consumed_panic() {
}

// FIXME: Re-enable emscripten once it can catch panics
#[ignore]
#[test]
#[cfg(not(target_os = "emscripten"))]
fn drain_filter_unconsumed_panic() {
Expand Down Expand Up @@ -2285,6 +2291,7 @@ fn test_vec_dedup() {
}
}

#[ignore]
#[test]
fn test_vec_dedup_panicking() {
#[derive(Debug)]
Expand Down
3 changes: 3 additions & 0 deletions library/alloc/tests/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ fn test_drop_clear() {
assert_eq!(unsafe { DROPS }, 4);
}

#[ignore]
#[test]
fn test_drop_panic() {
static mut DROPS: i32 = 0;
Expand Down Expand Up @@ -1619,6 +1620,7 @@ fn test_try_rfold_moves_iter() {
assert_eq!(iter.next_back(), Some(&70));
}

#[ignore]
#[test]
fn truncate_leak() {
static mut DROPS: i32 = 0;
Expand Down Expand Up @@ -1652,6 +1654,7 @@ fn truncate_leak() {
assert_eq!(unsafe { DROPS }, 7);
}

#[ignore]
#[test]
fn test_drain_leak() {
static mut DROPS: i32 = 0;
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/collections/hash/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ mod test_drain_filter {
}

#[test]
#[ignore]
fn drop_panic_leak() {
static PREDS: AtomicUsize = AtomicUsize::new(0);
static DROPS: AtomicUsize = AtomicUsize::new(0);
Expand Down Expand Up @@ -1041,6 +1042,7 @@ mod test_drain_filter {
}

#[test]
#[ignore]
fn pred_panic_leak() {
static PREDS: AtomicUsize = AtomicUsize::new(0);
static DROPS: AtomicUsize = AtomicUsize::new(0);
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/collections/hash/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ fn test_drain_filter() {
assert_eq!(y.len(), 1);
}

#[ignore]
#[test]
fn test_drain_filter_drop_panic_leak() {
static PREDS: AtomicU32 = AtomicU32::new(0);
Expand Down Expand Up @@ -458,6 +459,7 @@ fn test_drain_filter_drop_panic_leak() {
}

#[test]
#[ignore]
fn test_drain_filter_pred_panic_leak() {
static PREDS: AtomicU32 = AtomicU32::new(0);
static DROPS: AtomicU32 = AtomicU32::new(0);
Expand Down
9 changes: 5 additions & 4 deletions src/test/codegen/dealloc-no-unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ impl Drop for A {
}

#[no_mangle]
pub fn a(a: Box<i32>) {
pub fn a(b: Box<i32>) {
// CHECK-LABEL: define{{.*}}void @a
// CHECK: call void @__rust_dealloc
// CHECK-NEXT: call void @foo
let _a = A;
drop(a);
// CHECK-NOT: call void @foo
let a = A;
drop(b);
std::mem::forget(a);
}
2 changes: 1 addition & 1 deletion src/test/codegen/issue-47442.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// check that we don't emit unneeded `resume` cleanup blocks for every
// destructor.

// CHECK-NOT: Unwind
// CHECK-NOT: _Unwind_Resume

#![feature(test)]
#![crate_type="rlib"]
Expand Down
19 changes: 0 additions & 19 deletions src/test/codegen/vec-shrink-panik.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,13 @@ pub fn shrink_to_fit(vec: &mut Vec<u32>) {
// CHECK-LABEL: @issue71861
#[no_mangle]
pub fn issue71861(vec: Vec<u32>) -> Box<[u32]> {
// CHECK-NOT: panic

// Call to panic_no_unwind in case of double-panic is expected,
// but other panics are not.
// CHECK: cleanup
// CHECK-NEXT: ; call core::panicking::panic_no_unwind
// CHECK-NEXT: panic_no_unwind

// CHECK-NOT: panic
vec.into_boxed_slice()
}

// CHECK-LABEL: @issue75636
#[no_mangle]
pub fn issue75636<'a>(iter: &[&'a str]) -> Box<[&'a str]> {
// CHECK-NOT: panic

// Call to panic_no_unwind in case of double-panic is expected,
// but other panics are not.
// CHECK: cleanup
// CHECK-NEXT: ; call core::panicking::panic_no_unwind
// CHECK-NEXT: panic_no_unwind

// CHECK-NOT: panic
iter.iter().copied().collect()
}

// CHECK: ; core::panicking::panic_no_unwind
// CHECK: declare void @{{.*}}panic_no_unwind
6 changes: 1 addition & 5 deletions src/test/mir-opt/const_prop/boxes.main.ConstProp.diff
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
_2 = (*_3); // scope 0 at $DIR/boxes.rs:12:13: 12:22
_1 = Add(move _2, const 0_i32); // scope 0 at $DIR/boxes.rs:12:13: 12:26
StorageDead(_2); // scope 0 at $DIR/boxes.rs:12:25: 12:26
drop(_3) -> [return: bb2, unwind: bb3]; // scope 0 at $DIR/boxes.rs:12:26: 12:27
drop(_3) -> bb2; // scope 0 at $DIR/boxes.rs:12:26: 12:27
}

bb2: {
Expand All @@ -49,9 +49,5 @@
StorageDead(_1); // scope 0 at $DIR/boxes.rs:13:1: 13:2
return; // scope 0 at $DIR/boxes.rs:13:2: 13:2
}

bb3 (cleanup): {
resume; // scope 0 at $DIR/boxes.rs:11:1: 13:2
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,56 +29,47 @@ fn main::{closure#0}(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:10:15: 1

bb0: {
_8 = discriminant((*_1)); // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
switchInt(move _8) -> [0_u32: bb7, 3_u32: bb10, otherwise: bb11]; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
switchInt(move _8) -> [0_u32: bb5, 3_u32: bb8, otherwise: bb9]; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
}

bb1: {
StorageDead(_5); // scope 1 at $DIR/generator-drop-cleanup.rs:12:13: 12:14
StorageDead(_4); // scope 1 at $DIR/generator-drop-cleanup.rs:12:14: 12:15
drop((((*_1) as variant#3).0: std::string::String)) -> [return: bb2, unwind: bb5]; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
drop((((*_1) as variant#3).0: std::string::String)) -> bb2; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
}

bb2: {
nop; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
goto -> bb8; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
goto -> bb6; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
}

bb3: {
return; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
}

bb4 (cleanup): {
resume; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
bb4: {
return; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
}

bb5 (cleanup): {
nop; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
goto -> bb4; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
bb5: {
goto -> bb7; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
}

bb6: {
return; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
goto -> bb3; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
}

bb7: {
goto -> bb9; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
goto -> bb4; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
}

bb8: {
goto -> bb3; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
}

bb9: {
goto -> bb6; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
}

bb10: {
StorageLive(_4); // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
StorageLive(_5); // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
goto -> bb1; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
}

bb11: {
bb9: {
return; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6
}
}
Loading