enable validation for compile-fail tests, and add some new ones
This commit is contained in:
parent
62b819ba18
commit
c9cf0344ee
@ -1,5 +1,5 @@
|
||||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let b = Box::new(42);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let g = unsafe {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
#![feature(box_syntax)]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
use std::mem;
|
||||
|
||||
|
@ -1,9 +1,3 @@
|
||||
//ignore-test FIXME: do some basic validation of invariants for all values in flight
|
||||
//This does currently not get caught becuase it compiles to SwitchInt, which
|
||||
//has no knowledge about data invariants.
|
||||
|
||||
fn main() {
|
||||
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
|
||||
if b { unreachable!() } else { unreachable!() } //~ ERROR constant evaluation error
|
||||
//~^ NOTE invalid boolean value read
|
||||
let _b = unsafe { std::mem::transmute::<u8, bool>(2) }; //~ ERROR encountered 2, but expected something in the range 0..=1
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
|
||||
let _x = b == true; //~ ERROR invalid boolean value read
|
||||
|
8
tests/compile-fail/invalid_char.rs
Normal file
8
tests/compile-fail/invalid_char.rs
Normal file
@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
assert!(std::char::from_u32(-1_i32 as u32).is_none());
|
||||
let _ = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR encountered 4294967295, but expected something in the range 0..=1114111
|
||||
'a' => {true},
|
||||
'b' => {false},
|
||||
_ => {true},
|
||||
};
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
assert!(std::char::from_u32(-1_i32 as u32).is_none());
|
||||
let c = unsafe { std::mem::transmute::<i32, char>(-1) };
|
@ -1,17 +1,8 @@
|
||||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
|
||||
#[repr(C)]
|
||||
pub enum Foo {
|
||||
A, B, C, D
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let f = unsafe { std::mem::transmute::<i32, Foo>(42) };
|
||||
match f {
|
||||
Foo::A => {}, //~ ERROR invalid enum discriminant
|
||||
Foo::B => {},
|
||||
Foo::C => {},
|
||||
Foo::D => {},
|
||||
}
|
||||
let _f = unsafe { std::mem::transmute::<i32, Foo>(42) }; //~ ERROR encountered invalid enum discriminant 42
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Validation makes this fail in the wrong place
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
// error-pattern: invalid enum discriminant
|
||||
|
||||
|
@ -1,13 +0,0 @@
|
||||
//ignore-test FIXME: do some basic validation of invariants for all values in flight
|
||||
//This does currently not get caught becuase it compiles to SwitchInt, which
|
||||
//has no knowledge about data invariants.
|
||||
|
||||
fn main() {
|
||||
assert!(std::char::from_u32(-1_i32 as u32).is_none());
|
||||
let _ = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR constant evaluation error
|
||||
//~^ NOTE tried to interpret an invalid 32-bit value as a char: 4294967295
|
||||
'a' => {true},
|
||||
'b' => {false},
|
||||
_ => {true},
|
||||
};
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
#![feature(never_type)]
|
||||
#![allow(unreachable_code)]
|
||||
|
@ -1,5 +1,5 @@
|
||||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
#![feature(never_type)]
|
||||
#![allow(unreachable_code)]
|
||||
|
@ -1,5 +1,5 @@
|
||||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
#![feature(never_type)]
|
||||
#![allow(unreachable_code)]
|
||||
|
@ -1,5 +1,5 @@
|
||||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
#![allow(dead_code, unused_variables)]
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
// This should fail even without validation
|
||||
// compile-flags: -Zmir-emit-validate=0 -Zmiri-disable-validation
|
||||
|
||||
static mut LEAK: usize = 0;
|
||||
|
||||
fn fill(v: &mut i32) {
|
||||
|
10
tests/compile-fail/validation_cast_fn_ptr1.rs
Normal file
10
tests/compile-fail/validation_cast_fn_ptr1.rs
Normal file
@ -0,0 +1,10 @@
|
||||
fn main() {
|
||||
// Cast a function pointer such that on a call, the argument gets transmuted
|
||||
// from raw ptr to reference. This is ABI-compatible, so it's not the call that
|
||||
// should fail, but validation should.
|
||||
fn f(_x: &i32) { }
|
||||
|
||||
let g: fn(*const i32) = unsafe { std::mem::transmute(f as fn(&i32)) };
|
||||
|
||||
g(0usize as *const i32) //~ ERROR encountered 0, but expected something greater or equal to 1
|
||||
}
|
10
tests/compile-fail/validation_cast_fn_ptr2.rs
Normal file
10
tests/compile-fail/validation_cast_fn_ptr2.rs
Normal file
@ -0,0 +1,10 @@
|
||||
fn main() {
|
||||
// Cast a function pointer such that when returning, the return value gets transmuted
|
||||
// from raw ptr to reference. This is ABI-compatible, so it's not the call that
|
||||
// should fail, but validation should.
|
||||
fn f() -> *const i32 { 0usize as *const i32 }
|
||||
|
||||
let g: fn() -> &'static i32 = unsafe { std::mem::transmute(f as fn() -> *const i32) };
|
||||
|
||||
let _x = g(); //~ ERROR encountered 0, but expected something greater or equal to 1
|
||||
}
|
@ -64,7 +64,6 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, need_fullm
|
||||
flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
|
||||
config.src_base = PathBuf::from(path.to_string());
|
||||
flags.push("-Zmir-emit-validate=1".to_owned());
|
||||
flags.push("-Zmiri-disable-validation".to_owned());
|
||||
config.target_rustcflags = Some(flags.join(" "));
|
||||
config.target = target.to_owned();
|
||||
config.host = host.to_owned();
|
||||
|
Loading…
x
Reference in New Issue
Block a user