Auto merge of #146059 - folkertdev:va-end-lifetime, r=saethlin
explicitly end the lifetime of `va_list` tracking issue: https://github.com/rust-lang/rust/issues/44930 split out from: https://github.com/rust-lang/rust/pull/144549 The `va_list` is created in the compiler itself when the variable argument list `...` is desugared, and hence the lifetime end is not inserted automatically. The value can't outlive the function in which it was created, so it is correct to end the lifetime here. Ending the lifetime explicitly also appears to give slightly better codegen in https://github.com/rust-lang/rust/pull/144549. I also included a little drive-by improvement to not cast pointers to integers and back again. r? codegen
This commit is contained in:
commit
05abce5d05
2 changed files with 9 additions and 3 deletions
|
|
@ -28,9 +28,12 @@ fn round_pointer_up_to_alignment<'ll>(
|
||||||
align: Align,
|
align: Align,
|
||||||
ptr_ty: &'ll Type,
|
ptr_ty: &'ll Type,
|
||||||
) -> &'ll Value {
|
) -> &'ll Value {
|
||||||
let mut ptr_as_int = bx.ptrtoint(addr, bx.cx().type_isize());
|
let ptr = bx.inbounds_ptradd(addr, bx.const_i32(align.bytes() as i32 - 1));
|
||||||
ptr_as_int = round_up_to_alignment(bx, ptr_as_int, align);
|
bx.call_intrinsic(
|
||||||
bx.inttoptr(ptr_as_int, ptr_ty)
|
"llvm.ptrmask",
|
||||||
|
&[ptr_ty, bx.type_i32()],
|
||||||
|
&[ptr, bx.const_int(bx.isize_ty, -(align.bytes() as isize) as i64)],
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_direct_ptr_va_arg<'ll, 'tcx>(
|
fn emit_direct_ptr_va_arg<'ll, 'tcx>(
|
||||||
|
|
|
||||||
|
|
@ -519,6 +519,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
match self.locals[mir::Local::from_usize(1 + va_list_arg_idx)] {
|
match self.locals[mir::Local::from_usize(1 + va_list_arg_idx)] {
|
||||||
LocalRef::Place(va_list) => {
|
LocalRef::Place(va_list) => {
|
||||||
bx.va_end(va_list.val.llval);
|
bx.va_end(va_list.val.llval);
|
||||||
|
|
||||||
|
// Explicitly end the lifetime of the `va_list`, this matters for LLVM.
|
||||||
|
bx.lifetime_end(va_list.val.llval, va_list.layout.size);
|
||||||
}
|
}
|
||||||
_ => bug!("C-variadic function must have a `VaList` place"),
|
_ => bug!("C-variadic function must have a `VaList` place"),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue