Skip to content

Commit

Permalink
Auto merge of #1220 - elichai:2020-03-bump, r=RalfJung
Browse files Browse the repository at this point in the history
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? :) )
  • Loading branch information
bors committed Mar 11, 2020
2 parents 676c4f8 + 548c90e commit 704228d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3dbade652ed8ebac70f903e01f51cd92c4e4302c
303d8aff6092709edd4dbd35b1c88e9aa40bf6d8
14 changes: 12 additions & 2 deletions src/shims/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(result_ptr, dest)?;
}

"panic_if_uninhabited" => {
"panic_if_uninhabited" |
"panic_if_zero_invalid" |
"panic_if_any_invalid" => {
let ty = substs.type_at(0);
let layout = this.layout_of(ty)?;
if layout.abi.is_uninhabited() {
// Return here because we paniced instead of returning normally from the intrinsic.
return this.start_panic(&format!("Attempted to instantiate uninhabited type {}", ty), unwind);
return this.start_panic(&format!("attempted to instantiate uninhabited type `{}`", ty), unwind);
}
if intrinsic_name == "panic_if_zero_invalid" && !layout.might_permit_raw_init(this, /*zero:*/ true).unwrap() {
// Return here because we paniced instead of returning normally from the intrinsic.
return this.start_panic(&format!("attempted to zero-initialize type `{}`, which is invalid", ty), unwind);
}
if intrinsic_name == "panic_if_any_invalid" && !layout.might_permit_raw_init(this, /*zero:*/ false).unwrap() {
// Return here because we paniced instead of returning normally from the intrinsic.
return this.start_panic(&format!("attempted to leave type `{}` uninitialized, which is invalid", ty), unwind);
}
}

Expand Down
39 changes: 35 additions & 4 deletions tests/run-pass/panic/catch_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 instantiate uninhabited type `!`"),
|_old_val| unsafe { std::mem::zeroed::<!>() },
);
test(
Some("attempted to leave type `fn()` uninitialized, which is invalid"),
|_old_val| unsafe { std::mem::uninitialized::<fn()>(); loop {} },
);
test(
Some("attempted to zero-initialize type `fn()`, which is invalid"),
|_old_val| unsafe { std::mem::zeroed::<fn()>(); 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 {} },
Expand Down
22 changes: 18 additions & 4 deletions tests/run-pass/panic/catch_panic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 instantiate uninhabited type `!`', $LOC
Caught panic message (String): attempted to instantiate uninhabited type `!`
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
Expand Down

0 comments on commit 704228d

Please sign in to comment.