Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 05abce5

Browse files
committed
Auto merge of #146059 - folkertdev:va-end-lifetime, r=saethlin
explicitly end the lifetime of `va_list` tracking issue: #44930 split out from: #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 #144549. I also included a little drive-by improvement to not cast pointers to integers and back again. r? codegen
2 parents 75ee9ff + 213bb87 commit 05abce5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

‎compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ fn round_pointer_up_to_alignment<'ll>(
2828
align: Align,
2929
ptr_ty: &'ll Type,
3030
) -> &'ll Value {
31-
let mut ptr_as_int = bx.ptrtoint(addr, bx.cx().type_isize());
32-
ptr_as_int = round_up_to_alignment(bx, ptr_as_int, align);
33-
bx.inttoptr(ptr_as_int, ptr_ty)
31+
let ptr = bx.inbounds_ptradd(addr, bx.const_i32(align.bytes() as i32 - 1));
32+
bx.call_intrinsic(
33+
"llvm.ptrmask",
34+
&[ptr_ty, bx.type_i32()],
35+
&[ptr, bx.const_int(bx.isize_ty, -(align.bytes() as isize) as i64)],
36+
)
3437
}
3538

3639
fn emit_direct_ptr_va_arg<'ll, 'tcx>(

‎compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
519519
match self.locals[mir::Local::from_usize(1 + va_list_arg_idx)] {
520520
LocalRef::Place(va_list) => {
521521
bx.va_end(va_list.val.llval);
522+
523+
// Explicitly end the lifetime of the `va_list`, this matters for LLVM.
524+
bx.lifetime_end(va_list.val.llval, va_list.layout.size);
522525
}
523526
_ => bug!("C-variadic function must have a `VaList` place"),
524527
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /