Skip to content

Commit 7706e23

Browse files
committed
revise lifetime handling for alloca's that are initialized as "dropped."
(This can/should be revisited when drop flags are stored out of band.)
1 parent 8168765 commit 7706e23

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/librustc_trans/trans/base.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,13 @@ pub fn alloca_dropped<'blk, 'tcx>(cx: Block<'blk, 'tcx>, ty: Ty<'tcx>, name: &st
13541354
let p = alloca(cx, llty, name);
13551355
let b = cx.fcx.ccx.builder();
13561356
b.position_before(cx.fcx.alloca_insert_pt.get().unwrap());
1357+
1358+
// This is just like `call_lifetime_start` (but latter expects a
1359+
// Block, which we do not have for `alloca_insert_pt`).
1360+
core_lifetime_emit(cx.ccx(), p, Lifetime::Start, |ccx, size, lifetime_start| {
1361+
let ptr = b.pointercast(p, Type::i8p(ccx));
1362+
b.call(lifetime_start, &[C_u64(ccx, size), ptr], None);
1363+
});
13571364
memfill(&b, p, ty, adt::DTOR_DONE);
13581365
p
13591366
}

src/librustc_trans/trans/datum.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,9 @@ impl<'tcx> Datum<'tcx, Rvalue> {
513513
|this, bcx, llval| {
514514
debug!("populate call for Datum::to_lvalue_datum_in_scope \
515515
self.ty={:?}", this.ty);
516-
call_lifetime_start(bcx, llval);
516+
// do not call_lifetime_start here; the
517+
// `InitAlloc::Dropped` will start scratch
518+
// value's lifetime at open of function body.
517519
let bcx = this.store_to(bcx, llval);
518520
bcx.fcx.schedule_lifetime_end(scope, llval);
519521
bcx

0 commit comments

Comments
 (0)