File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1
- d4096e0412ac5de785d739a0aa2b1c1c7b9d3b7d
1
+ 743333f3dd90721461c09387ec73d09c080d5f5f
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
+
6
+ // It's not that easy to fool the MIR validity check
7
+ // which wants to prevent overlapping assignments...
8
+ // So we use two separate pointer arguments, and then arrange for them to alias.
9
+ #[ custom_mir( dialect = "runtime" , phase = "optimized" ) ]
10
+ pub fn self_copy ( ptr1 : * mut [ i32 ; 4 ] , ptr2 : * mut [ i32 ; 4 ] ) {
11
+ mir ! {
12
+ {
13
+ * ptr1 = * ptr2; //~ERROR: overlapping ranges
14
+ Return ( )
15
+ }
16
+ }
17
+ }
18
+
19
+ pub fn main ( ) {
20
+ let mut x = [ 0 ; 4 ] ;
21
+ let ptr = std:: ptr:: addr_of_mut!( x) ;
22
+ self_copy ( ptr, ptr) ;
23
+ }
Original file line number Diff line number Diff line change
1
+ error: Undefined Behavior: `copy_nonoverlapping` called on overlapping ranges
2
+ --> $DIR/overlapping_assignment.rs:LL:CC
3
+ |
4
+ LL | *ptr1 = *ptr2;
5
+ | ^^^^^^^^^^^^^ `copy_nonoverlapping` called on overlapping ranges
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 `self_copy` at $DIR/overlapping_assignment.rs:LL:CC
11
+ note: inside `main`
12
+ --> $DIR/overlapping_assignment.rs:LL:CC
13
+ |
14
+ LL | self_copy(ptr, ptr);
15
+ | ^^^^^^^^^^^^^^^^^^^
16
+
17
+ note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
18
+
19
+ error: aborting due to previous error
20
+
You can’t perform that action at this time.
0 commit comments