Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/fail/branchless-select-i128-pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ fn main() {
// This is branchless code to select one or the other pointer.
// However, it drops provenance when transmuting to TwoPtrs, so this is UB.
let val = unsafe {
transmute::<_, &str>( //~ERROR type validation failed: encountered a dangling reference
!mask & transmute::<_, TwoPtrs>("false !") | mask & transmute::<_, TwoPtrs>("true !"),
transmute::<_, &str>(
//~^ ERROR type validation failed: encountered a dangling reference
!mask & transmute::<_, TwoPtrs>("false !")
| mask & transmute::<_, TwoPtrs>("true !"),
)
};
println!("{}", val);
Expand Down
4 changes: 3 additions & 1 deletion tests/fail/branchless-select-i128-pointer.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error: Undefined Behavior: type validation failed: encountered a dangling refere
--> $DIR/branchless-select-i128-pointer.rs:LL:CC
|
LL | / transmute::<_, &str>(
LL | | !mask & transmute::<_, TwoPtrs>("false !") | mask & transmute::<_, TwoPtrs>("true !"),
LL | |
LL | | !mask & transmute::<_, TwoPtrs>("false !")
LL | | | mask & transmute::<_, TwoPtrs>("true !"),
LL | | )
| |_____________^ type validation failed: encountered a dangling reference (address $HEX is unallocated)
|
Expand Down
9 changes: 7 additions & 2 deletions tests/fail/data_race/dealloc_read_race1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ pub fn main() {

unsafe {
let j1 = spawn(move || {
*ptr.0
let _val = *ptr.0;
});
Comment on lines 21 to 23
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a behavior change, but I did this to preserve the way both spawn use a multiline block. This is similar to #2244 (comment). With the behavior change it still correctly tests what the test was intended to cover.


let j2 = spawn(move || {
__rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>()); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1)
__rust_dealloc(
//~^ ERROR Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1)
ptr.0 as *mut _,
std::mem::size_of::<usize>(),
std::mem::align_of::<usize>(),
);
});

j1.join().unwrap();
Expand Down
9 changes: 7 additions & 2 deletions tests/fail/data_race/dealloc_read_race1.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
error: Undefined Behavior: Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock)
--> $DIR/dealloc_read_race1.rs:LL:CC
|
LL | __rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock)
LL | / __rust_dealloc(
LL | |
LL | | ptr.0 as *mut _,
LL | | std::mem::size_of::<usize>(),
LL | | std::mem::align_of::<usize>(),
LL | | );
| |_____________^ Data race detected between Deallocate on Thread(id = 2) and Read on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock)
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Expand Down
7 changes: 6 additions & 1 deletion tests/fail/data_race/dealloc_write_race1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ pub fn main() {
});

let j2 = spawn(move || {
__rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>()); //~ ERROR Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1)
__rust_dealloc(
//~^ ERROR Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1)
ptr.0 as *mut _,
std::mem::size_of::<usize>(),
std::mem::align_of::<usize>(),
);
});

j1.join().unwrap();
Expand Down
9 changes: 7 additions & 2 deletions tests/fail/data_race/dealloc_write_race1.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
error: Undefined Behavior: Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock)
--> $DIR/dealloc_write_race1.rs:LL:CC
|
LL | __rust_dealloc(ptr.0 as *mut _, std::mem::size_of::<usize>(), std::mem::align_of::<usize>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock)
LL | / __rust_dealloc(
LL | |
LL | | ptr.0 as *mut _,
LL | | std::mem::size_of::<usize>(),
LL | | std::mem::align_of::<usize>(),
LL | | );
| |_____________^ Data race detected between Deallocate on Thread(id = 2) and Write on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock)
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Expand Down
3 changes: 2 additions & 1 deletion tests/fail/function_calls/check_callback_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ fn main() {
unsafe {
// Make sure we check the ABI when Miri itself invokes a function
// as part of a shim implementation.
std::intrinsics::r#try( //~ ERROR calling a function with ABI C using caller ABI Rust
std::intrinsics::r#try(
//~^ ERROR calling a function with ABI C using caller ABI Rust
std::mem::transmute::<extern "C" fn(*mut u8), _>(try_fn),
std::ptr::null_mut(),
|_, _| unreachable!(),
Expand Down
1 change: 1 addition & 0 deletions tests/fail/function_calls/check_callback_abi.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ error: Undefined Behavior: calling a function with ABI C using caller ABI Rust
--> $DIR/check_callback_abi.rs:LL:CC
|
LL | / std::intrinsics::r#try(
LL | |
LL | | std::mem::transmute::<extern "C" fn(*mut u8), _>(try_fn),
LL | | std::ptr::null_mut(),
LL | | |_, _| unreachable!(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: calling a function with calling convention Rust using calling convention C
--> $DIR/exported_symbol_abi_mismatch.rs:LL:CC
|
LL | unsafe { foo() }
| ^^^^^ calling a function with calling convention Rust using calling convention C
LL | foo();
| ^^^^^ calling a function with calling convention Rust using calling convention C
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: calling a function with calling convention Rust using calling convention C
--> $DIR/exported_symbol_abi_mismatch.rs:LL:CC
|
LL | unsafe { std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention Rust using calling convention C
LL | std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention Rust using calling convention C
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: calling a function with calling convention Rust using calling convention C
--> $DIR/exported_symbol_abi_mismatch.rs:LL:CC
|
LL | unsafe { foo() }
| ^^^^^ calling a function with calling convention Rust using calling convention C
LL | foo();
| ^^^^^ calling a function with calling convention Rust using calling convention C
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Expand Down
18 changes: 12 additions & 6 deletions tests/fail/function_calls/exported_symbol_abi_mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ fn main() {
}

#[cfg(fn_ptr)]
unsafe { std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)() }
//[fn_ptr]~^ ERROR calling a function with calling convention Rust using calling convention C
unsafe {
std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)();
//[fn_ptr]~^ ERROR calling a function with calling convention Rust using calling convention C
}

// `Instance` caching should not suppress ABI check.
#[cfg(cache)]
unsafe { foo() }
unsafe {
foo();
}

{
#[cfg_attr(any(cache, fn_ptr), allow(clashing_extern_declarations))]
extern "C" {
fn foo();
}
unsafe { foo() }
//[no_cache]~^ ERROR calling a function with calling convention Rust using calling convention C
//[cache]~^^ ERROR calling a function with calling convention Rust using calling convention C
unsafe {
foo();
//[no_cache]~^ ERROR calling a function with calling convention Rust using calling convention C
//[cache]~| ERROR calling a function with calling convention Rust using calling convention C
}
}
}
4 changes: 2 additions & 2 deletions tests/fail/type-too-large.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ignore-32bit

fn main() {
let _fat: [u8; (1<<61)+(1<<31)] =
[0; (1u64<<61) as usize +(1u64<<31) as usize]; //~ ERROR post-monomorphization error
let _fat: [u8; (1 << 61) + (1 << 31)];
_fat = [0; (1u64 << 61) as usize + (1u64 << 31) as usize]; //~ ERROR post-monomorphization error
Comment on lines -4 to +5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rustfmt wanted to do one line for all this. I split into 2 statements to preserve the specificity of the test in checking that the error is triggered on the rhs, not on the binding's pattern or type.

}
4 changes: 2 additions & 2 deletions tests/fail/type-too-large.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: post-monomorphization error: values of the type `[u8; 2305843011361177600]` are too big for the current architecture
--> $DIR/type-too-large.rs:LL:CC
|
LL | [0; (1u64<<61) as usize +(1u64<<31) as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ values of the type `[u8; 2305843011361177600]` are too big for the current architecture
LL | _fat = [0; (1u64 << 61) as usize + (1u64 << 31) as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ values of the type `[u8; 2305843011361177600]` are too big for the current architecture
|
= note: inside `main` at $DIR/type-too-large.rs:LL:CC

Expand Down
9 changes: 5 additions & 4 deletions tests/fail/validity/invalid_char.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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 0xffffffff, but expected a valid unicode scalar value
'a' => {true},
'b' => {false},
_ => {true},
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,
};
}
11 changes: 7 additions & 4 deletions tests/pass/0weak_memory_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ fn test_corr() {
x.store(2, Relaxed);
});

#[rustfmt::skip]
let j2 = spawn(move || {
let r2 = x.load(Relaxed); // -------------------------------------+
y.store(1, Release); // ---------------------+ |
r2 // | |
}); // | |
// |synchronizes-with |happens-before
#[rustfmt::skip] // |synchronizes-with |happens-before
let j3 = spawn(move || { // | |
acquires_value(&y, 1); // <------------------+ |
x.load(Relaxed) // <----------------------------------------------+
Expand All @@ -80,15 +81,16 @@ fn test_wrc() {
let x = static_atomic(0);
let y = static_atomic(0);

#[rustfmt::skip]
let j1 = spawn(move || {
x.store(1, Release); // ---------------------+---------------------+
}); // | |
// |synchronizes-with |
#[rustfmt::skip] // |synchronizes-with |
let j2 = spawn(move || { // | |
acquires_value(&x, 1); // <------------------+ |
y.store(1, Release); // ---------------------+ |happens-before
}); // | |
// |synchronizes-with |
#[rustfmt::skip] // |synchronizes-with |
let j3 = spawn(move || { // | |
acquires_value(&y, 1); // <------------------+ |
x.load(Relaxed) // <-----------------------------------------------+
Expand All @@ -107,11 +109,12 @@ fn test_message_passing() {
let x = EvilSend(ptr);
let y = static_atomic(0);

#[rustfmt::skip]
let j1 = spawn(move || {
unsafe { *x.0 = 1 }; // -----------------------------------------+
y.store(1, Release); // ---------------------+ |
}); // | |
// |synchronizes-with | happens-before
#[rustfmt::skip] // |synchronizes-with | happens-before
let j2 = spawn(move || { // | |
acquires_value(&y, 1); // <------------------+ |
unsafe { *x.0 } // <---------------------------------------------+
Expand Down
Loading