summaryrefslogtreecommitdiffstats
path: root/src/test/mir-opt/dead-store-elimination
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/mir-opt/dead-store-elimination
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/mir-opt/dead-store-elimination')
-rw-r--r--src/test/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.diff75
-rw-r--r--src/test/mir-opt/dead-store-elimination/cycle.rs22
-rw-r--r--src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff35
-rw-r--r--src/test/mir-opt/dead-store-elimination/provenance_soundness.retags.DeadStoreElimination.diff14
-rw-r--r--src/test/mir-opt/dead-store-elimination/provenance_soundness.rs18
5 files changed, 164 insertions, 0 deletions
diff --git a/src/test/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.diff b/src/test/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.diff
new file mode 100644
index 000000000..58dd788b6
--- /dev/null
+++ b/src/test/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.diff
@@ -0,0 +1,75 @@
+- // MIR for `cycle` before DeadStoreElimination
++ // MIR for `cycle` after DeadStoreElimination
+
+ fn cycle(_1: i32, _2: i32, _3: i32) -> () {
+ debug x => _1; // in scope 0 at $DIR/cycle.rs:+0:10: +0:15
+ debug y => _2; // in scope 0 at $DIR/cycle.rs:+0:22: +0:27
+ debug z => _3; // in scope 0 at $DIR/cycle.rs:+0:34: +0:39
+ let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:+0:46: +0:46
+ let mut _4: (); // in scope 0 at $DIR/cycle.rs:+0:1: +9:2
+ let mut _5: bool; // in scope 0 at $DIR/cycle.rs:+3:11: +3:17
+ let _6: i32; // in scope 0 at $DIR/cycle.rs:+4:13: +4:17
+ let mut _7: i32; // in scope 0 at $DIR/cycle.rs:+5:13: +5:14
+ let mut _8: i32; // in scope 0 at $DIR/cycle.rs:+6:13: +6:14
+ let mut _9: i32; // in scope 0 at $DIR/cycle.rs:+7:13: +7:17
+ let mut _10: !; // in scope 0 at $DIR/cycle.rs:+3:5: +8:6
+ let _11: (); // in scope 0 at $DIR/cycle.rs:+3:5: +8:6
+ let mut _12: !; // in scope 0 at $DIR/cycle.rs:+3:5: +8:6
+ scope 1 {
+ debug temp => _6; // in scope 1 at $DIR/cycle.rs:+4:13: +4:17
+ }
+
+ bb0: {
+ goto -> bb1; // scope 0 at $DIR/cycle.rs:+3:5: +8:6
+ }
+
+ bb1: {
+ StorageLive(_5); // scope 0 at $DIR/cycle.rs:+3:11: +3:17
+ _5 = cond() -> bb2; // scope 0 at $DIR/cycle.rs:+3:11: +3:17
+ // mir::Constant
+ // + span: $DIR/cycle.rs:12:11: 12:15
+ // + literal: Const { ty: fn() -> bool {cond}, val: Value(<ZST>) }
+ }
+
+ bb2: {
+ switchInt(move _5) -> [false: bb4, otherwise: bb3]; // scope 0 at $DIR/cycle.rs:+3:11: +3:17
+ }
+
+ bb3: {
+ StorageLive(_6); // scope 0 at $DIR/cycle.rs:+4:13: +4:17
+- _6 = _3; // scope 0 at $DIR/cycle.rs:+4:20: +4:21
++ nop; // scope 0 at $DIR/cycle.rs:+4:20: +4:21
+ StorageLive(_7); // scope 1 at $DIR/cycle.rs:+5:13: +5:14
+- _7 = _2; // scope 1 at $DIR/cycle.rs:+5:13: +5:14
+- _3 = move _7; // scope 1 at $DIR/cycle.rs:+5:9: +5:14
++ nop; // scope 1 at $DIR/cycle.rs:+5:13: +5:14
++ nop; // scope 1 at $DIR/cycle.rs:+5:9: +5:14
+ StorageDead(_7); // scope 1 at $DIR/cycle.rs:+5:13: +5:14
+ StorageLive(_8); // scope 1 at $DIR/cycle.rs:+6:13: +6:14
+- _8 = _1; // scope 1 at $DIR/cycle.rs:+6:13: +6:14
+- _2 = move _8; // scope 1 at $DIR/cycle.rs:+6:9: +6:14
++ nop; // scope 1 at $DIR/cycle.rs:+6:13: +6:14
++ nop; // scope 1 at $DIR/cycle.rs:+6:9: +6:14
+ StorageDead(_8); // scope 1 at $DIR/cycle.rs:+6:13: +6:14
+ StorageLive(_9); // scope 1 at $DIR/cycle.rs:+7:13: +7:17
+- _9 = _6; // scope 1 at $DIR/cycle.rs:+7:13: +7:17
+- _1 = move _9; // scope 1 at $DIR/cycle.rs:+7:9: +7:17
++ nop; // scope 1 at $DIR/cycle.rs:+7:13: +7:17
++ nop; // scope 1 at $DIR/cycle.rs:+7:9: +7:17
+ StorageDead(_9); // scope 1 at $DIR/cycle.rs:+7:16: +7:17
+- _4 = const (); // scope 0 at $DIR/cycle.rs:+3:18: +8:6
++ nop; // scope 0 at $DIR/cycle.rs:+3:18: +8:6
+ StorageDead(_6); // scope 0 at $DIR/cycle.rs:+8:5: +8:6
+ StorageDead(_5); // scope 0 at $DIR/cycle.rs:+8:5: +8:6
+ goto -> bb1; // scope 0 at $DIR/cycle.rs:+3:5: +8:6
+ }
+
+ bb4: {
+ StorageLive(_11); // scope 0 at $DIR/cycle.rs:+3:5: +8:6
+ _0 = const (); // scope 0 at $DIR/cycle.rs:+3:5: +8:6
+ StorageDead(_11); // scope 0 at $DIR/cycle.rs:+8:5: +8:6
+ StorageDead(_5); // scope 0 at $DIR/cycle.rs:+8:5: +8:6
+ return; // scope 0 at $DIR/cycle.rs:+9:2: +9:2
+ }
+ }
+
diff --git a/src/test/mir-opt/dead-store-elimination/cycle.rs b/src/test/mir-opt/dead-store-elimination/cycle.rs
new file mode 100644
index 000000000..b35ce0bcb
--- /dev/null
+++ b/src/test/mir-opt/dead-store-elimination/cycle.rs
@@ -0,0 +1,22 @@
+// unit-test: DeadStoreElimination
+
+#[inline(never)]
+fn cond() -> bool {
+ false
+}
+
+// EMIT_MIR cycle.cycle.DeadStoreElimination.diff
+fn cycle(mut x: i32, mut y: i32, mut z: i32) {
+ // This example is interesting because the non-transitive version of `MaybeLiveLocals` would
+ // report that *all* of these stores are live.
+ while cond() {
+ let temp = z;
+ z = y;
+ y = x;
+ x = temp;
+ }
+}
+
+fn main() {
+ cycle(1, 2, 3);
+}
diff --git a/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff b/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff
new file mode 100644
index 000000000..89f1846b4
--- /dev/null
+++ b/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff
@@ -0,0 +1,35 @@
+- // MIR for `pointer_to_int` before DeadStoreElimination
++ // MIR for `pointer_to_int` after DeadStoreElimination
+
+ fn pointer_to_int(_1: *mut i32) -> () {
+ debug p => _1; // in scope 0 at $DIR/provenance_soundness.rs:+0:19: +0:20
+ let mut _0: (); // return place in scope 0 at $DIR/provenance_soundness.rs:+0:32: +0:32
+ let _2: usize; // in scope 0 at $DIR/provenance_soundness.rs:+1:9: +1:11
+ let mut _3: *mut i32; // in scope 0 at $DIR/provenance_soundness.rs:+1:14: +1:15
+ let mut _5: *mut i32; // in scope 0 at $DIR/provenance_soundness.rs:+2:14: +2:15
+ scope 1 {
+ debug _x => _2; // in scope 1 at $DIR/provenance_soundness.rs:+1:9: +1:11
+ let _4: isize; // in scope 1 at $DIR/provenance_soundness.rs:+2:9: +2:11
+ scope 2 {
+ debug _y => _4; // in scope 2 at $DIR/provenance_soundness.rs:+2:9: +2:11
+ }
+ }
+
+ bb0: {
+ StorageLive(_2); // scope 0 at $DIR/provenance_soundness.rs:+1:9: +1:11
+ StorageLive(_3); // scope 0 at $DIR/provenance_soundness.rs:+1:14: +1:15
+ _3 = _1; // scope 0 at $DIR/provenance_soundness.rs:+1:14: +1:15
+ _2 = move _3 as usize (PointerExposeAddress); // scope 0 at $DIR/provenance_soundness.rs:+1:14: +1:24
+ StorageDead(_3); // scope 0 at $DIR/provenance_soundness.rs:+1:23: +1:24
+ StorageLive(_4); // scope 1 at $DIR/provenance_soundness.rs:+2:9: +2:11
+ StorageLive(_5); // scope 1 at $DIR/provenance_soundness.rs:+2:14: +2:15
+ _5 = _1; // scope 1 at $DIR/provenance_soundness.rs:+2:14: +2:15
+ _4 = move _5 as isize (PointerExposeAddress); // scope 1 at $DIR/provenance_soundness.rs:+2:14: +2:24
+ StorageDead(_5); // scope 1 at $DIR/provenance_soundness.rs:+2:23: +2:24
+ _0 = const (); // scope 0 at $DIR/provenance_soundness.rs:+0:32: +3:2
+ StorageDead(_4); // scope 1 at $DIR/provenance_soundness.rs:+3:1: +3:2
+ StorageDead(_2); // scope 0 at $DIR/provenance_soundness.rs:+3:1: +3:2
+ return; // scope 0 at $DIR/provenance_soundness.rs:+3:2: +3:2
+ }
+ }
+
diff --git a/src/test/mir-opt/dead-store-elimination/provenance_soundness.retags.DeadStoreElimination.diff b/src/test/mir-opt/dead-store-elimination/provenance_soundness.retags.DeadStoreElimination.diff
new file mode 100644
index 000000000..300f0d5dc
--- /dev/null
+++ b/src/test/mir-opt/dead-store-elimination/provenance_soundness.retags.DeadStoreElimination.diff
@@ -0,0 +1,14 @@
+- // MIR for `retags` before DeadStoreElimination
++ // MIR for `retags` after DeadStoreElimination
+
+ fn retags(_1: &mut i32) -> () {
+ debug _r => _1; // in scope 0 at $DIR/provenance_soundness.rs:+0:11: +0:13
+ let mut _0: (); // return place in scope 0 at $DIR/provenance_soundness.rs:+0:25: +0:25
+
+ bb0: {
+ Retag([fn entry] _1); // scope 0 at $DIR/provenance_soundness.rs:+0:1: +0:27
+ _0 = const (); // scope 0 at $DIR/provenance_soundness.rs:+0:25: +0:27
+ return; // scope 0 at $DIR/provenance_soundness.rs:+0:27: +0:27
+ }
+ }
+
diff --git a/src/test/mir-opt/dead-store-elimination/provenance_soundness.rs b/src/test/mir-opt/dead-store-elimination/provenance_soundness.rs
new file mode 100644
index 000000000..11314e990
--- /dev/null
+++ b/src/test/mir-opt/dead-store-elimination/provenance_soundness.rs
@@ -0,0 +1,18 @@
+// unit-test: DeadStoreElimination
+// compile-flags: -Zmir-emit-retag
+
+// Test that we don't remove pointer to int casts or retags
+
+// EMIT_MIR provenance_soundness.pointer_to_int.DeadStoreElimination.diff
+fn pointer_to_int(p: *mut i32) {
+ let _x = p as usize;
+ let _y = p as isize;
+}
+
+// EMIT_MIR provenance_soundness.retags.DeadStoreElimination.diff
+fn retags(_r: &mut i32) {}
+
+fn main() {
+ pointer_to_int(&mut 5 as *mut _);
+ retags(&mut 5);
+}