From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/mir-opt/array_index_is_temporary.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/mir-opt/array_index_is_temporary.rs (limited to 'tests/mir-opt/array_index_is_temporary.rs') diff --git a/tests/mir-opt/array_index_is_temporary.rs b/tests/mir-opt/array_index_is_temporary.rs new file mode 100644 index 000000000..e7bde81d4 --- /dev/null +++ b/tests/mir-opt/array_index_is_temporary.rs @@ -0,0 +1,17 @@ +// Retagging (from Stacked Borrows) relies on the array index being a fresh +// temporary, so that side-effects cannot change it. +// Test that this is indeed the case. + +unsafe fn foo(z: *mut usize) -> u32 { + *z = 2; + 99 +} + + +// EMIT_MIR array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.mir +fn main() { + let mut x = [42, 43, 44]; + let mut y = 1; + let z: *mut usize = &mut y; + x[y] = unsafe { foo(z) }; +} -- cgit v1.2.3