Skip to content

Commit f251ff4

Browse files
committed
bug fixes for issues 30018 and 30822.
includes bugfixes pointed out during review: * Only `call_lifetime_start` for an alloca if the function entry does not itself initialize it to "dropped." * Remove `schedule_lifetime_end` after writing an *element* into a borrowed slice. (As explained by [dotdash][irc], "the lifetime end that is being removed was for an element in the slice, which is not an alloca of its own and has no lifetime start of its own") [irc]: https://botbot.me/mozilla/rust-internals/2016-01-13/?msg=57844504&page=3
1 parent cec7280 commit f251ff4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/librustc_trans/trans/tvec.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,15 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
111111

112112
// Always create an alloca even if zero-sized, to preserve
113113
// the non-null invariant of the inner slice ptr
114-
let llfixed = base::alloc_ty(bcx, fixed_ty, "");
115-
call_lifetime_start(bcx, llfixed);
114+
let llfixed;
115+
// Issue 30018: ensure state is initialized as dropped if necessary.
116+
if fcx.type_needs_drop(vt.unit_ty) {
117+
llfixed = base::alloc_ty_init(bcx, fixed_ty, InitAlloca::Dropped, "");
118+
} else {
119+
let uninit = InitAlloca::Uninit("fcx says vt.unit_ty is non-drop");
120+
llfixed = base::alloc_ty_init(bcx, fixed_ty, uninit, "");
121+
call_lifetime_start(bcx, llfixed);
122+
};
116123

117124
if count > 0 {
118125
// Arrange for the backing array to be cleaned up.
@@ -212,8 +219,8 @@ fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
212219
bcx = expr::trans_into(bcx, &**element,
213220
SaveIn(lleltptr));
214221
let scope = cleanup::CustomScope(temp_scope);
215-
fcx.schedule_lifetime_end(scope, lleltptr);
216-
fcx.schedule_drop_mem(scope, lleltptr, vt.unit_ty, None);
222+
// Issue #30822: mark memory as dropped after running destructor
223+
fcx.schedule_drop_and_fill_mem(scope, lleltptr, vt.unit_ty, None);
217224
}
218225
fcx.pop_custom_cleanup_scope(temp_scope);
219226
}

0 commit comments

Comments
 (0)