about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/overlapping_assignment.rs
blob: 84994c179f9eae03f5dafa3467ed2535ecaadb52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#![feature(core_intrinsics)]
#![feature(custom_mir)]

use std::intrinsics::mir::*;

// It's not that easy to fool the MIR validity check
// which wants to prevent overlapping assignments...
// So we use two separate pointer arguments, and then arrange for them to alias.
#[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn self_copy(ptr1: *mut [i32; 4], ptr2: *mut [i32; 4]) {
    mir! {
        {
            *ptr1 = *ptr2; //~ERROR: overlapping ranges
            Return()
        }
    }
}

pub fn main() {
    let mut x = [0; 4];
    let ptr = std::ptr::addr_of_mut!(x);
    self_copy(ptr, ptr);
}