about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-05-27 15:43:55 +0000
committerbors <bors@rust-lang.org>2025-05-27 15:43:55 +0000
commitc583fa6d8425dbb38fe5d1dbd007f9ca8e4aa128 (patch)
tree3632c9c4156fe847e290be9a4a700824a0a1af28 /compiler/rustc_codegen_llvm/src
parent642e49bfed2481e54e252732be20d3c24cbec9e8 (diff)
parentd7e961a4c92e0d9d634bbdf8f35c292740fe1c7a (diff)
downloadrust-c583fa6d8425dbb38fe5d1dbd007f9ca8e4aa128.tar.gz
rust-c583fa6d8425dbb38fe5d1dbd007f9ca8e4aa128.zip
Auto merge of #141644 - compiler-errors:rollup-gl5hize, r=compiler-errors
Rollup of 17 pull requests

Successful merges:

 - rust-lang/rust#140591 (Fix malformed suggestion for E0061 when method is a macro token in macro context)
 - rust-lang/rust#141536 (Improve `ambiguous_wide_pointer_comparisons` lint compare diagnostics)
 - rust-lang/rust#141552 (Pull out dedicated `cfg_version` syntax test from feature gate test)
 - rust-lang/rust#141556 (bootstrap: translate Windows paths in a way that works for both Cygwin and MSYS2)
 - rust-lang/rust#141563 (Remove out-of-date `noop_*` names.)
 - rust-lang/rust#141568 (dist: make sure llvm-project submodule is present)
 - rust-lang/rust#141580 (Use more detailed spans in dyn compat errors within bodies)
 - rust-lang/rust#141582 (intrinsics, ScalarInt: minor cleanup)
 - rust-lang/rust#141584 (Support `opaque_types_defined_by` for `SyntheticCoroutineBody`)
 - rust-lang/rust#141587 (Add missing edition directives for async-await tests)
 - rust-lang/rust#141594 (Add `generic_arg_infer` test)
 - rust-lang/rust#141596 (rustc book: fix erratic sentence by making it more simple)
 - rust-lang/rust#141599 (Remove an unnecessary use of `Box::into_inner`.)
 - rust-lang/rust#141611 (Update mdbook to 0.4.51)
 - rust-lang/rust#141616 (Remove spastorino from vacations)
 - rust-lang/rust#141623 (use custom types to clarify arguments to `emit_ptr_va_arg`)
 - rust-lang/rust#141635 (further dedup `WalkItemKind` for `mut_visit` and `visit`)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/va_arg.rs83
1 files changed, 61 insertions, 22 deletions
diff --git a/compiler/rustc_codegen_llvm/src/va_arg.rs b/compiler/rustc_codegen_llvm/src/va_arg.rs
index c216f0f4a09..b91b6efed45 100644
--- a/compiler/rustc_codegen_llvm/src/va_arg.rs
+++ b/compiler/rustc_codegen_llvm/src/va_arg.rs
@@ -63,14 +63,33 @@ fn emit_direct_ptr_va_arg<'ll, 'tcx>(
     }
 }
 
+enum PassMode {
+    Direct,
+    Indirect,
+}
+
+enum SlotSize {
+    Bytes8 = 8,
+    Bytes4 = 4,
+}
+
+enum AllowHigherAlign {
+    No,
+    Yes,
+}
+
 fn emit_ptr_va_arg<'ll, 'tcx>(
     bx: &mut Builder<'_, 'll, 'tcx>,
     list: OperandRef<'tcx, &'ll Value>,
     target_ty: Ty<'tcx>,
-    indirect: bool,
-    slot_size: Align,
-    allow_higher_align: bool,
+    pass_mode: PassMode,
+    slot_size: SlotSize,
+    allow_higher_align: AllowHigherAlign,
 ) -> &'ll Value {
+    let indirect = matches!(pass_mode, PassMode::Indirect);
+    let allow_higher_align = matches!(allow_higher_align, AllowHigherAlign::Yes);
+    let slot_size = Align::from_bytes(slot_size as u64).unwrap();
+
     let layout = bx.cx.layout_of(target_ty);
     let (llty, size, align) = if indirect {
         (
@@ -179,8 +198,14 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
 
     // On Stack block
     bx.switch_to_block(on_stack);
-    let stack_value =
-        emit_ptr_va_arg(bx, list, target_ty, false, Align::from_bytes(8).unwrap(), true);
+    let stack_value = emit_ptr_va_arg(
+        bx,
+        list,
+        target_ty,
+        PassMode::Direct,
+        SlotSize::Bytes8,
+        AllowHigherAlign::Yes,
+    );
     bx.br(end);
 
     bx.switch_to_block(end);
@@ -386,29 +411,43 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
     // Determine the va_arg implementation to use. The LLVM va_arg instruction
     // is lacking in some instances, so we should only use it as a fallback.
     let target = &bx.cx.tcx.sess.target;
-    let arch = &bx.cx.tcx.sess.target.arch;
-    match &**arch {
-        // Windows x86
-        "x86" if target.is_like_windows => {
-            emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), false)
-        }
-        // Generic x86
-        "x86" => emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), true),
-        // Windows AArch64
-        "aarch64" | "arm64ec" if target.is_like_windows => {
-            emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), false)
-        }
-        // macOS / iOS AArch64
-        "aarch64" if target.is_like_darwin => {
-            emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), true)
+
+    match &*target.arch {
+        "x86" => emit_ptr_va_arg(
+            bx,
+            addr,
+            target_ty,
+            PassMode::Direct,
+            SlotSize::Bytes4,
+            if target.is_like_windows { AllowHigherAlign::No } else { AllowHigherAlign::Yes },
+        ),
+        "aarch64" | "arm64ec" if target.is_like_windows || target.is_like_darwin => {
+            emit_ptr_va_arg(
+                bx,
+                addr,
+                target_ty,
+                PassMode::Direct,
+                SlotSize::Bytes8,
+                if target.is_like_windows { AllowHigherAlign::No } else { AllowHigherAlign::Yes },
+            )
         }
         "aarch64" => emit_aapcs_va_arg(bx, addr, target_ty),
         "s390x" => emit_s390x_va_arg(bx, addr, target_ty),
         // Windows x86_64
         "x86_64" if target.is_like_windows => {
             let target_ty_size = bx.cx.size_of(target_ty).bytes();
-            let indirect: bool = target_ty_size > 8 || !target_ty_size.is_power_of_two();
-            emit_ptr_va_arg(bx, addr, target_ty, indirect, Align::from_bytes(8).unwrap(), false)
+            emit_ptr_va_arg(
+                bx,
+                addr,
+                target_ty,
+                if target_ty_size > 8 || !target_ty_size.is_power_of_two() {
+                    PassMode::Indirect
+                } else {
+                    PassMode::Direct
+                },
+                SlotSize::Bytes8,
+                AllowHigherAlign::No,
+            )
         }
         "xtensa" => emit_xtensa_va_arg(bx, addr, target_ty),
         // For all other architecture/OS combinations fall back to using