Skip to content

Commit 704228d

Browse files
committed
Auto merge of #1220 - elichai:2020-03-bump, r=RalfJung
Bump rust-version to latest I hoped for some errors I could fix to learn more of the codebase but got none :/ IDK if it's still worth the PR hehe (is there a TODO list or something like that I can look at when I'm in the mood of contributing to Miri? :) )
2 parents 676c4f8 + 548c90e commit 704228d

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3dbade652ed8ebac70f903e01f51cd92c4e4302c
1+
303d8aff6092709edd4dbd35b1c88e9aa40bf6d8

src/shims/intrinsics.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
444444
this.write_scalar(result_ptr, dest)?;
445445
}
446446

447-
"panic_if_uninhabited" => {
447+
"panic_if_uninhabited" |
448+
"panic_if_zero_invalid" |
449+
"panic_if_any_invalid" => {
448450
let ty = substs.type_at(0);
449451
let layout = this.layout_of(ty)?;
450452
if layout.abi.is_uninhabited() {
451453
// Return here because we paniced instead of returning normally from the intrinsic.
452-
return this.start_panic(&format!("Attempted to instantiate uninhabited type {}", ty), unwind);
454+
return this.start_panic(&format!("attempted to instantiate uninhabited type `{}`", ty), unwind);
455+
}
456+
if intrinsic_name == "panic_if_zero_invalid" && !layout.might_permit_raw_init(this, /*zero:*/ true).unwrap() {
457+
// Return here because we paniced instead of returning normally from the intrinsic.
458+
return this.start_panic(&format!("attempted to zero-initialize type `{}`, which is invalid", ty), unwind);
459+
}
460+
if intrinsic_name == "panic_if_any_invalid" && !layout.might_permit_raw_init(this, /*zero:*/ false).unwrap() {
461+
// Return here because we paniced instead of returning normally from the intrinsic.
462+
return this.start_panic(&format!("attempted to leave type `{}` uninitialized, which is invalid", ty), unwind);
453463
}
454464
}
455465

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 instantiate uninhabited type `!`"),
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 instantiate uninhabited type `!`', $LOC
22+
Caught panic message (String): attempted to instantiate uninhabited type `!`
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)