From a95ffcf5587c2ddb7fa19439817898ea68633b0b Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Tue, 28 Nov 2023 21:43:23 +0000 Subject: [PATCH] ConstProp: Remove const when rvalue check fails. --- compiler/rustc_mir_transform/src/const_prop.rs | 7 ++++++- .../mir-opt/const_prop/issue_118328.size_of.ConstProp.diff | 3 +-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index c68d8742f1c65..6e3e7df63fc2a 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -445,6 +445,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // FIXME we need to revisit this for #67176 if rvalue.has_param() { + trace!("skipping, has param"); return None; } if !rvalue @@ -724,7 +725,11 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> { fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { self.super_assign(place, rvalue, location); - let Some(()) = self.check_rvalue(rvalue) else { return }; + let Some(()) = self.check_rvalue(rvalue) else { + trace!("rvalue check failed, removing const"); + Self::remove_const(&mut self.ecx, place.local); + return; + }; match self.ecx.machine.can_const_prop[place.local] { // Do nothing if the place is indirect. diff --git a/tests/mir-opt/const_prop/issue_118328.size_of.ConstProp.diff b/tests/mir-opt/const_prop/issue_118328.size_of.ConstProp.diff index 0f44c49bc4da1..ad8318832d63b 100644 --- a/tests/mir-opt/const_prop/issue_118328.size_of.ConstProp.diff +++ b/tests/mir-opt/const_prop/issue_118328.size_of.ConstProp.diff @@ -12,8 +12,7 @@ StorageLive(_1); _1 = const 0_usize; _1 = const _; -- _0 = _1; -+ _0 = const 0_usize; + _0 = _1; StorageDead(_1); return; }