Skip to content

Commit

Permalink
Merge from rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
The Miri Cronjob Bot committed Mar 24, 2024
2 parents c9178fa + 1b11211 commit 6ecfcbb
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/fail/intrinsics/typed-swap-invalid-array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![feature(core_intrinsics)]
#![feature(rustc_attrs)]

use std::intrinsics::typed_swap;
use std::ptr::addr_of_mut;

fn invalid_array() {
let mut a = [1_u8; 100];
let mut b = [2_u8; 100];
unsafe {
let a = addr_of_mut!(a).cast::<[bool; 100]>();
let b = addr_of_mut!(b).cast::<[bool; 100]>();
typed_swap(a, b); //~ERROR: constructing invalid value
}
}

fn main() {
invalid_array();
}
20 changes: 20 additions & 0 deletions tests/fail/intrinsics/typed-swap-invalid-array.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: Undefined Behavior: constructing invalid value at [0]: encountered 0x02, but expected a boolean
--> $DIR/typed-swap-invalid-array.rs:LL:CC
|
LL | typed_swap(a, b);
| ^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered 0x02, but expected a boolean
|
= 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 `invalid_array` at $DIR/typed-swap-invalid-array.rs:LL:CC
note: inside `main`
--> $DIR/typed-swap-invalid-array.rs:LL:CC
|
LL | invalid_array();
| ^^^^^^^^^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

19 changes: 19 additions & 0 deletions tests/fail/intrinsics/typed-swap-invalid-scalar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![feature(core_intrinsics)]
#![feature(rustc_attrs)]

use std::intrinsics::typed_swap;
use std::ptr::addr_of_mut;

fn invalid_scalar() {
let mut a = 1_u8;
let mut b = 2_u8;
unsafe {
let a = addr_of_mut!(a).cast::<bool>();
let b = addr_of_mut!(b).cast::<bool>();
typed_swap(a, b); //~ERROR: constructing invalid value
}
}

fn main() {
invalid_scalar();
}
20 changes: 20 additions & 0 deletions tests/fail/intrinsics/typed-swap-invalid-scalar.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: Undefined Behavior: constructing invalid value: encountered 0x02, but expected a boolean
--> $DIR/typed-swap-invalid-scalar.rs:LL:CC
|
LL | typed_swap(a, b);
| ^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0x02, but expected a boolean
|
= 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 `invalid_scalar` at $DIR/typed-swap-invalid-scalar.rs:LL:CC
note: inside `main`
--> $DIR/typed-swap-invalid-scalar.rs:LL:CC
|
LL | invalid_scalar();
| ^^^^^^^^^^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

0 comments on commit 6ecfcbb

Please sign in to comment.