]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/array-index-is-temporary.rs
Rollup merge of #100445 - krasimirgg:llvm-16-msan, r=tmiasko
[rust.git] / src / test / mir-opt / array-index-is-temporary.rs
1 // Retagging (from Stacked Borrows) relies on the array index being a fresh
2 // temporary, so that side-effects cannot change it.
3 // Test that this is indeed the case.
4
5 unsafe fn foo(z: *mut usize) -> u32 {
6     *z = 2;
7     99
8 }
9
10 // EMIT_MIR_FOR_EACH_BIT_WIDTH
11 // EMIT_MIR array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.mir
12 fn main() {
13     let mut x = [42, 43, 44];
14     let mut y = 1;
15     let z: *mut usize = &mut y;
16     x[y] = unsafe { foo(z) };
17 }