Do not emit alloca for ZST local even if it is uninitialized
This commit is contained in:
parent
bb36e3c7e7
commit
35566bfd7d
3 changed files with 12 additions and 4 deletions
|
@ -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);
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#[naked]
|
||||
pub fn naked_empty() {
|
||||
// CHECK-NEXT: {{.+}}:
|
||||
// CHECK-NEXT: %0 = alloca {}, align 1
|
||||
// CHECK-NEXT: ret void
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue