diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-02-17 17:36:43 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2023-02-27 20:02:18 +0000 |
| commit | 2a32a2b64faf52b65080ea84b5bc110627294954 (patch) | |
| tree | 348b02aededbc14d33b0a67c4c1e68c6b3a7bd86 /tests/mir-opt/copy-prop/reborrow.rs | |
| parent | 43ee4d15bf201f72c36abd7f02961df87dead441 (diff) | |
| download | rust-2a32a2b64faf52b65080ea84b5bc110627294954.tar.gz rust-2a32a2b64faf52b65080ea84b5bc110627294954.zip | |
Special case deref projections in SsaVisitor.
Diffstat (limited to 'tests/mir-opt/copy-prop/reborrow.rs')
| -rw-r--r-- | tests/mir-opt/copy-prop/reborrow.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/mir-opt/copy-prop/reborrow.rs b/tests/mir-opt/copy-prop/reborrow.rs new file mode 100644 index 00000000000..a1624215feb --- /dev/null +++ b/tests/mir-opt/copy-prop/reborrow.rs @@ -0,0 +1,39 @@ +// Check that CopyProp considers reborrows as not mutating the pointer. +// unit-test: CopyProp + +#![feature(raw_ref_op)] + +// EMIT_MIR reborrow.remut.CopyProp.diff +fn remut(mut x: u8) { + let a = &mut x; + let b = &mut *a; //< this cannot mutate a. + let c = a; //< so `c` and `a` can be merged. +} + +// EMIT_MIR reborrow.reraw.CopyProp.diff +fn reraw(mut x: u8) { + let a = &mut x; + let b = &raw mut *a; //< this cannot mutate a. + let c = a; //< so `c` and `a` can be merged. +} + +// EMIT_MIR reborrow.miraw.CopyProp.diff +fn miraw(mut x: u8) { + let a = &raw mut x; + let b = unsafe { &raw mut *a }; //< this cannot mutate a. + let c = a; //< so `c` and `a` can be merged. +} + +// EMIT_MIR reborrow.demiraw.CopyProp.diff +fn demiraw(mut x: u8) { + let a = &raw mut x; + let b = unsafe { &mut *a }; //< this cannot mutate a. + let c = a; //< so `c` and `a` can be merged. +} + +fn main() { + remut(0); + reraw(0); + miraw(0); + demiraw(0); +} |
