From b851e554ddf64d4889d305ee4d8972028bc86b90 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 7 Sep 2023 17:13:58 +0000 Subject: [PATCH] Support CopyForDeref. --- .../rustc_mir_transform/src/dataflow_const_prop.rs | 6 ++++++ .../struct.main.DataflowConstProp.diff | 12 ++++++++---- 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 5ec9d13f7d20..fc8eccb27051 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 89e37cc04dc2..71a28f2165b2 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);