Skip to content

Commit

Permalink
Do not emit alloca for ZST local even if it is uninitialized
Browse files Browse the repository at this point in the history
  • Loading branch information
simonvandel authored and erikdesjardins committed Mar 13, 2021
1 parent bb36e3c commit 35566bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
13 changes: 12 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/test/codegen/naked-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#[naked]
pub fn naked_empty() {
// CHECK-NEXT: {{.+}}:
// CHECK-NEXT: %0 = alloca {}, align 1
// CHECK-NEXT: ret void
}

Expand All @@ -19,7 +18,6 @@ pub fn naked_empty() {
// CHECK-NEXT: define void @naked_with_args(i{{[0-9]+( %a)?}})
pub fn naked_with_args(a: isize) {
// CHECK-NEXT: {{.+}}:
// CHECK-NEXT: %0 = alloca {}, align 1
// CHECK: ret void
}

Expand Down
1 change: 0 additions & 1 deletion src/test/run-make/const_fn_mir/dump.mir
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn main() -> () {
}

bb1: {
_0 = const (); // scope 0 at main.rs:8:11: 10:2
return; // scope 0 at main.rs:10:2: 10:2
}
}
Expand Down

0 comments on commit 35566bf

Please sign in to comment.