File tree 2 files changed +74
-0
lines changed
src/tools/miri/tests/fail/function_calls
2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Doesn't need an aliasing model.
2
+ //@compile-flags: -Zmiri-disable-stacked-borrows
3
+ #![ feature( raw_ref_op) ]
4
+ #![ feature( core_intrinsics) ]
5
+ #![ feature( custom_mir) ]
6
+
7
+ use std:: intrinsics:: mir:: * ;
8
+ use std:: panic;
9
+
10
+ #[ repr( C ) ]
11
+ struct S ( i32 , [ u8 ; 128 ] ) ;
12
+
13
+ #[ custom_mir( dialect = "runtime" , phase = "optimized" ) ]
14
+ fn docall ( out : & mut S ) {
15
+ mir ! {
16
+ {
17
+ Call ( * out = callee( ) , after_call)
18
+ }
19
+
20
+ after_call = {
21
+ Return ( )
22
+ }
23
+ }
24
+ }
25
+
26
+ fn startpanic ( ) -> ( ) {
27
+ panic ! ( )
28
+ }
29
+
30
+ #[ custom_mir( dialect = "runtime" , phase = "optimized" ) ]
31
+ fn callee ( ) -> S {
32
+ mir ! {
33
+ type RET = S ;
34
+ let _unit: ( ) ;
35
+ {
36
+ // We test whether changes done to RET before unwinding
37
+ // become visible to the outside. In codegen we can see them
38
+ // but Miri should detect this as UB!
39
+ RET . 0 = 42 ;
40
+ Call ( _unit = startpanic( ) , after_call)
41
+ }
42
+
43
+ after_call = {
44
+ Return ( )
45
+ }
46
+ }
47
+ }
48
+
49
+ fn main ( ) {
50
+ let mut x = S ( 0 , [ 0 ; 128 ] ) ;
51
+ panic:: catch_unwind ( panic:: AssertUnwindSafe ( || docall ( & mut x) ) ) . unwrap_err ( ) ;
52
+ // The return place got de-initialized before the call and assigning to RET
53
+ // does not propagate if we do not reach the `Return`.
54
+ dbg ! ( x. 0 ) ; //~ERROR: uninitialized
55
+ }
Original file line number Diff line number Diff line change
1
+ thread 'main' panicked at $DIR/return_pointer_on_unwind.rs:LL:CC:
2
+ explicit panic
3
+ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4
+ error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
5
+ --> $DIR/return_pointer_on_unwind.rs:LL:CC
6
+ |
7
+ LL | dbg!(x.0);
8
+ | ^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
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 `main` at RUSTLIB/std/src/macros.rs:LL:CC
14
+ = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
15
+
16
+ note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
17
+
18
+ error: aborting due to previous error
19
+
You can’t perform that action at this time.
0 commit comments