Skip to content
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

Avoid error patterns matching themselves #2158

Merged
merged 13 commits into from
May 30, 2022
5 changes: 3 additions & 2 deletions miri
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ test|test-debug|bless|bless-debug)
;;
esac
# Then test, and let caller control flags.
# Only in root project as `cargo-miri` has no tests.
exec cargo test $CARGO_BUILD_FLAGS "$@"
# Only in root project and ui_test as `cargo-miri` has no tests.
cargo test $CARGO_BUILD_FLAGS "$@"
cargo test $CARGO_BUILD_FLAGS --manifest-path ui_test/Cargo.toml "$@"
;;
run|run-debug)
# Scan for "--target" to set the "MIRI_TEST_TARGET" env var so
Expand Down
2 changes: 1 addition & 1 deletion tests/compile-fail/intrinsics/copy_unaligned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ fn main() {
let mut data = [0u16; 8];
let ptr = (&mut data[0] as *mut u16 as *mut u8).wrapping_add(1) as *mut u16;
// Even copying 0 elements to something unaligned should error
unsafe { copy_nonoverlapping(&data[5], ptr, 0); } //~ ERROR accessing memory with alignment ALIGN, but alignment ALIGN is required
unsafe { copy_nonoverlapping(&data[5], ptr, 0); } //~ ERROR accessing memory with alignment 1, but alignment 2 is required
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ static X: usize = 5;
#[allow(mutable_transmutes)]
fn main() {
let _x = unsafe {
std::mem::transmute::<&usize, &mut usize>(&X) //~ ERROR writing to ALLOC which is read-only
std::mem::transmute::<&usize, &mut usize>(&X) //~ ERROR writing to alloc1 which is read-only
};
}
2 changes: 1 addition & 1 deletion tests/compile-fail/unaligned_pointers/dyn_alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ fn main() {
// Overwrite the data part of `ptr` so it points to `buf`.
unsafe { (&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8); }
// Re-borrow that. This should be UB.
let _ptr = &*ptr; //~ERROR alignment ALIGN is required
let _ptr = &*ptr; //~ERROR alignment 256 is required
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ fn main() {
// Manually make sure the pointer is properly aligned.
let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr+1 };
let u16_ptr = base_addr_aligned as *mut u16;
unsafe { *u16_ptr = 2; } //~ERROR memory with alignment ALIGN, but alignment ALIGN is required
unsafe { *u16_ptr = 2; } //~ERROR memory with alignment 1, but alignment 2 is required
println!("{:?}", x);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ fn main() {
y: 99,
};
let p = &foo.x;
let i = *p; //~ERROR alignment ALIGN is required
let i = *p; //~ERROR alignment 4 is required
}
}
2 changes: 1 addition & 1 deletion tests/compile-fail/unaligned_pointers/unaligned_ptr1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ fn main() {
let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
let x = &x[0] as *const _ as *const u32;
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
let _x = unsafe { *x }; //~ERROR memory with alignment ALIGN, but alignment ALIGN is required
let _x = unsafe { *x }; //~ERROR memory with alignment 2, but alignment 4 is required
}
}
2 changes: 1 addition & 1 deletion tests/compile-fail/unaligned_pointers/unaligned_ptr2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ fn main() {
let x = (x.as_ptr() as *const u8).wrapping_offset(3) as *const u32;
// This must fail because alignment is violated: the offset is not sufficiently aligned.
// Also make the offset not a power of 2, that used to ICE.
let _x = unsafe { *x }; //~ERROR memory with alignment ALIGN, but alignment ALIGN is required
let _x = unsafe { *x }; //~ERROR memory with alignment 1, but alignment 4 is required
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ fn main() {
let x = &x[0] as *const _ as *const u32;
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
// The deref is UB even if we just put the result into a raw pointer.
let _x = unsafe { ptr::addr_of!(*x) }; //~ ERROR memory with alignment ALIGN, but alignment ALIGN is required
let _x = unsafe { ptr::addr_of!(*x) }; //~ ERROR memory with alignment 2, but alignment 4 is required
}
}
2 changes: 1 addition & 1 deletion tests/compile-fail/unaligned_pointers/unaligned_ptr_zst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ fn main() {
let x = i as u8;
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 alignment ALIGN is required
let _x = unsafe { *x }; //~ERROR alignment 4 is required
}
}
2 changes: 1 addition & 1 deletion tests/compile-fail/validity/dangling_ref1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
use std::mem;

fn main() {
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address $HEX is unallocated)
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address 0x10 is unallocated)
}
2 changes: 1 addition & 1 deletion tests/compile-fail/validity/invalid_char.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
assert!(std::char::from_u32(-1_i32 as u32).is_none());
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR encountered $HEX, but expected a valid unicode scalar value
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR encountered 0xffffffff, but expected a valid unicode scalar value
'a' => {true},
'b' => {false},
_ => {true},
Expand Down
3 changes: 3 additions & 0 deletions tests/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ fn run_tests(mode: Mode, path: &str, target: Option<String>) {
(true, true) => panic!("cannot use MIRI_BLESS and MIRI_SKIP_UI_CHECKS at the same time"),
};

let path_filter = std::env::args().skip(1).next();

let config = Config {
args: flags,
target,
stderr_filters: STDERR.clone(),
stdout_filters: STDOUT.clone(),
root_dir: PathBuf::from(path),
mode,
path_filter,
program: miri_path(),
output_conflict_handling,
};
Expand Down
Loading