1
Fork 0

Rollup merge of #97597 - tmiasko:simplify-locals-side-effects, r=RalfJung,JakobDegen

Preserve unused pointer to address casts

Fixes #97421.

cc `@RalfJung`
This commit is contained in:
Dylan DPC 2022-06-08 07:37:30 +02:00 committed by GitHub
commit d380b457d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 11 deletions

View file

@ -34,7 +34,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
for (statement_index, statement) in bb_data.statements.iter().enumerate().rev() {
let loc = Location { block: bb, statement_index };
if let StatementKind::Assign(assign) = &statement.kind {
if assign.1.is_pointer_int_cast() {
if !assign.1.is_safe_to_remove() {
continue;
}
}

View file

@ -494,8 +494,12 @@ impl<'tcx> Visitor<'tcx> for UsedLocals {
StatementKind::StorageLive(_local) | StatementKind::StorageDead(_local) => {}
StatementKind::Assign(box (ref place, ref rvalue)) => {
self.visit_lhs(place, location);
self.visit_rvalue(rvalue, location);
if rvalue.is_safe_to_remove() {
self.visit_lhs(place, location);
self.visit_rvalue(rvalue, location);
} else {
self.super_statement(statement, location);
}
}
StatementKind::SetDiscriminant { ref place, variant_index: _ }