summaryrefslogtreecommitdiff
path: root/src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.rs
blob: b2ec23bda02c5eadb4e6241d6dfdb5392f88b8bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//@error-in-other-file: /deallocation .* tag does not exist in the borrow stack/
use std::alloc::{alloc, dealloc, Layout};

fn main() {
    unsafe {
        let x = alloc(Layout::from_size_align_unchecked(1, 1));
        let ptr1 = (&mut *x) as *mut u8;
        let ptr2 = (&mut *ptr1) as *mut u8;
        // Invalidate ptr2 by writing to ptr1.
        ptr1.write(0);
        // Deallocate through ptr2.
        dealloc(ptr2, Layout::from_size_align_unchecked(1, 1));
    }
}