Skip to content

Commit 147a001

Browse files
authored
Rollup merge of rust-lang#78126 - shepmaster:aarch64-apple-darwin-valist, r=nagisa
Properly define va_arg and va_list for aarch64-apple-darwin From [Apple][]: > Because of these changes, the type `va_list` is an alias for `char*`, > and not for the struct type in the generic procedure call standard. With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi` passes. Fixes rust-lang#78092 [Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2 parents 9885232 + 0a91755 commit 147a001

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,26 +173,24 @@ pub(super) fn emit_va_arg(
173173
// is lacking in some instances, so we should only use it as a fallback.
174174
let target = &bx.cx.tcx.sess.target;
175175
let arch = &bx.cx.tcx.sess.target.arch;
176-
match (&**arch, target.options.is_like_windows) {
176+
match &**arch {
177177
// Windows x86
178-
("x86", true) => {
178+
"x86" if target.options.is_like_windows => {
179179
emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), false)
180180
}
181181
// Generic x86
182-
("x86", _) => {
183-
emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), true)
184-
}
182+
"x86" => emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), true),
185183
// Windows AArch64
186-
("aarch64", true) => {
184+
"aarch64" if target.options.is_like_windows => {
187185
emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), false)
188186
}
189-
// iOS AArch64
190-
("aarch64", _) if target.target_os == "ios" => {
187+
// macOS / iOS AArch64
188+
"aarch64" if target.options.is_like_osx => {
191189
emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), true)
192190
}
193-
("aarch64", _) => emit_aapcs_va_arg(bx, addr, target_ty),
191+
"aarch64" => emit_aapcs_va_arg(bx, addr, target_ty),
194192
// Windows x86_64
195-
("x86_64", true) => {
193+
"x86_64" if target.options.is_like_windows => {
196194
let target_ty_size = bx.cx.size_of(target_ty).bytes();
197195
let indirect: bool = target_ty_size > 8 || !target_ty_size.is_power_of_two();
198196
emit_ptr_va_arg(bx, addr, target_ty, indirect, Align::from_bytes(8).unwrap(), false)

library/core/src/ffi.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl fmt::Debug for c_void {
6262
// The name is WIP, using `VaListImpl` for now.
6363
#[cfg(any(
6464
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
65-
all(target_arch = "aarch64", target_os = "ios"),
65+
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
6666
target_arch = "wasm32",
6767
target_arch = "asmjs",
6868
windows
@@ -85,7 +85,7 @@ pub struct VaListImpl<'f> {
8585

8686
#[cfg(any(
8787
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
88-
all(target_arch = "aarch64", target_os = "ios"),
88+
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
8989
target_arch = "wasm32",
9090
target_arch = "asmjs",
9191
windows
@@ -107,7 +107,11 @@ impl<'f> fmt::Debug for VaListImpl<'f> {
107107
///
108108
/// [AArch64 Procedure Call Standard]:
109109
/// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf
110-
#[cfg(all(target_arch = "aarch64", not(target_os = "ios"), not(windows)))]
110+
#[cfg(all(
111+
target_arch = "aarch64",
112+
not(any(target_os = "macos", target_os = "ios")),
113+
not(windows)
114+
))]
111115
#[repr(C)]
112116
#[derive(Debug)]
113117
#[unstable(
@@ -181,7 +185,7 @@ pub struct VaList<'a, 'f: 'a> {
181185
not(target_arch = "powerpc"),
182186
not(target_arch = "x86_64")
183187
),
184-
all(target_arch = "aarch64", target_os = "ios"),
188+
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
185189
target_arch = "wasm32",
186190
target_arch = "asmjs",
187191
windows
@@ -190,7 +194,7 @@ pub struct VaList<'a, 'f: 'a> {
190194

191195
#[cfg(all(
192196
any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
193-
any(not(target_arch = "aarch64"), not(target_os = "ios")),
197+
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
194198
not(target_arch = "wasm32"),
195199
not(target_arch = "asmjs"),
196200
not(windows)
@@ -202,7 +206,7 @@ pub struct VaList<'a, 'f: 'a> {
202206

203207
#[cfg(any(
204208
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
205-
all(target_arch = "aarch64", target_os = "ios"),
209+
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
206210
target_arch = "wasm32",
207211
target_arch = "asmjs",
208212
windows
@@ -223,7 +227,7 @@ impl<'f> VaListImpl<'f> {
223227

224228
#[cfg(all(
225229
any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
226-
any(not(target_arch = "aarch64"), not(target_os = "ios")),
230+
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
227231
not(target_arch = "wasm32"),
228232
not(target_arch = "asmjs"),
229233
not(windows)

0 commit comments

Comments
 (0)