diff options
| author | Simon Vandel Sillesen <simon.vandel@gmail.com> | 2021-01-03 15:45:15 +0100 |
|---|---|---|
| committer | Erik Desjardins <erikdesjardins@users.noreply.github.com> | 2021-03-13 18:01:14 -0500 |
| commit | 35566bfd7dd2e316d190078703de54a4dadda062 (patch) | |
| tree | b8ea64bbeb39703b3bb478fe2d8309da94304097 /compiler/rustc_codegen_ssa/src | |
| parent | bb36e3c7e709cb8f4be56a874ce7b224f05b8ed4 (diff) | |
| download | rust-35566bfd7dd2e316d190078703de54a4dadda062.tar.gz rust-35566bfd7dd2e316d190078703de54a4dadda062.zip | |
Do not emit alloca for ZST local even if it is uninitialized
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/analyze.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs index 289629d9215..31d5c87182d 100644 --- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs +++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs @@ -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); |
