Skip to content

Commit d606172

Browse files
committed
Auto merge of #1381 - RalfJung:rustup, r=RalfJung
rustup; fix for changed error messages
2 parents 04f235d + 393165f commit d606172

18 files changed

+22
-20
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e94eaa6dce468928b4e1326b2f0054f3075681ff
1+
fd61d06772d17c6242265d860fbfb5eafd282caa

src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub enum TerminationInfo {
1616
Deadlock,
1717
}
1818

19-
impl fmt::Debug for TerminationInfo {
19+
impl fmt::Display for TerminationInfo {
2020
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2121
use TerminationInfo::*;
2222
match self {

src/intptrcast.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashMap;
99
use rustc_mir::interpret::{AllocCheck, AllocId, InterpResult, Memory, Machine, Pointer, PointerArithmetic};
1010
use rustc_target::abi::{Size, HasDataLayout};
1111

12-
use crate::{Evaluator, Tag, STACK_ADDR};
12+
use crate::{Evaluator, Tag, STACK_ADDR, CheckInAllocMsg};
1313

1414
pub type MemoryExtra = RefCell<GlobalState>;
1515

@@ -46,14 +46,16 @@ impl<'mir, 'tcx> GlobalState {
4646
let global_state = memory.extra.intptrcast.borrow();
4747
let pos = global_state.int_to_ptr_map.binary_search_by_key(&int, |(addr, _)| *addr);
4848

49+
// The int must be in-bounds after being cast to a pointer, so we error
50+
// with `CheckInAllocMsg::InboundsTest`.
4951
Ok(match pos {
5052
Ok(pos) => {
5153
let (_, alloc_id) = global_state.int_to_ptr_map[pos];
5254
// `int` is equal to the starting address for an allocation, the offset should be
5355
// zero. The pointer is untagged because it was created from a cast
5456
Pointer::new_with_tag(alloc_id, Size::from_bytes(0), Tag::Untagged)
5557
}
56-
Err(0) => throw_ub!(InvalidIntPointerUsage(int)),
58+
Err(0) => throw_ub!(DanglingIntPointer(int, CheckInAllocMsg::InboundsTest)),
5759
Err(pos) => {
5860
// This is the largest of the adresses smaller than `int`,
5961
// i.e. the greatest lower bound (glb)
@@ -65,7 +67,7 @@ impl<'mir, 'tcx> GlobalState {
6567
// This pointer is untagged because it was created from a cast
6668
Pointer::new_with_tag(alloc_id, Size::from_bytes(offset), Tag::Untagged)
6769
} else {
68-
throw_ub!(InvalidIntPointerUsage(int))
70+
throw_ub!(DanglingIntPointer(int, CheckInAllocMsg::InboundsTest))
6971
}
7072
}
7173
})

tests/compile-fail/dangling_pointers/deref-invalid-ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
fn main() {
55
let x = 16usize as *const u32;
6-
let _y = unsafe { &*x as *const u32 }; //~ ERROR invalid use of 16 as a pointer
6+
let _y = unsafe { &*x as *const u32 }; //~ ERROR inbounds test failed: 0x10 is not a valid pointer
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
22
let p = 44 as *const i32;
3-
let x = unsafe { *p }; //~ ERROR invalid use of 44 as a pointer
3+
let x = unsafe { *p }; //~ ERROR inbounds test failed: 0x2c is not a valid pointer
44
panic!("this should never print: {}", x);
55
}

tests/compile-fail/function_pointers/cast_int_to_fn_ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ fn main() {
66
std::mem::transmute::<usize, fn(i32)>(42)
77
};
88

9-
g(42) //~ ERROR invalid use of 42 as a pointer
9+
g(42) //~ ERROR inbounds test failed: 0x2a is not a valid pointer
1010
}

tests/compile-fail/intrinsics/copy_null.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ fn main() {
99
let mut data = [0u16; 4];
1010
let ptr = &mut data[0] as *mut u16;
1111
// Even copying 0 elements from NULL should error.
12-
unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); } //~ ERROR: invalid use of NULL pointer
12+
unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); } //~ ERROR: memory access failed: 0x0 is not a valid pointer
1313
}

tests/compile-fail/intrinsics/ptr_offset_0_plus_0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern: invalid use of NULL pointer
1+
// error-pattern: inbounds test failed: 0x0 is not a valid pointer
22

33
fn main() {
44
let x = 0 as *mut i32;

tests/compile-fail/intrinsics/ptr_offset_int_plus_int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern: invalid use of 1 as a pointer
1+
// error-pattern: inbounds test failed: 0x1 is not a valid pointer
22

33
fn main() {
44
// Can't offset an integer pointer by non-zero offset.

tests/compile-fail/intrinsics/ptr_offset_int_plus_ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern: invalid use of 1 as a pointer
1+
// error-pattern: inbounds test failed: 0x1 is not a valid pointer
22

33
fn main() {
44
let ptr = Box::into_raw(Box::new(0u32));

0 commit comments

Comments
 (0)