From 3c39dc2cba7434e88e580274d20e5d4ae0f8ab1c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 3 Aug 2023 14:14:14 +0200 Subject: [PATCH] add test checking that overlapping assignments work --- src/tools/miri/tests/pass/ptr_raw.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/tools/miri/tests/pass/ptr_raw.rs b/src/tools/miri/tests/pass/ptr_raw.rs index 3ba0fba9a94..2f184358907 100644 --- a/src/tools/miri/tests/pass/ptr_raw.rs +++ b/src/tools/miri/tests/pass/ptr_raw.rs @@ -20,6 +20,15 @@ fn basic_raw() { assert_eq!(*x, 23); } +fn assign_overlapping() { + // Test an assignment where LHS and RHS alias. + // In Mir, that's UB (see `fail/overlapping_assignment.rs`), but in surface Rust this is allowed. + let mut mem = [0u32; 4]; + let ptr = &mut mem as *mut [u32; 4]; + unsafe { *ptr = *ptr }; +} + fn main() { basic_raw(); + assign_overlapping(); }