Skip to content

Commit 06126eb

Browse files
committed
Add missing calls to llvm.lifetime.end intrinsics
These missing calls lead to miscompilations with more recent LLVM versions.
1 parent e0f5980 commit 06126eb

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/librustc_trans/trans/base.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,9 @@ pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
20072007
let bcx = match dest {
20082008
expr::SaveIn(_) => bcx,
20092009
expr::Ignore => {
2010-
glue::drop_ty(bcx, llresult, result_ty, debug_loc)
2010+
let bcx = glue::drop_ty(bcx, llresult, result_ty, debug_loc);
2011+
call_lifetime_end(bcx, llresult);
2012+
bcx
20112013
}
20122014
};
20132015

src/librustc_trans/trans/datum.rs

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ impl KindOps for Rvalue {
199199
-> Block<'blk, 'tcx> {
200200
// No cleanup is scheduled for an rvalue, so we don't have
201201
// to do anything after a move to cancel or duplicate it.
202+
if self.is_by_ref() {
203+
call_lifetime_end(bcx, _val);
204+
}
202205
bcx
203206
}
204207

@@ -320,6 +323,7 @@ impl<'tcx> Datum<'tcx, Rvalue> {
320323
ByValue => DatumBlock::new(bcx, self),
321324
ByRef => {
322325
let llval = load_ty(bcx, self.val, self.ty);
326+
call_lifetime_end(bcx, self.val);
323327
DatumBlock::new(bcx, Datum::new(llval, self.ty, Rvalue::new(ByValue)))
324328
}
325329
}

src/librustc_trans/trans/intrinsic.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
243243
dest
244244
};
245245

246-
fcx.pop_custom_cleanup_scope(cleanup_scope);
246+
fcx.scopes.borrow_mut().last_mut().unwrap().drop_non_lifetime_clean();
247+
fcx.pop_and_trans_custom_cleanup_scope(bcx, cleanup_scope);
247248

248249
return match dest {
249250
expr::SaveIn(d) => Result::new(bcx, d),
@@ -268,17 +269,19 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
268269
false,
269270
RustIntrinsic);
270271

271-
fcx.pop_custom_cleanup_scope(cleanup_scope);
272+
fcx.scopes.borrow_mut().last_mut().unwrap().drop_non_lifetime_clean();
272273

273274
let call_debug_location = DebugLoc::At(call_info.id, call_info.span);
274275

275276
// These are the only intrinsic functions that diverge.
276277
if name.get() == "abort" {
277278
let llfn = ccx.get_intrinsic(&("llvm.trap"));
278279
Call(bcx, llfn, &[], None, call_debug_location);
280+
fcx.pop_and_trans_custom_cleanup_scope(bcx, cleanup_scope);
279281
Unreachable(bcx);
280282
return Result::new(bcx, C_undef(Type::nil(ccx).ptr_to()));
281283
} else if name.get() == "unreachable" {
284+
fcx.pop_and_trans_custom_cleanup_scope(bcx, cleanup_scope);
282285
Unreachable(bcx);
283286
return Result::new(bcx, C_nil(ccx));
284287
}
@@ -765,6 +768,8 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
765768
expr::SaveIn(_) => {}
766769
}
767770

771+
fcx.pop_and_trans_custom_cleanup_scope(bcx, cleanup_scope);
772+
768773
Result::new(bcx, llresult)
769774
}
770775

0 commit comments

Comments
 (0)