about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2023-09-07 17:13:58 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2023-09-11 16:29:41 +0000
commitb851e554ddf64d4889d305ee4d8972028bc86b90 (patch)
tree70633fcb6d6610beff833f6d24520732bf740da8
parent82f0468009da17c14a3ab69d01526db848cf8b55 (diff)
downloadrust-b851e554ddf64d4889d305ee4d8972028bc86b90.tar.gz
rust-b851e554ddf64d4889d305ee4d8972028bc86b90.zip
Support CopyForDeref.
-rw-r--r--compiler/rustc_mir_transform/src/dataflow_const_prop.rs6
-rw-r--r--tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff12
2 files changed, 14 insertions, 4 deletions
diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs
index 5ec9d13f7d2..fc8eccb2705 100644
--- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs
+++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs
@@ -119,6 +119,12 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
                     self.assign_operand(state, target, operand);
                 }
             }
+            Rvalue::CopyForDeref(rhs) => {
+                state.flood(target.as_ref(), self.map());
+                if let Some(target) = self.map.find(target.as_ref()) {
+                    self.assign_operand(state, target, &Operand::Copy(*rhs));
+                }
+            }
             Rvalue::Aggregate(kind, operands) => {
                 // If we assign `target = Enum::Variant#0(operand)`,
                 // we must make sure that all `target as Variant#i` are `Top`.
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 89e37cc04dc..71a28f2165b 100644
--- a/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff
+++ b/tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff
@@ -88,16 +88,20 @@
           _17 = deref_copy (*_16);
           StorageLive(_12);
           _18 = deref_copy (*_16);
-          _12 = ((*_18).0: S);
+-         _12 = ((*_18).0: S);
++         _12 = const S(1_i32);
           StorageLive(_13);
           _19 = deref_copy (*_16);
-          _13 = ((*_19).1: u8);
+-         _13 = ((*_19).1: u8);
++         _13 = const 5_u8;
           StorageLive(_14);
           _20 = deref_copy (*_16);
-          _14 = ((*_20).2: f32);
+-         _14 = ((*_20).2: f32);
++         _14 = const 7f32;
           StorageLive(_15);
           _21 = deref_copy (*_16);
-          _15 = ((*_21).3: S);
+-         _15 = ((*_21).3: S);
++         _15 = const S(13_i32);
           StorageDead(_16);
           _0 = const ();
           StorageDead(_15);