Skip to content

Commit 2802c3c

Browse files
committed
Add tests for the new panic_if_any_invalid, panic_if_zero_invalid intrinsics
1 parent e81ebff commit 2802c3c

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

tests/run-pass/panic/catch_panic.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,41 @@ fn main() {
6969

7070
// libcore panics from shims.
7171
#[allow(deprecated, invalid_value)]
72-
test(
73-
Some("Attempted to instantiate uninhabited type !"),
74-
|_old_val| unsafe { std::mem::uninitialized::<!>() },
75-
);
72+
{
73+
test(
74+
Some("attempted to instantiate uninhabited type !"),
75+
|_old_val| unsafe { std::mem::uninitialized::<!>() },
76+
);
77+
test(
78+
Some("attempted to zero-initialize type `!`, which is invalid"),
79+
|_old_val| unsafe { std::mem::zeroed::<!>() },
80+
);
81+
test(
82+
Some("attempted to leave type `fn()` uninitialized, which is invalid"),
83+
|_old_val| unsafe { std::mem::uninitialized::<fn()>(); loop {} },
84+
);
85+
test(
86+
Some("attempted to zero-initialize type `fn()`, which is invalid"),
87+
|_old_val| unsafe { std::mem::zeroed::<fn()>(); loop {} },
88+
);
89+
test(
90+
Some("attempted to leave type `*const dyn std::marker::Sync` uninitialized, which is invalid"),
91+
|_old_val| unsafe { std::mem::uninitialized::<*const dyn Sync>(); loop {} },
92+
);
93+
test(
94+
Some("attempted to zero-initialize type `*mut dyn std::marker::Sync`, which is invalid"),
95+
|_old_val| unsafe { std::mem::zeroed::<*mut dyn Sync>(); loop {} },
96+
);
97+
test(
98+
Some("attempted to leave type `&u8` uninitialized, which is invalid"),
99+
|_old_val| unsafe { std::mem::uninitialized::<&u8>(); loop {} },
100+
);
101+
test(
102+
Some("attempted to zero-initialize type `&u8`, which is invalid"),
103+
|_old_val| unsafe { std::mem::zeroed::<&u8>(); loop {} },
104+
);
105+
}
106+
76107
test(
77108
Some("align_offset: align is not a power-of-two"),
78109
|_old_val| { (0usize as *const u8).align_offset(3); loop {} },

tests/run-pass/panic/catch_panic.stderr

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,27 @@ thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 4'
1616
Caught panic message (String): index out of bounds: the len is 3 but the index is 4
1717
thread 'main' panicked at 'attempt to divide by zero', $DIR/catch_panic.rs:67:33
1818
Caught panic message (String): attempt to divide by zero
19-
thread 'main' panicked at 'Attempted to instantiate uninhabited type !', $LOC
20-
Caught panic message (String): Attempted to instantiate uninhabited type !
19+
thread 'main' panicked at 'attempted to instantiate uninhabited type !', $LOC
20+
Caught panic message (String): attempted to instantiate uninhabited type !
21+
thread 'main' panicked at 'attempted to zero-initialize type `!`, which is invalid', $LOC
22+
Caught panic message (String): attempted to zero-initialize type `!`, which is invalid
23+
thread 'main' panicked at 'attempted to leave type `fn()` uninitialized, which is invalid', $LOC
24+
Caught panic message (String): attempted to leave type `fn()` uninitialized, which is invalid
25+
thread 'main' panicked at 'attempted to zero-initialize type `fn()`, which is invalid', $LOC
26+
Caught panic message (String): attempted to zero-initialize type `fn()`, which is invalid
27+
thread 'main' panicked at 'attempted to leave type `*const dyn std::marker::Sync` uninitialized, which is invalid', $LOC
28+
Caught panic message (String): attempted to leave type `*const dyn std::marker::Sync` uninitialized, which is invalid
29+
thread 'main' panicked at 'attempted to zero-initialize type `*mut dyn std::marker::Sync`, which is invalid', $LOC
30+
Caught panic message (String): attempted to zero-initialize type `*mut dyn std::marker::Sync`, which is invalid
31+
thread 'main' panicked at 'attempted to leave type `&u8` uninitialized, which is invalid', $LOC
32+
Caught panic message (String): attempted to leave type `&u8` uninitialized, which is invalid
33+
thread 'main' panicked at 'attempted to zero-initialize type `&u8`, which is invalid', $LOC
34+
Caught panic message (String): attempted to zero-initialize type `&u8`, which is invalid
2135
thread 'main' panicked at 'align_offset: align is not a power-of-two', $LOC
2236
Caught panic message (String): align_offset: align is not a power-of-two
23-
thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:82:29
37+
thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:113:29
2438
Caught panic message (&str): assertion failed: false
25-
thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:83:29
39+
thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:114:29
2640
Caught panic message (&str): assertion failed: false
2741
thread 'main' panicked at 'attempt to copy from unaligned or null pointer', $LOC
2842
Caught panic message (String): attempt to copy from unaligned or null pointer

0 commit comments

Comments
 (0)