Skip to content

Commit 89a369a

Browse files
committed
Replace hard-coded field indexes with lookup on aarch64 non-macos.
The indexes into the VaListImpl struct used on aarch64 ABI (not macos/ios) are hard-coded which is brittle so we replace them with the usual lookup. The varargs ffi is tested in ui/abi/variadic-ffi.rs on aarch64 Linux.
1 parent 4a4e9e3 commit 89a369a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ fn emit_aapcs_va_arg(
9898
// Implementation of the AAPCS64 calling convention for va_args see
9999
// https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst
100100
let va_list_addr = list.immediate();
101-
let va_list_ty = list.deref(bx.cx).layout.llvm_type(bx);
101+
let va_list_layout = list.deref(bx.cx).layout;
102+
let va_list_ty = va_list_layout.llvm_type(bx);
102103
let layout = bx.cx.layout_of(target_ty);
103104

104105
let mut maybe_reg = bx.build_sibling_block("va_arg.maybe_reg");
@@ -110,13 +111,15 @@ fn emit_aapcs_va_arg(
110111

111112
let gr_type = target_ty.is_any_ptr() || target_ty.is_integral();
112113
let (reg_off, reg_top_index, slot_size) = if gr_type {
113-
let gr_offs = bx.struct_gep(va_list_ty, va_list_addr, 3);
114+
let gr_offs =
115+
bx.struct_gep(va_list_ty, va_list_addr, va_list_layout.llvm_field_index(bx.cx, 3));
114116
let nreg = (layout.size.bytes() + 7) / 8;
115-
(gr_offs, 1, nreg * 8)
117+
(gr_offs, va_list_layout.llvm_field_index(bx.cx, 1), nreg * 8)
116118
} else {
117-
let vr_off = bx.struct_gep(va_list_ty, va_list_addr, 4);
119+
let vr_off =
120+
bx.struct_gep(va_list_ty, va_list_addr, va_list_layout.llvm_field_index(bx.cx, 4));
118121
let nreg = (layout.size.bytes() + 15) / 16;
119-
(vr_off, 2, nreg * 16)
122+
(vr_off, va_list_layout.llvm_field_index(bx.cx, 2), nreg * 16)
120123
};
121124

122125
// if the offset >= 0 then the value will be on the stack

0 commit comments

Comments
 (0)