Skip to content

Commit 0027511

Browse files
committed
round pointer to alignment without going via int
1 parent 1bc901e commit 0027511

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-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>(

0 commit comments

Comments
 (0)