mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 18:27:37 +00:00

And introduce two new directives for ui tests: * `run-crash` * `run-fail-or-crash` Normally a `run-fail` ui test like tests that panic shall not be terminated by a signal like `SIGABRT`. So begin having that as a hard requirement. Some of our current tests do terminate by a signal/crash however. Introduce and use `run-crash` for those tests. Note that Windows crashes are not handled by signals but by certain high bits set on the process exit code. Example exit code for crash on Windows: `0xc000001d`. Because of this, we define "crash" on all platforms as "not exit with success and not exit with a regular failure code in the range 1..=127". Some tests behave differently on different targets: * Targets without unwind support will abort (crash) instead of exit with failure code 101 after panicking. As a special case, allow crashes for `run-fail` tests for such targets. * Different sanitizer implementations handle detected memory problems differently. Some abort (crash) the process while others exit with failure code 1. Introduce and use `run-fail-or-crash` for such tests.
28 lines
882 B
Rust
28 lines
882 B
Rust
//@ run-crash
|
|
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
|
|
//@ error-pattern: unsafe precondition(s) violated: ptr::swap_nonoverlapping requires
|
|
//@ revisions: null_src null_dst misaligned_src misaligned_dst overlapping
|
|
|
|
#![allow(invalid_null_arguments)]
|
|
|
|
use std::ptr;
|
|
|
|
fn main() {
|
|
let mut src = [0u16; 3];
|
|
let mut dst = [0u16; 3];
|
|
let src = src.as_mut_ptr();
|
|
let dst = dst.as_mut_ptr();
|
|
unsafe {
|
|
#[cfg(null_src)]
|
|
ptr::swap_nonoverlapping(ptr::null_mut(), dst, 1);
|
|
#[cfg(null_dst)]
|
|
ptr::swap_nonoverlapping(src, ptr::null_mut(), 1);
|
|
#[cfg(misaligned_src)]
|
|
ptr::swap_nonoverlapping(src.byte_add(1), dst, 1);
|
|
#[cfg(misaligned_dst)]
|
|
ptr::swap_nonoverlapping(src, dst.byte_add(1), 1);
|
|
#[cfg(overlapping)]
|
|
ptr::swap_nonoverlapping(dst, dst.add(1), 2);
|
|
}
|
|
}
|