Convert some of the tests to the new format
This commit is contained in:
parent
569792acbc
commit
8ae66db798
45 changed files with 91 additions and 55 deletions
|
|
@ -5,7 +5,8 @@ fn main() {
|
|||
let x_ptr: *mut u8 = &mut x[0];
|
||||
let y_ptr = x_ptr as *mut u64;
|
||||
unsafe {
|
||||
*y_ptr = 42; //~ ERROR tried to access memory with alignment 1, but alignment
|
||||
*y_ptr = 42; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to access memory with alignment 1, but alignment
|
||||
}
|
||||
panic!("unreachable in miri");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ fn main() {
|
|||
unsafe {
|
||||
std::intrinsics::assume(x < 10);
|
||||
std::intrinsics::assume(x > 1);
|
||||
std::intrinsics::assume(x > 42); //~ ERROR: `assume` argument was false
|
||||
std::intrinsics::assume(x > 42); //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE `assume` argument was false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,11 @@ fn mk_rec() -> Rec {
|
|||
fn is_u64_aligned(u: &Tag<u64>) -> bool {
|
||||
let p: usize = unsafe { mem::transmute(u) };
|
||||
let u64_align = std::mem::align_of::<u64>();
|
||||
return (p & (u64_align + 1)) == 0; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
|
||||
return (p & (u64_align + 1)) == 0; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let x = mk_rec();
|
||||
assert!(is_u64_aligned(&x.t));
|
||||
assert!(is_u64_aligned(&x.t)); //~ NOTE inside call to `is_u64_aligned
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ fn main() {
|
|||
std::mem::transmute::<&usize, &fn(i32)>(&b)
|
||||
};
|
||||
|
||||
(*g)(42) //~ ERROR a memory access tried to interpret some bytes as a pointer
|
||||
(*g)(42) //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE a memory access tried to interpret some bytes as a pointer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ fn main() {
|
|||
std::mem::transmute::<fn(), fn(i32)>(f)
|
||||
};
|
||||
|
||||
g(42) //~ ERROR tried to call a function with sig fn() through a function pointer of type fn(i32)
|
||||
g(42) //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to call a function with sig fn() through a function pointer of type fn(i32)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ fn main() {
|
|||
std::mem::transmute::<fn((i32,i32)), fn(i32)>(f)
|
||||
};
|
||||
|
||||
g(42) //~ ERROR tried to call a function with sig fn((i32, i32)) through a function pointer of type fn(i32)
|
||||
g(42) //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to call a function with sig fn((i32, i32)) through a function pointer of type fn(i32)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@ fn main() {
|
|||
std::mem::transmute::<usize, fn(i32)>(42)
|
||||
};
|
||||
|
||||
g(42) //~ ERROR a memory access tried to interpret some bytes as a pointer
|
||||
g(42) //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE a memory access tried to interpret some bytes as a pointer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ pub fn main() {
|
|||
unsafe {
|
||||
use rusti::*;
|
||||
|
||||
ctlz_nonzero(0u8); //~ ERROR: ctlz_nonzero called on 0
|
||||
ctlz_nonzero(0u8); //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE ctlz_nonzero called on 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ pub fn main() {
|
|||
unsafe {
|
||||
use rusti::*;
|
||||
|
||||
cttz_nonzero(0u8); //~ ERROR: cttz_nonzero called on 0
|
||||
cttz_nonzero(0u8); //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE cttz_nonzero called on 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ fn main() {
|
|||
let b = Box::new(42);
|
||||
&*b as *const i32
|
||||
};
|
||||
let x = unsafe { *p }; //~ ERROR: dangling pointer was dereferenced
|
||||
let x = unsafe { *p }; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE dangling pointer was dereferenced
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ fn f() {}
|
|||
|
||||
fn main() {
|
||||
let x: i32 = unsafe {
|
||||
*std::mem::transmute::<fn(), *const i32>(f) //~ ERROR: tried to dereference a function pointer
|
||||
*std::mem::transmute::<fn(), *const i32>(f) //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to dereference a function pointer
|
||||
};
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,5 +11,6 @@
|
|||
#![allow(const_err)]
|
||||
|
||||
fn main() {
|
||||
let _n = 1 / 0; //~ ERROR: DivisionByZero
|
||||
let _n = 1 / 0; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE attempt to divide by zero
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ fn main() {
|
|||
let x = box 42;
|
||||
unsafe {
|
||||
let f = std::mem::transmute::<Box<i32>, fn()>(x);
|
||||
f() //~ ERROR: tried to treat a memory pointer as a function pointer
|
||||
f() //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to treat a memory pointer as a function pointer
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,6 @@ fn main() {
|
|||
let y : *mut u8 = unsafe { mem::transmute(x) };
|
||||
let y = y.wrapping_offset(1);
|
||||
let x : fn() = unsafe { mem::transmute(y) };
|
||||
x(); //~ ERROR: tried to use a function pointer after offsetting it
|
||||
x(); //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to use a function pointer after offsetting it
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
fn main() {
|
||||
let b = unsafe { std::mem::transmute::<u8, bool>(2) }; //~ ERROR: invalid boolean value read
|
||||
if b { unreachable!() } else { unreachable!() }
|
||||
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
|
||||
if b { unreachable!() } else { unreachable!() } //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE invalid boolean value read
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ pub enum Foo {
|
|||
fn main() {
|
||||
let f = unsafe { std::mem::transmute::<i32, Foo>(42) };
|
||||
match f {
|
||||
Foo::A => {}, //~ ERROR invalid enum discriminant value read
|
||||
Foo::A => {},
|
||||
Foo::B => {},
|
||||
Foo::C => {},
|
||||
Foo::D => {},
|
||||
}
|
||||
}
|
||||
} //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE entered unreachable code
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
fn main() {
|
||||
let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is marked static, not the pointee
|
||||
let y = unsafe { &mut *(x as *const i32 as *mut i32) };
|
||||
*y = 42; //~ ERROR tried to modify constant memory
|
||||
*y = 42; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to modify constant memory
|
||||
assert_eq!(*x, 42);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
fn main() {
|
||||
let y = &5;
|
||||
let x: ! = unsafe {
|
||||
*(y as *const _ as *const !) //~ ERROR entered unreachable code
|
||||
*(y as *const _ as *const !) //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE entered unreachable code
|
||||
};
|
||||
f(x)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// This should fail even without validation
|
||||
// compile-fail causes rustc ICE: rust-lang/rust#50570
|
||||
// ignore-test causes rustc ICE: rust-lang/rust#50570
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
|
||||
#![feature(never_type)]
|
||||
|
|
|
|||
|
|
@ -8,12 +8,13 @@
|
|||
enum Void {}
|
||||
|
||||
fn f(v: Void) -> ! {
|
||||
match v {} //~ ERROR entered unreachable code
|
||||
match v {} //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE entered unreachable code
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let v: Void = unsafe {
|
||||
std::mem::transmute::<(), Void>(())
|
||||
};
|
||||
f(v);
|
||||
f(v); //~ inside call to `f`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
fn main() {
|
||||
let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR: invalid use of NULL pointer
|
||||
let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE invalid use of NULL pointer
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
#![feature(custom_attribute, attr_literals)]
|
||||
#![miri(memory_size=4095)]
|
||||
|
||||
fn main() {
|
||||
let _x = [42; 1024];
|
||||
//~^ERROR tried to allocate 4096 more bytes, but only
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
fn main() {
|
||||
let v: Vec<u8> = vec![1, 2];
|
||||
let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR: which has size 2
|
||||
let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE which has size 2
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
fn main() {
|
||||
let v: Vec<u8> = vec![1, 2];
|
||||
let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR: memory access at offset 6, outside bounds of allocation
|
||||
let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE memory access at offset 6, outside bounds of allocation
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,5 +12,6 @@
|
|||
#![allow(const_err)]
|
||||
|
||||
fn main() {
|
||||
let _n = 2i64 << -1; //~ Overflow(Shl)
|
||||
let _n = 2i64 << -1; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE attempt to shift left with overflow
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,5 +11,6 @@
|
|||
#![allow(exceeding_bitshifts)]
|
||||
|
||||
fn main() {
|
||||
let _n = 1i64 >> 64; //~ Overflow(Shr)
|
||||
let _n = 1i64 >> 64; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE attempt to shift right with overflow
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ fn main() {
|
|||
// "attempted to interpret some raw bytes as a pointer address" instead of
|
||||
// "attempted to read undefined bytes"
|
||||
}
|
||||
let x = *p; //~ ERROR: attempted to read undefined bytes
|
||||
let x = *p; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE attempted to read undefined bytes
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@ fn main() {
|
|||
let y = &x;
|
||||
let z = &y as *const &i32 as *const usize;
|
||||
let ptr_bytes = unsafe { *z }; // the actual deref is fine, because we read the entire pointer at once
|
||||
let _ = ptr_bytes % 432; //~ ERROR: tried to access part of a pointer value as raw bytes
|
||||
let _ = ptr_bytes % 432; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to access part of a pointer value as raw bytes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@ fn main() {
|
|||
let y = &x;
|
||||
let z = &y as *const &i32 as *const u8;
|
||||
// the deref fails, because we are reading only a part of the pointer
|
||||
let _ = unsafe { *z }; //~ ERROR: tried to access part of a pointer value as raw bytes
|
||||
let _ = unsafe { *z }; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to access part of a pointer value as raw bytes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
fn main() {
|
||||
let x: *const u8 = &1;
|
||||
let y: *const u8 = &2;
|
||||
if x < y { //~ ERROR: attempted to do invalid arithmetic on pointers
|
||||
if x < y { //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE attempted to do invalid arithmetic on pointers
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ fn main() {
|
|||
let bytes = [0i8, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
let one = bytes.as_ptr().wrapping_offset(1);
|
||||
let three = bytes.as_ptr().wrapping_offset(3);
|
||||
let res = (one as usize) | (three as usize); //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
|
||||
let res = (one as usize) | (three as usize); //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes
|
||||
println!("{}", res);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ fn main() {
|
|||
let x = &1;
|
||||
// Casting down to u8 and back up to a pointer loses too much precision; this must not work.
|
||||
let x = x as *const i32;
|
||||
let x = x as u8; //~ ERROR: a raw memory access tried to access part of a pointer value as raw bytes
|
||||
let x = x as u8; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes
|
||||
let x = x as *const i32;
|
||||
let _ = unsafe { *x };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ fn main() {
|
|||
// starts 1 byte to the right, so using it would actually be wrong!
|
||||
let d_alias = &mut w.data as *mut _ as *mut *const u8;
|
||||
unsafe {
|
||||
let _x = *d_alias; //~ ERROR: tried to access part of a pointer value as raw bytes
|
||||
let _x = *d_alias; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to access part of a pointer value as raw bytes
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ fn main() {
|
|||
unsafe {
|
||||
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1));
|
||||
let _y = Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
|
||||
let _z = *(x as *mut u8); //~ ERROR: dangling pointer was dereferenced
|
||||
let _z = *(x as *mut u8); //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE dangling pointer was dereferenced
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,5 +15,6 @@ fn main() {
|
|||
y: 99,
|
||||
};
|
||||
let p = unsafe { &foo.x };
|
||||
let i = *p; //~ ERROR tried to access memory with alignment 1, but alignment 4 is required
|
||||
let i = *p; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to access memory with alignment 1, but alignment 4 is required
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use std::mem::transmute;
|
|||
fn main() {
|
||||
unsafe {
|
||||
let s = "this is a test";
|
||||
transmute::<&[u8], &mut [u8]>(s.as_bytes())[4] = 42; //~ ERROR: tried to modify constant memory
|
||||
transmute::<&[u8], &mut [u8]>(s.as_bytes())[4] = 42; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to modify constant memory
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use std::mem::transmute;
|
|||
fn main() {
|
||||
unsafe {
|
||||
let bs = b"this is a test";
|
||||
transmute::<&[u8], &mut [u8]>(bs)[4] = 42; //~ ERROR: tried to modify constant memory
|
||||
transmute::<&[u8], &mut [u8]>(bs)[4] = 42; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to modify constant memory
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,5 +16,6 @@ fn main() {
|
|||
assert_eq!(byte, 0);
|
||||
}
|
||||
let v = unsafe { *z.offset(first_undef) };
|
||||
if v == 0 {} //~ ERROR attempted to read undefined bytes
|
||||
if v == 0 {} //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE attempted to read undefined bytes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,6 @@ fn main() {
|
|||
let bad = unsafe {
|
||||
std::mem::transmute::<&[u8], u64>(&[1u8])
|
||||
};
|
||||
let _ = bad + 1; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
|
||||
let _ = bad + 1; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ fn main() {
|
|||
let bad = unsafe {
|
||||
std::mem::transmute::<u64, &[u8]>(42)
|
||||
};
|
||||
bad[0]; //~ ERROR index out of bounds: the len is 0 but the index is 0
|
||||
bad[0]; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE index out of bounds: the len is 0 but the index is 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,5 +2,6 @@ fn main() {
|
|||
let x = &2u16;
|
||||
let x = x as *const _ as *const u32;
|
||||
// This must fail because alignment is violated
|
||||
let _x = unsafe { *x }; //~ ERROR: tried to access memory with alignment 2, but alignment 4 is required
|
||||
let _x = unsafe { *x }; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to access memory with alignment 2, but alignment 4 is required
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@ fn main() {
|
|||
let x = x as *const _ as *const *const u8;
|
||||
// This must fail because alignment is violated. Test specifically for loading pointers, which have special code
|
||||
// in miri's memory.
|
||||
let _x = unsafe { *x }; //~ ERROR: tried to access memory with alignment 2, but alignment
|
||||
let _x = unsafe { *x }; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to access memory with alignment 2, but alignment
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,5 +2,6 @@ fn main() {
|
|||
let x = &2u16;
|
||||
let x = x as *const _ as *const [u32; 0];
|
||||
// This must fail because alignment is violated. Test specifically for loading ZST.
|
||||
let _x = unsafe { *x }; //~ ERROR: tried to access memory with alignment 2, but alignment 4 is required
|
||||
let _x = unsafe { *x }; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to access memory with alignment 2, but alignment 4 is required
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
fn main() {
|
||||
let p = 44 as *const i32;
|
||||
let x = unsafe { *p }; //~ ERROR: a memory access tried to interpret some bytes as a pointer
|
||||
let x = unsafe { *p }; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE a memory access tried to interpret some bytes as a pointer
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
fn main() {
|
||||
let x = &() as *const () as *const i32;
|
||||
let _ = unsafe { *x }; //~ ERROR: tried to access memory with alignment 1, but alignment 4 is required
|
||||
let _ = unsafe { *x }; //~ ERROR constant evaluation error [E0080]
|
||||
//~^ NOTE tried to access memory with alignment 1, but alignment 4 is required
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue