summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/dataflow-const-prop
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:43 +0000
commit3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245 (patch)
treedaf049b282ab10e8c3d03e409b3cd84ff3f7690c /tests/mir-opt/dataflow-const-prop
parentAdding debian version 1.68.2+dfsg1-1. (diff)
downloadrustc-3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245.tar.xz
rustc-3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245.zip
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/mir-opt/dataflow-const-prop')
-rw-r--r--tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.diff2
-rw-r--r--tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.diff82
-rw-r--r--tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.diff26
-rw-r--r--tests/mir-opt/dataflow-const-prop/enum.rs61
-rw-r--r--tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.diff (renamed from tests/mir-opt/dataflow-const-prop/enum.main.DataflowConstProp.diff)26
-rw-r--r--tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.diff34
-rw-r--r--tests/mir-opt/dataflow-const-prop/inherit_overflow.rs7
-rw-r--r--tests/mir-opt/dataflow-const-prop/repr_transparent.main.DataflowConstProp.diff8
-rw-r--r--tests/mir-opt/dataflow-const-prop/sibling_ptr.main.DataflowConstProp.diff6
-rw-r--r--tests/mir-opt/dataflow-const-prop/sibling_ptr.rs9
-rw-r--r--tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff3
-rw-r--r--tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.diff8
12 files changed, 218 insertions, 54 deletions
diff --git a/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.diff
index a4ebd0c8c..944afed8f 100644
--- a/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.diff
+++ b/tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.diff
@@ -61,7 +61,7 @@
- assert(!move (_10.1: bool), "attempt to compute `{} + {}`, which would overflow", move _9, const 1_i32) -> bb2; // scope 4 at $DIR/checked.rs:+6:13: +6:18
+ _9 = const i32::MAX; // scope 4 at $DIR/checked.rs:+6:13: +6:14
+ _10 = CheckedAdd(const i32::MAX, const 1_i32); // scope 4 at $DIR/checked.rs:+6:13: +6:18
-+ assert(!move (_10.1: bool), "attempt to compute `{} + {}`, which would overflow", const i32::MAX, const 1_i32) -> bb2; // scope 4 at $DIR/checked.rs:+6:13: +6:18
++ assert(!const true, "attempt to compute `{} + {}`, which would overflow", const i32::MAX, const 1_i32) -> bb2; // scope 4 at $DIR/checked.rs:+6:13: +6:18
}
bb2: {
diff --git a/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.diff
new file mode 100644
index 000000000..c4002d65e
--- /dev/null
+++ b/tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.diff
@@ -0,0 +1,82 @@
+- // MIR for `multiple` before DataflowConstProp
++ // MIR for `multiple` after DataflowConstProp
+
+ fn multiple(_1: bool, _2: u8) -> () {
+ debug x => _1; // in scope 0 at $DIR/enum.rs:+0:13: +0:14
+ debug i => _2; // in scope 0 at $DIR/enum.rs:+0:22: +0:23
+ let mut _0: (); // return place in scope 0 at $DIR/enum.rs:+0:29: +0:29
+ let _3: std::option::Option<u8>; // in scope 0 at $DIR/enum.rs:+1:9: +1:10
+ let mut _4: bool; // in scope 0 at $DIR/enum.rs:+1:16: +1:17
+ let mut _5: u8; // in scope 0 at $DIR/enum.rs:+2:14: +2:15
+ let mut _7: isize; // in scope 0 at $DIR/enum.rs:+9:23: +9:30
+ scope 1 {
+ debug e => _3; // in scope 1 at $DIR/enum.rs:+1:9: +1:10
+ let _6: u8; // in scope 1 at $DIR/enum.rs:+9:9: +9:10
+ let _8: u8; // in scope 1 at $DIR/enum.rs:+9:28: +9:29
+ scope 2 {
+ debug x => _6; // in scope 2 at $DIR/enum.rs:+9:9: +9:10
+ let _9: u8; // in scope 2 at $DIR/enum.rs:+11:9: +11:10
+ scope 4 {
+ debug y => _9; // in scope 4 at $DIR/enum.rs:+11:9: +11:10
+ }
+ }
+ scope 3 {
+ debug i => _8; // in scope 3 at $DIR/enum.rs:+9:28: +9:29
+ }
+ }
+
+ bb0: {
+ StorageLive(_3); // scope 0 at $DIR/enum.rs:+1:9: +1:10
+ StorageLive(_4); // scope 0 at $DIR/enum.rs:+1:16: +1:17
+ _4 = _1; // scope 0 at $DIR/enum.rs:+1:16: +1:17
+ switchInt(move _4) -> [0: bb2, otherwise: bb1]; // scope 0 at $DIR/enum.rs:+1:16: +1:17
+ }
+
+ bb1: {
+ StorageLive(_5); // scope 0 at $DIR/enum.rs:+2:14: +2:15
+ _5 = _2; // scope 0 at $DIR/enum.rs:+2:14: +2:15
+ _3 = Option::<u8>::Some(move _5); // scope 0 at $DIR/enum.rs:+2:9: +2:16
+ StorageDead(_5); // scope 0 at $DIR/enum.rs:+2:15: +2:16
+ goto -> bb3; // scope 0 at $DIR/enum.rs:+1:13: +5:6
+ }
+
+ bb2: {
+ _3 = Option::<u8>::None; // scope 0 at $DIR/enum.rs:+4:9: +4:13
+ goto -> bb3; // scope 0 at $DIR/enum.rs:+1:13: +5:6
+ }
+
+ bb3: {
+ StorageDead(_4); // scope 0 at $DIR/enum.rs:+5:5: +5:6
+ StorageLive(_6); // scope 1 at $DIR/enum.rs:+9:9: +9:10
+ _7 = discriminant(_3); // scope 1 at $DIR/enum.rs:+9:19: +9:20
+ switchInt(move _7) -> [0: bb4, 1: bb6, otherwise: bb5]; // scope 1 at $DIR/enum.rs:+9:13: +9:20
+ }
+
+ bb4: {
+ _6 = const 0_u8; // scope 1 at $DIR/enum.rs:+9:45: +9:46
+ goto -> bb7; // scope 1 at $DIR/enum.rs:+9:45: +9:46
+ }
+
+ bb5: {
+ unreachable; // scope 1 at $DIR/enum.rs:+9:19: +9:20
+ }
+
+ bb6: {
+ StorageLive(_8); // scope 1 at $DIR/enum.rs:+9:28: +9:29
+ _8 = ((_3 as Some).0: u8); // scope 1 at $DIR/enum.rs:+9:28: +9:29
+ _6 = _8; // scope 3 at $DIR/enum.rs:+9:34: +9:35
+ StorageDead(_8); // scope 1 at $DIR/enum.rs:+9:34: +9:35
+ goto -> bb7; // scope 1 at $DIR/enum.rs:+9:34: +9:35
+ }
+
+ bb7: {
+ StorageLive(_9); // scope 2 at $DIR/enum.rs:+11:9: +11:10
+ _9 = _6; // scope 2 at $DIR/enum.rs:+11:13: +11:14
+ _0 = const (); // scope 0 at $DIR/enum.rs:+0:29: +12:2
+ StorageDead(_9); // scope 2 at $DIR/enum.rs:+12:1: +12:2
+ StorageDead(_6); // scope 1 at $DIR/enum.rs:+12:1: +12:2
+ StorageDead(_3); // scope 0 at $DIR/enum.rs:+12:1: +12:2
+ return; // scope 0 at $DIR/enum.rs:+12:2: +12:2
+ }
+ }
+
diff --git a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.diff
new file mode 100644
index 000000000..038e6c6bd
--- /dev/null
+++ b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.diff
@@ -0,0 +1,26 @@
+- // MIR for `mutate_discriminant` before DataflowConstProp
++ // MIR for `mutate_discriminant` after DataflowConstProp
+
+ fn mutate_discriminant() -> u8 {
+ let mut _0: u8; // return place in scope 0 at $DIR/enum.rs:+0:29: +0:31
+ let mut _1: std::option::Option<NonZeroUsize>; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
+ let mut _2: isize; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
+
+ bb0: {
+ discriminant(_1) = 1; // scope 0 at $DIR/enum.rs:+4:13: +4:34
+ (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; // scope 0 at $DIR/enum.rs:+6:13: +6:64
+ _2 = discriminant(_1); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
+ switchInt(_2) -> [0: bb1, otherwise: bb2]; // scope 0 at $DIR/enum.rs:+9:13: +12:14
+ }
+
+ bb1: {
+ _0 = const 1_u8; // scope 0 at $DIR/enum.rs:+15:13: +15:20
+ return; // scope 0 at $DIR/enum.rs:+16:13: +16:21
+ }
+
+ bb2: {
+ _0 = const 2_u8; // scope 0 at $DIR/enum.rs:+19:13: +19:20
+ unreachable; // scope 0 at $DIR/enum.rs:+20:13: +20:26
+ }
+ }
+
diff --git a/tests/mir-opt/dataflow-const-prop/enum.rs b/tests/mir-opt/dataflow-const-prop/enum.rs
index 13288577d..79a20d7ef 100644
--- a/tests/mir-opt/dataflow-const-prop/enum.rs
+++ b/tests/mir-opt/dataflow-const-prop/enum.rs
@@ -1,13 +1,68 @@
// unit-test: DataflowConstProp
-// Not trackable, because variants could be aliased.
+#![feature(custom_mir, core_intrinsics, rustc_attrs)]
+
+use std::intrinsics::mir::*;
+
enum E {
V1(i32),
V2(i32)
}
-// EMIT_MIR enum.main.DataflowConstProp.diff
-fn main() {
+// EMIT_MIR enum.simple.DataflowConstProp.diff
+fn simple() {
let e = E::V1(0);
let x = match e { E::V1(x) => x, E::V2(x) => x };
}
+
+#[rustc_layout_scalar_valid_range_start(1)]
+#[rustc_nonnull_optimization_guaranteed]
+struct NonZeroUsize(usize);
+
+// EMIT_MIR enum.mutate_discriminant.DataflowConstProp.diff
+#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
+fn mutate_discriminant() -> u8 {
+ mir!(
+ let x: Option<NonZeroUsize>;
+ {
+ SetDiscriminant(x, 1);
+ // This assignment overwrites the niche in which the discriminant is stored.
+ place!(Field(Field(Variant(x, 1), 0), 0)) = 0_usize;
+ // So we cannot know the value of this discriminant.
+ let a = Discriminant(x);
+ match a {
+ 0 => bb1,
+ _ => bad,
+ }
+ }
+ bb1 = {
+ RET = 1;
+ Return()
+ }
+ bad = {
+ RET = 2;
+ Unreachable()
+ }
+ )
+}
+
+// EMIT_MIR enum.multiple.DataflowConstProp.diff
+fn multiple(x: bool, i: u8) {
+ let e = if x {
+ Some(i)
+ } else {
+ None
+ };
+ // The dataflow state must have:
+ // discriminant(e) => Top
+ // (e as Some).0 => Top
+ let x = match e { Some(i) => i, None => 0 };
+ // Therefore, `x` should be `Top` here, and no replacement shall happen.
+ let y = x;
+}
+
+fn main() {
+ simple();
+ mutate_discriminant();
+ multiple(false, 5);
+}
diff --git a/tests/mir-opt/dataflow-const-prop/enum.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.diff
index fce18fae4..22bdc35d6 100644
--- a/tests/mir-opt/dataflow-const-prop/enum.main.DataflowConstProp.diff
+++ b/tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.diff
@@ -1,8 +1,8 @@
-- // MIR for `main` before DataflowConstProp
-+ // MIR for `main` after DataflowConstProp
+- // MIR for `simple` before DataflowConstProp
++ // MIR for `simple` after DataflowConstProp
- fn main() -> () {
- let mut _0: (); // return place in scope 0 at $DIR/enum.rs:+0:11: +0:11
+ fn simple() -> () {
+ let mut _0: (); // return place in scope 0 at $DIR/enum.rs:+0:13: +0:13
let _1: E; // in scope 0 at $DIR/enum.rs:+1:9: +1:10
let mut _3: isize; // in scope 0 at $DIR/enum.rs:+2:23: +2:31
scope 1 {
@@ -23,12 +23,12 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/enum.rs:+1:9: +1:10
- Deinit(_1); // scope 0 at $DIR/enum.rs:+1:13: +1:21
- ((_1 as V1).0: i32) = const 0_i32; // scope 0 at $DIR/enum.rs:+1:13: +1:21
- discriminant(_1) = 0; // scope 0 at $DIR/enum.rs:+1:13: +1:21
+ _1 = E::V1(const 0_i32); // scope 0 at $DIR/enum.rs:+1:13: +1:21
StorageLive(_2); // scope 1 at $DIR/enum.rs:+2:9: +2:10
- _3 = discriminant(_1); // scope 1 at $DIR/enum.rs:+2:19: +2:20
- switchInt(move _3) -> [0: bb3, 1: bb1, otherwise: bb2]; // scope 1 at $DIR/enum.rs:+2:13: +2:20
+- _3 = discriminant(_1); // scope 1 at $DIR/enum.rs:+2:19: +2:20
+- switchInt(move _3) -> [0: bb3, 1: bb1, otherwise: bb2]; // scope 1 at $DIR/enum.rs:+2:13: +2:20
++ _3 = const 0_isize; // scope 1 at $DIR/enum.rs:+2:19: +2:20
++ switchInt(const 0_isize) -> [0: bb3, 1: bb1, otherwise: bb2]; // scope 1 at $DIR/enum.rs:+2:13: +2:20
}
bb1: {
@@ -45,14 +45,16 @@
bb3: {
StorageLive(_4); // scope 1 at $DIR/enum.rs:+2:29: +2:30
- _4 = ((_1 as V1).0: i32); // scope 1 at $DIR/enum.rs:+2:29: +2:30
- _2 = _4; // scope 3 at $DIR/enum.rs:+2:35: +2:36
+- _4 = ((_1 as V1).0: i32); // scope 1 at $DIR/enum.rs:+2:29: +2:30
+- _2 = _4; // scope 3 at $DIR/enum.rs:+2:35: +2:36
++ _4 = const 0_i32; // scope 1 at $DIR/enum.rs:+2:29: +2:30
++ _2 = const 0_i32; // scope 3 at $DIR/enum.rs:+2:35: +2:36
StorageDead(_4); // scope 1 at $DIR/enum.rs:+2:35: +2:36
goto -> bb4; // scope 1 at $DIR/enum.rs:+2:35: +2:36
}
bb4: {
- _0 = const (); // scope 0 at $DIR/enum.rs:+0:11: +3:2
+ _0 = const (); // scope 0 at $DIR/enum.rs:+0:13: +3:2
StorageDead(_2); // scope 1 at $DIR/enum.rs:+3:1: +3:2
StorageDead(_1); // scope 0 at $DIR/enum.rs:+3:1: +3:2
return; // scope 0 at $DIR/enum.rs:+3:2: +3:2
diff --git a/tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.diff
index 02aafd7ac..29781e9ce 100644
--- a/tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.diff
+++ b/tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.diff
@@ -5,34 +5,34 @@
let mut _0: (); // return place in scope 0 at $DIR/inherit_overflow.rs:+0:11: +0:11
let mut _1: u8; // in scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
let mut _2: u8; // in scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
+ let mut _3: u8; // in scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
scope 1 {
}
- scope 2 (inlined <u8 as Add>::add) { // at $DIR/inherit_overflow.rs:7:13: 7:47
- debug self => _1; // in scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
- debug other => _2; // in scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
- let mut _3: u8; // in scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
- let mut _4: u8; // in scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
- let mut _5: (u8, bool); // in scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
+ scope 2 (inlined <u8 as Add>::add) { // at $DIR/inherit_overflow.rs:8:13: 8:47
+ debug self => _2; // in scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
+ debug other => _3; // in scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
+ let mut _4: (u8, bool); // in scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
}
bb0: {
StorageLive(_1); // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
- _1 = const u8::MAX; // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
StorageLive(_2); // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
- _2 = const 1_u8; // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
- StorageLive(_3); // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
- _3 = const u8::MAX; // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
- StorageLive(_4); // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
- _4 = const 1_u8; // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
- _5 = CheckedAdd(const u8::MAX, const 1_u8); // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
- assert(!move (_5.1: bool), "attempt to compute `{} + {}`, which would overflow", const u8::MAX, const 1_u8) -> bb1; // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
+ _2 = const u8::MAX; // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
+ StorageLive(_3); // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
+ _3 = const 1_u8; // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
+- _4 = CheckedAdd(_2, _3); // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
+- assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> bb1; // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
++ _4 = CheckedAdd(const u8::MAX, const 1_u8); // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
++ assert(!const true, "attempt to compute `{} + {}`, which would overflow", const u8::MAX, const 1_u8) -> bb1; // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
}
bb1: {
- StorageDead(_4); // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
- StorageDead(_3); // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
+- _1 = move (_4.0: u8); // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
++ _1 = const 0_u8; // scope 2 at $SRC_DIR/core/src/ops/arith.rs:LL:COL
+ StorageDead(_3); // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
StorageDead(_2); // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
- StorageDead(_1); // scope 0 at $DIR/inherit_overflow.rs:+3:13: +3:47
+ StorageDead(_1); // scope 0 at $DIR/inherit_overflow.rs:+3:47: +3:48
+ _0 = const (); // scope 0 at $DIR/inherit_overflow.rs:+0:11: +4:2
return; // scope 0 at $DIR/inherit_overflow.rs:+4:2: +4:2
}
}
diff --git a/tests/mir-opt/dataflow-const-prop/inherit_overflow.rs b/tests/mir-opt/dataflow-const-prop/inherit_overflow.rs
index 2f2d9d010..f4aba60f0 100644
--- a/tests/mir-opt/dataflow-const-prop/inherit_overflow.rs
+++ b/tests/mir-opt/dataflow-const-prop/inherit_overflow.rs
@@ -1,8 +1,9 @@
-// compile-flags: -Zunsound-mir-opts
+// unit-test: DataflowConstProp
+// compile-flags: -Zmir-enable-passes=+Inline
// EMIT_MIR inherit_overflow.main.DataflowConstProp.diff
fn main() {
- // After inlining, this will contain a `CheckedBinaryOp`. The overflow
- // must be ignored by the constant propagation to avoid triggering a panic.
+ // After inlining, this will contain a `CheckedBinaryOp`.
+ // Propagating the overflow is ok as codegen will just skip emitting the panic.
let _ = <u8 as std::ops::Add>::add(255, 1);
}
diff --git a/tests/mir-opt/dataflow-const-prop/repr_transparent.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/repr_transparent.main.DataflowConstProp.diff
index f66b00a9a..8f045eedf 100644
--- a/tests/mir-opt/dataflow-const-prop/repr_transparent.main.DataflowConstProp.diff
+++ b/tests/mir-opt/dataflow-const-prop/repr_transparent.main.DataflowConstProp.diff
@@ -17,8 +17,7 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/repr_transparent.rs:+1:9: +1:10
- Deinit(_1); // scope 0 at $DIR/repr_transparent.rs:+1:13: +1:19
- (_1.0: i32) = const 0_i32; // scope 0 at $DIR/repr_transparent.rs:+1:13: +1:19
+ _1 = I32(const 0_i32); // scope 0 at $DIR/repr_transparent.rs:+1:13: +1:19
StorageLive(_2); // scope 1 at $DIR/repr_transparent.rs:+2:9: +2:10
StorageLive(_3); // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:26
StorageLive(_4); // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:20
@@ -31,9 +30,8 @@
+ _3 = const 0_i32; // scope 1 at $DIR/repr_transparent.rs:+2:17: +2:26
StorageDead(_5); // scope 1 at $DIR/repr_transparent.rs:+2:25: +2:26
StorageDead(_4); // scope 1 at $DIR/repr_transparent.rs:+2:25: +2:26
- Deinit(_2); // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
-- (_2.0: i32) = move _3; // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
-+ (_2.0: i32) = const 0_i32; // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
+- _2 = I32(move _3); // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
++ _2 = I32(const 0_i32); // scope 1 at $DIR/repr_transparent.rs:+2:13: +2:27
StorageDead(_3); // scope 1 at $DIR/repr_transparent.rs:+2:26: +2:27
_0 = const (); // scope 0 at $DIR/repr_transparent.rs:+0:11: +3:2
StorageDead(_2); // scope 1 at $DIR/repr_transparent.rs:+3:1: +3:2
diff --git a/tests/mir-opt/dataflow-const-prop/sibling_ptr.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/sibling_ptr.main.DataflowConstProp.diff
index 8126d4b85..004643e36 100644
--- a/tests/mir-opt/dataflow-const-prop/sibling_ptr.main.DataflowConstProp.diff
+++ b/tests/mir-opt/dataflow-const-prop/sibling_ptr.main.DataflowConstProp.diff
@@ -23,9 +23,7 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/sibling_ptr.rs:+1:9: +1:14
- Deinit(_1); // scope 0 at $DIR/sibling_ptr.rs:+1:27: +1:33
- (_1.0: u8) = const 0_u8; // scope 0 at $DIR/sibling_ptr.rs:+1:27: +1:33
- (_1.1: u8) = const 0_u8; // scope 0 at $DIR/sibling_ptr.rs:+1:27: +1:33
+ _1 = (const 0_u8, const 0_u8); // scope 0 at $DIR/sibling_ptr.rs:+1:27: +1:33
StorageLive(_2); // scope 1 at $DIR/sibling_ptr.rs:+2:5: +5:6
StorageLive(_3); // scope 2 at $DIR/sibling_ptr.rs:+3:13: +3:14
_3 = &raw mut (_1.0: u8); // scope 2 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
@@ -34,7 +32,7 @@
_5 = _3; // scope 3 at $DIR/sibling_ptr.rs:+4:10: +4:11
_4 = ptr::mut_ptr::<impl *mut u8>::add(move _5, const 1_usize) -> bb1; // scope 3 at $DIR/sibling_ptr.rs:+4:10: +4:18
// mir::Constant
- // + span: $DIR/sibling_ptr.rs:8:12: 8:15
+ // + span: $DIR/sibling_ptr.rs:15:12: 15:15
// + literal: Const { ty: unsafe fn(*mut u8, usize) -> *mut u8 {ptr::mut_ptr::<impl *mut u8>::add}, val: Value(<ZST>) }
}
diff --git a/tests/mir-opt/dataflow-const-prop/sibling_ptr.rs b/tests/mir-opt/dataflow-const-prop/sibling_ptr.rs
index 87ef00d18..6dfb3a4ed 100644
--- a/tests/mir-opt/dataflow-const-prop/sibling_ptr.rs
+++ b/tests/mir-opt/dataflow-const-prop/sibling_ptr.rs
@@ -1,3 +1,10 @@
+// This attempts to modify `x.1` via a pointer derived from `addr_of_mut!(x.0)`.
+// According to Miri, that is UB. However, T-opsem has not finalized that
+// decision and as such we cannot rely on it in optimizations. Consequently,
+// DataflowConstProp must treat the `addr_of_mut!(x.0)` as potentially being
+// used to modify `x.1` - if it did not, then it might incorrectly assume that it
+// can infer the value of `x.1` at the end of this function.
+
// unit-test: DataflowConstProp
// EMIT_MIR sibling_ptr.main.DataflowConstProp.diff
@@ -7,5 +14,5 @@ fn main() {
let p = std::ptr::addr_of_mut!(x.0);
*p.add(1) = 1;
}
- let x1 = x.1; // should not be propagated
+ let x1 = x.1; // should not be propagated
}
diff --git a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff
index cfb2706c1..53c62c081 100644
--- a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff
+++ b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff
@@ -21,8 +21,7 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/struct.rs:+1:9: +1:14
- Deinit(_1); // scope 0 at $DIR/struct.rs:+1:17: +1:21
- (_1.0: i32) = const 1_i32; // scope 0 at $DIR/struct.rs:+1:17: +1:21
+ _1 = S(const 1_i32); // scope 0 at $DIR/struct.rs:+1:17: +1:21
StorageLive(_2); // scope 1 at $DIR/struct.rs:+2:9: +2:10
StorageLive(_3); // scope 1 at $DIR/struct.rs:+2:13: +2:16
- _3 = (_1.0: i32); // scope 1 at $DIR/struct.rs:+2:13: +2:16
diff --git a/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.diff
index e028def00..8ce4ce4ba 100644
--- a/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.diff
+++ b/tests/mir-opt/dataflow-const-prop/tuple.main.DataflowConstProp.diff
@@ -25,9 +25,7 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/tuple.rs:+1:9: +1:14
- Deinit(_1); // scope 0 at $DIR/tuple.rs:+1:17: +1:23
- (_1.0: i32) = const 1_i32; // scope 0 at $DIR/tuple.rs:+1:17: +1:23
- (_1.1: i32) = const 2_i32; // scope 0 at $DIR/tuple.rs:+1:17: +1:23
+ _1 = (const 1_i32, const 2_i32); // scope 0 at $DIR/tuple.rs:+1:17: +1:23
StorageLive(_2); // scope 1 at $DIR/tuple.rs:+2:9: +2:10
StorageLive(_3); // scope 1 at $DIR/tuple.rs:+2:13: +2:22
StorageLive(_4); // scope 1 at $DIR/tuple.rs:+2:13: +2:16
@@ -43,9 +41,7 @@
- _2 = Add(move _3, const 3_i32); // scope 1 at $DIR/tuple.rs:+2:13: +2:26
+ _2 = const 6_i32; // scope 1 at $DIR/tuple.rs:+2:13: +2:26
StorageDead(_3); // scope 1 at $DIR/tuple.rs:+2:25: +2:26
- Deinit(_1); // scope 2 at $DIR/tuple.rs:+3:5: +3:15
- (_1.0: i32) = const 2_i32; // scope 2 at $DIR/tuple.rs:+3:5: +3:15
- (_1.1: i32) = const 3_i32; // scope 2 at $DIR/tuple.rs:+3:5: +3:15
+ _1 = (const 2_i32, const 3_i32); // scope 2 at $DIR/tuple.rs:+3:5: +3:15
StorageLive(_6); // scope 2 at $DIR/tuple.rs:+4:9: +4:10
StorageLive(_7); // scope 2 at $DIR/tuple.rs:+4:13: +4:22
StorageLive(_8); // scope 2 at $DIR/tuple.rs:+4:13: +4:16