This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
src/tools/miri/tests/fail Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ #![ feature( core_intrinsics) ]
2+ #![ feature( custom_mir) ]
3+
4+ use std:: intrinsics:: mir:: * ;
5+ use std:: ptr;
6+
7+ #[ repr( C ) ]
8+ struct S ( u8 , u16 ) ;
9+
10+ #[ custom_mir( dialect = "runtime" , phase = "optimized" ) ]
11+ fn main ( ) {
12+ mir ! {
13+ let s: S ;
14+ let sptr;
15+ let sptr2;
16+ let _val;
17+ {
18+ sptr = ptr:: addr_of_mut!( s) ;
19+ sptr2 = sptr as * mut [ u8 ; 4 ] ;
20+ * sptr2 = [ 0 ; 4 ] ;
21+ * sptr = S ( 0 , 0 ) ; // should reset the padding
22+ _val = * sptr2; // should hence be UB
23+ //~^ERROR: encountered uninitialized memory
24+ Return ( )
25+ }
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ error: Undefined Behavior: constructing invalid value at [1]: encountered uninitialized memory, but expected an integer
2+ --> $DIR/uninit-after-aggregate-assign.rs:LL:CC
3+ |
4+ LL | _val = *sptr2; // should hence be UB
5+ | ^^^^^^^^^^^^^ constructing invalid value at [1]: encountered uninitialized memory, but expected an integer
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 `main` at $DIR/uninit-after-aggregate-assign.rs:LL:CC
11+
12+ note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+ error: aborting due to 1 previous error
15+
You can’t perform that action at this time.
0 commit comments