-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
182 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
tests/fail-dep/concurrency/libc_pthread_cond_move.init.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: Undefined Behavior: pthread_cond_t can't be moved after first use | ||
--> $DIR/libc_pthread_cond_move.rs:LL:CC | ||
| | ||
LL | libc::pthread_cond_destroy(cond2.as_mut_ptr()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pthread_cond_t can't be moved after first use | ||
| | ||
= 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 | ||
= note: BACKTRACE: | ||
= note: inside `check` at $DIR/libc_pthread_cond_move.rs:LL:CC | ||
note: inside `main` | ||
--> $DIR/libc_pthread_cond_move.rs:LL:CC | ||
| | ||
LL | check() | ||
| ^^^^^^^ | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//@revisions: static_initializer init | ||
//@ignore-target-windows: No pthreads on Windows | ||
|
||
/// Test that moving a pthread_cond between uses fails. | ||
|
||
fn main() { | ||
check() | ||
} | ||
|
||
#[cfg(init)] | ||
fn check() { | ||
unsafe { | ||
use core::mem::MaybeUninit; | ||
let mut cond = MaybeUninit::<libc::pthread_cond_t>::uninit(); | ||
|
||
libc::pthread_cond_init(cond.as_mut_ptr(), std::ptr::null()); | ||
|
||
// move pthread_cond_t | ||
let mut cond2 = cond; | ||
|
||
libc::pthread_cond_destroy(cond2.as_mut_ptr()); //~[init] ERROR: pthread_cond_t can't be moved after first use | ||
} | ||
} | ||
|
||
#[cfg(static_initializer)] | ||
fn check() { | ||
unsafe { | ||
let mut cond = libc::PTHREAD_COND_INITIALIZER; | ||
|
||
libc::pthread_cond_signal(&mut cond as *mut _); | ||
|
||
// move pthread_cond_t | ||
let mut cond2 = cond; | ||
|
||
libc::pthread_cond_destroy(&mut cond2 as *mut _); //~[static_initializer] ERROR: pthread_cond_t can't be moved after first use | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/fail-dep/concurrency/libc_pthread_cond_move.static_initializer.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: Undefined Behavior: pthread_cond_t can't be moved after first use | ||
--> $DIR/libc_pthread_cond_move.rs:LL:CC | ||
| | ||
LL | libc::pthread_cond_destroy(&mut cond2 as *mut _); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pthread_cond_t can't be moved after first use | ||
| | ||
= 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 | ||
= note: BACKTRACE: | ||
= note: inside `check` at $DIR/libc_pthread_cond_move.rs:LL:CC | ||
note: inside `main` | ||
--> $DIR/libc_pthread_cond_move.rs:LL:CC | ||
| | ||
LL | check() | ||
| ^^^^^^^ | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|