Skip to content

Commit 9cdad78

Browse files
committed
Auto merge of #126274 - jieyouxu:rollup-uj93sfm, r=jieyouxu
Rollup of 5 pull requests Successful merges: - #126186 (Migrate `run-make/multiple-emits` to `rmake.rs`) - #126236 (Delegation: fix ICE on recursive delegation) - #126254 (Remove ignore-cross-compile directive from ui/macros/proc_macro) - #126258 (Do not define opaque types when selecting impls) - #126265 (interpret: ensure we check bool/char for validity when they are used in a cast) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5cc316c + 9218c7c commit 9cdad78

6 files changed

+125
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Make sure we find these even with many checks disabled.
2+
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
3+
#![feature(core_intrinsics)]
4+
#![feature(custom_mir)]
5+
6+
use std::intrinsics::mir::*;
7+
8+
#[custom_mir(dialect = "runtime", phase = "optimized")]
9+
fn cast(ptr: *const char) -> u32 {
10+
mir! {
11+
{
12+
RET = *ptr as u32; //~ERROR: interpreting an invalid 32-bit value as a char
13+
Return()
14+
}
15+
}
16+
}
17+
18+
pub fn main() {
19+
let v = u32::MAX;
20+
cast(&v as *const u32 as *const char);
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: Undefined Behavior: interpreting an invalid 32-bit value as a char: $HEX
2+
--> $DIR/invalid_char_cast.rs:LL:CC
3+
|
4+
LL | RET = *ptr as u32;
5+
| ^^^^^^^^^^^^^^^^^ interpreting an invalid 32-bit value as a char: $HEX
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `cast` at $DIR/invalid_char_cast.rs:LL:CC
11+
note: inside `main`
12+
--> $DIR/invalid_char_cast.rs:LL:CC
13+
|
14+
LL | cast(&v as *const u32 as *const char);
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
18+
19+
error: aborting due to 1 previous error
20+
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Make sure we find these even with many checks disabled.
2+
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
3+
#![feature(core_intrinsics)]
4+
#![feature(custom_mir)]
5+
6+
use std::intrinsics::mir::*;
7+
8+
#[custom_mir(dialect = "runtime", phase = "optimized")]
9+
fn switch_int(ptr: *const char) {
10+
mir! {
11+
{
12+
match *ptr { //~ERROR: interpreting an invalid 32-bit value as a char
13+
'0' => ret,
14+
_ => ret,
15+
}
16+
}
17+
ret = {
18+
Return()
19+
}
20+
}
21+
}
22+
23+
pub fn main() {
24+
let v = u32::MAX;
25+
switch_int(&v as *const u32 as *const char);
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: Undefined Behavior: interpreting an invalid 32-bit value as a char: $HEX
2+
--> $DIR/invalid_char_match.rs:LL:CC
3+
|
4+
LL | / match *ptr {
5+
LL | | '0' => ret,
6+
LL | | _ => ret,
7+
LL | | }
8+
| |_____________^ interpreting an invalid 32-bit value as a char: $HEX
9+
|
10+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
11+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
12+
= note: BACKTRACE:
13+
= note: inside `switch_int` at $DIR/invalid_char_match.rs:LL:CC
14+
note: inside `main`
15+
--> $DIR/invalid_char_match.rs:LL:CC
16+
|
17+
LL | switch_int(&v as *const u32 as *const char);
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
20+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
21+
22+
error: aborting due to 1 previous error
23+
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Make sure we find these even with many checks disabled.
2+
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
3+
4+
#[derive(Copy, Clone)]
5+
#[allow(unused)]
6+
enum E {A, B, C }
7+
8+
fn cast(ptr: *const E) { unsafe {
9+
let _val = *ptr as u32; //~ERROR: enum value has invalid tag
10+
}}
11+
12+
pub fn main() {
13+
let v = u32::MAX;
14+
cast(&v as *const u32 as *const E);
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: Undefined Behavior: enum value has invalid tag: 0xff
2+
--> $DIR/invalid_enum_cast.rs:LL:CC
3+
|
4+
LL | let _val = *ptr as u32;
5+
| ^^^^^^^^^^^ enum value has invalid tag: 0xff
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `cast` at $DIR/invalid_enum_cast.rs:LL:CC
11+
note: inside `main`
12+
--> $DIR/invalid_enum_cast.rs:LL:CC
13+
|
14+
LL | cast(&v as *const u32 as *const E);
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
18+
19+
error: aborting due to 1 previous error
20+

0 commit comments

Comments
 (0)