From 7706e2333eacbbdf943164cec583a51b216bbde1 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 12 Jan 2016 17:21:11 +0100 Subject: [PATCH] revise lifetime handling for alloca's that are initialized as "dropped." (This can/should be revisited when drop flags are stored out of band.) --- src/librustc_trans/trans/base.rs | 7 +++++++ src/librustc_trans/trans/datum.rs | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 636db8fecdf..375b3e3f0d2 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -1354,6 +1354,13 @@ pub fn alloca_dropped<'blk, 'tcx>(cx: Block<'blk, 'tcx>, ty: Ty<'tcx>, name: &st let p = alloca(cx, llty, name); let b = cx.fcx.ccx.builder(); b.position_before(cx.fcx.alloca_insert_pt.get().unwrap()); + + // This is just like `call_lifetime_start` (but latter expects a + // Block, which we do not have for `alloca_insert_pt`). + core_lifetime_emit(cx.ccx(), p, Lifetime::Start, |ccx, size, lifetime_start| { + let ptr = b.pointercast(p, Type::i8p(ccx)); + b.call(lifetime_start, &[C_u64(ccx, size), ptr], None); + }); memfill(&b, p, ty, adt::DTOR_DONE); p } diff --git a/src/librustc_trans/trans/datum.rs b/src/librustc_trans/trans/datum.rs index 6a033602ada..32f263746d3 100644 --- a/src/librustc_trans/trans/datum.rs +++ b/src/librustc_trans/trans/datum.rs @@ -513,7 +513,9 @@ impl<'tcx> Datum<'tcx, Rvalue> { |this, bcx, llval| { debug!("populate call for Datum::to_lvalue_datum_in_scope \ self.ty={:?}", this.ty); - call_lifetime_start(bcx, llval); + // do not call_lifetime_start here; the + // `InitAlloc::Dropped` will start scratch + // value's lifetime at open of function body. let bcx = this.store_to(bcx, llval); bcx.fcx.schedule_lifetime_end(scope, llval); bcx