Skip to content

Commit 5a496dd

Browse files
authored
Merge pull request #467 from solson/rustup
rustup; test for return type mismatch
2 parents c91d8dc + 6ae988f commit 5a496dd

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2018-10-01
1+
nightly-2018-10-10

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
233233
type MemoryKinds = MiriMemoryKind;
234234

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

237238
/// Returns Ok() when the function was handled, fail otherwise
238239
fn find_fn(

src/operator.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
142142
// allocations sit right next to each other. The C/C++ standards are
143143
// somewhat fuzzy about this case, so I think for now this check is
144144
// "good enough".
145-
self.memory.check_bounds(left, false)?;
146-
self.memory.check_bounds(right, false)?;
145+
self.memory.check_bounds_ptr(left, false)?;
146+
self.memory.check_bounds_ptr(right, false)?;
147147
// Two live in-bounds pointers, we can compare across allocations
148148
left == right
149149
}
@@ -153,7 +153,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
153153
(Scalar::Bits { bits, size }, Scalar::Ptr(ptr)) => {
154154
assert_eq!(size as u64, self.pointer_size().bytes());
155155
let bits = bits as u64;
156-
let (alloc_size, alloc_align) = self.memory.get_size_and_align(ptr.alloc_id)?;
156+
let (alloc_size, alloc_align) = self.memory.get_size_and_align(ptr.alloc_id);
157157

158158
// Case I: Comparing with NULL
159159
if bits == 0 {
@@ -296,9 +296,9 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
296296
if let Scalar::Ptr(ptr) = ptr {
297297
// Both old and new pointer must be in-bounds.
298298
// (Of the same allocation, but that part is trivial with our representation.)
299-
self.memory.check_bounds(ptr, false)?;
299+
self.memory.check_bounds_ptr(ptr, false)?;
300300
let ptr = ptr.signed_offset(offset, self)?;
301-
self.memory.check_bounds(ptr, false)?;
301+
self.memory.check_bounds_ptr(ptr, false)?;
302302
Ok(Scalar::Ptr(ptr))
303303
} else {
304304
// An integer pointer. They can move around freely, as long as they do not overflow

tests/compile-fail/cast_fn_ptr5.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
fn f() -> u32 { 42 }
3+
4+
let g = unsafe {
5+
std::mem::transmute::<fn() -> u32, fn()>(f)
6+
};
7+
8+
g() //~ ERROR tried to call a function with return type u32 passing return place of type ()
9+
}

tests/compile-fail/deref_fn_ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fn f() {}
22

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

0 commit comments

Comments
 (0)