From 2802c3cf0b91e18de1f37e24929a406033df0cc0 Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Wed, 11 Mar 2020 16:02:49 +0200 Subject: [PATCH] Add tests for the new panic_if_any_invalid, panic_if_zero_invalid intrinsics --- tests/run-pass/panic/catch_panic.rs | 39 ++++++++++++++++++++++--- tests/run-pass/panic/catch_panic.stderr | 22 +++++++++++--- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/tests/run-pass/panic/catch_panic.rs b/tests/run-pass/panic/catch_panic.rs index 33c2beb682ae..a406fd434a05 100644 --- a/tests/run-pass/panic/catch_panic.rs +++ b/tests/run-pass/panic/catch_panic.rs @@ -69,10 +69,41 @@ fn main() { // libcore panics from shims. #[allow(deprecated, invalid_value)] - test( - Some("Attempted to instantiate uninhabited type !"), - |_old_val| unsafe { std::mem::uninitialized::() }, - ); + { + test( + Some("attempted to instantiate uninhabited type !"), + |_old_val| unsafe { std::mem::uninitialized::() }, + ); + test( + Some("attempted to zero-initialize type `!`, which is invalid"), + |_old_val| unsafe { std::mem::zeroed::() }, + ); + test( + Some("attempted to leave type `fn()` uninitialized, which is invalid"), + |_old_val| unsafe { std::mem::uninitialized::(); loop {} }, + ); + test( + Some("attempted to zero-initialize type `fn()`, which is invalid"), + |_old_val| unsafe { std::mem::zeroed::(); loop {} }, + ); + test( + Some("attempted to leave type `*const dyn std::marker::Sync` uninitialized, which is invalid"), + |_old_val| unsafe { std::mem::uninitialized::<*const dyn Sync>(); loop {} }, + ); + test( + Some("attempted to zero-initialize type `*mut dyn std::marker::Sync`, which is invalid"), + |_old_val| unsafe { std::mem::zeroed::<*mut dyn Sync>(); loop {} }, + ); + test( + Some("attempted to leave type `&u8` uninitialized, which is invalid"), + |_old_val| unsafe { std::mem::uninitialized::<&u8>(); loop {} }, + ); + test( + Some("attempted to zero-initialize type `&u8`, which is invalid"), + |_old_val| unsafe { std::mem::zeroed::<&u8>(); loop {} }, + ); + } + test( Some("align_offset: align is not a power-of-two"), |_old_val| { (0usize as *const u8).align_offset(3); loop {} }, diff --git a/tests/run-pass/panic/catch_panic.stderr b/tests/run-pass/panic/catch_panic.stderr index 4ff22fe2176a..1899ea3c684a 100644 --- a/tests/run-pass/panic/catch_panic.stderr +++ b/tests/run-pass/panic/catch_panic.stderr @@ -16,13 +16,27 @@ thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 4' Caught panic message (String): index out of bounds: the len is 3 but the index is 4 thread 'main' panicked at 'attempt to divide by zero', $DIR/catch_panic.rs:67:33 Caught panic message (String): attempt to divide by zero -thread 'main' panicked at 'Attempted to instantiate uninhabited type !', $LOC -Caught panic message (String): Attempted to instantiate uninhabited type ! +thread 'main' panicked at 'attempted to instantiate uninhabited type !', $LOC +Caught panic message (String): attempted to instantiate uninhabited type ! +thread 'main' panicked at 'attempted to zero-initialize type `!`, which is invalid', $LOC +Caught panic message (String): attempted to zero-initialize type `!`, which is invalid +thread 'main' panicked at 'attempted to leave type `fn()` uninitialized, which is invalid', $LOC +Caught panic message (String): attempted to leave type `fn()` uninitialized, which is invalid +thread 'main' panicked at 'attempted to zero-initialize type `fn()`, which is invalid', $LOC +Caught panic message (String): attempted to zero-initialize type `fn()`, which is invalid +thread 'main' panicked at 'attempted to leave type `*const dyn std::marker::Sync` uninitialized, which is invalid', $LOC +Caught panic message (String): attempted to leave type `*const dyn std::marker::Sync` uninitialized, which is invalid +thread 'main' panicked at 'attempted to zero-initialize type `*mut dyn std::marker::Sync`, which is invalid', $LOC +Caught panic message (String): attempted to zero-initialize type `*mut dyn std::marker::Sync`, which is invalid +thread 'main' panicked at 'attempted to leave type `&u8` uninitialized, which is invalid', $LOC +Caught panic message (String): attempted to leave type `&u8` uninitialized, which is invalid +thread 'main' panicked at 'attempted to zero-initialize type `&u8`, which is invalid', $LOC +Caught panic message (String): attempted to zero-initialize type `&u8`, which is invalid thread 'main' panicked at 'align_offset: align is not a power-of-two', $LOC Caught panic message (String): align_offset: align is not a power-of-two -thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:82:29 +thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:113:29 Caught panic message (&str): assertion failed: false -thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:83:29 +thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:114:29 Caught panic message (&str): assertion failed: false thread 'main' panicked at 'attempt to copy from unaligned or null pointer', $LOC Caught panic message (String): attempt to copy from unaligned or null pointer