Skip to content

Commit

Permalink
ConstProp: Remove const when rvalue check fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
aDotInTheVoid committed Nov 28, 2023
1 parent aef5074 commit a95ffcf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_mir_transform/src/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions tests/mir-opt/const_prop/issue_118328.size_of.ConstProp.diff
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
StorageLive(_1);
_1 = const 0_usize;
_1 = const _;
- _0 = _1;
+ _0 = const 0_usize;
_0 = _1;
StorageDead(_1);
return;
}
Expand Down

0 comments on commit a95ffcf

Please sign in to comment.