Skip to content

Commit 9121a41

Browse files
committed
ConstProp: Remove const when rvalue check fails.
1 parent b1a6cf4 commit 9121a41

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Diff for: compiler/rustc_mir_transform/src/const_prop.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
439439

440440
// FIXME we need to revisit this for #67176
441441
if rvalue.has_param() {
442+
trace!("skipping, has param");
442443
return None;
443444
}
444445
if !rvalue
@@ -707,7 +708,11 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
707708
fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
708709
self.super_assign(place, rvalue, location);
709710

710-
let Some(()) = self.check_rvalue(rvalue) else { return };
711+
let Some(()) = self.check_rvalue(rvalue) else {
712+
trace!("rvalue check failed, removing const");
713+
Self::remove_const(&mut self.ecx, place.local);
714+
return;
715+
};
711716

712717
match self.ecx.machine.can_const_prop[place.local] {
713718
// Do nothing if the place is indirect.

Diff for: tests/mir-opt/const_prop/issue_118328.size_of.ConstProp.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
StorageLive(_1);
1313
_1 = const 0_usize;
1414
_1 = const _;
15-
- _0 = _1;
16-
+ _0 = const 0_usize;
15+
_0 = _1;
1716
StorageDead(_1);
1817
return;
1918
}

0 commit comments

Comments
 (0)