Skip to content

rustup; test for return type mismatch #467

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

Merged
merged 5 commits into from
Oct 10, 2018
Merged
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
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2018-10-01
nightly-2018-10-10
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
type MemoryKinds = MiriMemoryKind;

const MUT_STATIC_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::MutStatic);
const ENFORCE_VALIDITY: bool = false; // this is still WIP

/// Returns Ok() when the function was handled, fail otherwise
fn find_fn(
Expand Down
10 changes: 5 additions & 5 deletions src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
// allocations sit right next to each other. The C/C++ standards are
// somewhat fuzzy about this case, so I think for now this check is
// "good enough".
self.memory.check_bounds(left, false)?;
self.memory.check_bounds(right, false)?;
self.memory.check_bounds_ptr(left, false)?;
self.memory.check_bounds_ptr(right, false)?;
// Two live in-bounds pointers, we can compare across allocations
left == right
}
Expand All @@ -153,7 +153,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
(Scalar::Bits { bits, size }, Scalar::Ptr(ptr)) => {
assert_eq!(size as u64, self.pointer_size().bytes());
let bits = bits as u64;
let (alloc_size, alloc_align) = self.memory.get_size_and_align(ptr.alloc_id)?;
let (alloc_size, alloc_align) = self.memory.get_size_and_align(ptr.alloc_id);

// Case I: Comparing with NULL
if bits == 0 {
Expand Down Expand Up @@ -296,9 +296,9 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
if let Scalar::Ptr(ptr) = ptr {
// Both old and new pointer must be in-bounds.
// (Of the same allocation, but that part is trivial with our representation.)
self.memory.check_bounds(ptr, false)?;
self.memory.check_bounds_ptr(ptr, false)?;
let ptr = ptr.signed_offset(offset, self)?;
self.memory.check_bounds(ptr, false)?;
self.memory.check_bounds_ptr(ptr, false)?;
Ok(Scalar::Ptr(ptr))
} else {
// An integer pointer. They can move around freely, as long as they do not overflow
Expand Down
9 changes: 9 additions & 0 deletions tests/compile-fail/cast_fn_ptr5.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() {
fn f() -> u32 { 42 }

let g = unsafe {
std::mem::transmute::<fn() -> u32, fn()>(f)
};

g() //~ ERROR tried to call a function with return type u32 passing return place of type ()
}
4 changes: 2 additions & 2 deletions tests/compile-fail/deref_fn_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fn f() {}

fn main() {
let x: i32 = unsafe {
*std::mem::transmute::<fn(), *const i32>(f) //~ ERROR constant evaluation error: tried to dereference a function pointer
let x: u8 = unsafe {
*std::mem::transmute::<fn(), *const u8>(f) //~ ERROR constant evaluation error: tried to dereference a function pointer
};
panic!("this should never print: {}", x);
}