Skip to content

Commit 9f227ca

Browse files
committed
Auto merge of #27960 - dotdash:zerosize_lifetime, r=alexcrichton
These aren't super common, but happen for e.g. closures that have an empty environment, and for for-loops that return ().
2 parents c69c29b + 64fcf3b commit 9f227ca

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/librustc_trans/trans/base.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,14 @@ pub fn call_lifetime_start(cx: Block, ptr: ValueRef) {
917917
let _icx = push_ctxt("lifetime_start");
918918
let ccx = cx.ccx();
919919

920-
let llsize = C_u64(ccx, machine::llsize_of_alloc(ccx, val_ty(ptr).element_type()));
920+
let size = machine::llsize_of_alloc(ccx, val_ty(ptr).element_type());
921+
if size == 0 {
922+
return;
923+
}
924+
921925
let ptr = PointerCast(cx, ptr, Type::i8p(ccx));
922926
let lifetime_start = ccx.get_intrinsic(&"llvm.lifetime.start");
923-
Call(cx, lifetime_start, &[llsize, ptr], None, DebugLoc::None);
927+
Call(cx, lifetime_start, &[C_u64(ccx, size), ptr], None, DebugLoc::None);
924928
}
925929

926930
pub fn call_lifetime_end(cx: Block, ptr: ValueRef) {
@@ -931,10 +935,14 @@ pub fn call_lifetime_end(cx: Block, ptr: ValueRef) {
931935
let _icx = push_ctxt("lifetime_end");
932936
let ccx = cx.ccx();
933937

934-
let llsize = C_u64(ccx, machine::llsize_of_alloc(ccx, val_ty(ptr).element_type()));
938+
let size = machine::llsize_of_alloc(ccx, val_ty(ptr).element_type());
939+
if size == 0 {
940+
return;
941+
}
942+
935943
let ptr = PointerCast(cx, ptr, Type::i8p(ccx));
936944
let lifetime_end = ccx.get_intrinsic(&"llvm.lifetime.end");
937-
Call(cx, lifetime_end, &[llsize, ptr], None, DebugLoc::None);
945+
Call(cx, lifetime_end, &[C_u64(ccx, size), ptr], None, DebugLoc::None);
938946
}
939947

940948
pub fn call_memcpy(cx: Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, align: u32) {

0 commit comments

Comments
 (0)