Skip to content

Commit 780d162

Browse files
committed
Treat double StorageLive as deinit
1 parent f1ae5ee commit 780d162

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler/rustc_mir_transform/src/ssa.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_, 'tcx> {
245245
self.check_dominates(local, loc);
246246
self.direct_uses[local] += 1;
247247
}
248+
PlaceContext::NonUse(NonUseContext::StorageLive) => {
249+
// If the local is already assigned, than marking it _again_ as storage live
250+
// deinitializes it, so need to treat if as a mutating use.
251+
if let Set1::One(_) = self.assignments[local] {
252+
self.assignments[local] = Set1::Many;
253+
}
254+
}
248255
PlaceContext::NonUse(_) => {}
249256
}
250257
}

tests/mir-opt/gvn_storage_twice.repeat_local_dead_live.GVN.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
StorageDead(_3);
1313
StorageLive(_3);
1414
- _0 = copy (*_5);
15-
+ _0 = copy _3;
15+
+ _0 = copy _4[_1];
1616
return;
1717
}
1818
}

0 commit comments

Comments
 (0)