summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/copy-prop/reborrow.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
commit631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch)
treea1b87c8f8cad01cf18f7c5f57a08f102771ed303 /tests/mir-opt/copy-prop/reborrow.rs
parentAdding debian version 1.69.0+dfsg1-1. (diff)
downloadrustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz
rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/mir-opt/copy-prop/reborrow.rs')
-rw-r--r--tests/mir-opt/copy-prop/reborrow.rs47
1 files changed, 47 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 000000000..91b77966b
--- /dev/null
+++ b/tests/mir-opt/copy-prop/reborrow.rs
@@ -0,0 +1,47 @@
+// ignore-wasm32 compiled with panic=abort by default
+// Check that CopyProp considers reborrows as not mutating the pointer.
+// unit-test: CopyProp
+
+#![feature(raw_ref_op)]
+
+#[inline(never)]
+fn opaque(_: impl Sized) {}
+
+// 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.
+ opaque(c);
+}
+
+// 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.
+ opaque(c);
+}
+
+// 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.
+ opaque(c);
+}
+
+// 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.
+ opaque(c);
+}
+
+fn main() {
+ remut(0);
+ reraw(0);
+ miraw(0);
+ demiraw(0);
+}