Do not emit alloca for ZST local even if it is uninitialized

This commit is contained in:
Simon Vandel Sillesen 2021-01-03 15:45:15 +01:00 committed by Erik Desjardins
parent bb36e3c7e7
commit 35566bfd7d
3 changed files with 12 additions and 4 deletions

View file

@ -281,7 +281,18 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
Some(assignment_location) => {
assignment_location.dominates(location, &self.dominators)
}
None => false,
None => {
debug!("No first assignment found for {:?}", local);
// We have not seen any assignment to the local yet,
// but before marking not_ssa, check if it is a ZST,
// in which case we don't need to initialize the local.
let ty = self.fx.mir.local_decls[local].ty;
let ty = self.fx.monomorphize(ty);
let is_zst = self.fx.cx.layout_of(ty).is_zst();
debug!("is_zst: {}", is_zst);
is_zst
}
};
if !ssa_read {
self.not_ssa(local);