Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1838,10 +1838,6 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {

Cow::Owned(casted_args)
}

pub(crate) fn va_arg(&mut self, list: &'ll Value, ty: Type<'ll>) -> &'ll Value {
unsafe { llvm::LLVMBuildVAArg(self.llbuilder(), list, ty, UNNAMED) }
}
}

impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_codegen_llvm/src/va_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,17 +1313,19 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
AllowHigherAlign::No,
ForceRightAdjust::No,
),
Arch::M68k => emit_ptr_va_arg(
bx,
addr,
layout,
PassMode::Direct,
SlotSize::Bytes4,
AllowHigherAlign::No,
ForceRightAdjust::Yes,
),

Arch::Bpf => bug!("bpf does not support c-variadic functions"),
Arch::SpirV => bug!("spirv does not support c-variadic functions"),

Arch::M68k => {
std::assert_matches!(stability, CVariadicStatus::Unstable { .. });

// Clang uses the LLVM implementation for these architectures.
bx.va_arg(addr.immediate(), layout.llvm_type(bx.cx))
}

Arch::Other(ref arch) => {
std::assert_matches!(stability, CVariadicStatus::Unstable { .. });

Expand Down
67 changes: 67 additions & 0 deletions tests/assembly-llvm/c-variadic/m68k.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//@ add-minicore
//@ assembly-output: emit-asm
//
//@ compile-flags: -Copt-level=3 --target=m68k-unknown-linux-gnu
//@ needs-llvm-components: m68k
#![feature(c_variadic_experimental_arch, no_core, lang_items, intrinsics, rustc_attrs)]
#![no_core]
#![crate_type = "lib"]

extern crate minicore;
use minicore::ffi::VaList;
use minicore::*;

// This checks `va_arg` does the same thing as GCC.

#[unsafe(no_mangle)]
unsafe extern "C" fn read_f64(ap: &mut VaList<'_>) -> f64 {
// CHECK-LABEL: read_f64
//
// CHECK: move.l (4,%sp), %a0
// CHECK-NEXT: move.l (%a0), %d0
// CHECK-NEXT: move.l %d0, %d1
// CHECK-NEXT: add.l #8, %d1
// CHECK-NEXT: move.l %d1, (%a0)
// CHECK-NEXT: move.l %d0, %a0
// CHECK-NEXT: move.l (%a0), %d0
// CHECK-NEXT: move.l (4,%a0), %d1
// CHECK-NEXT: rts
ap.next_arg()
}

#[unsafe(no_mangle)]
unsafe extern "C" fn read_i32(ap: &mut VaList<'_>) -> i32 {
// CHECK-LABEL: read_i32
//
// CHECK: move.l (4,%sp), %a0
// CHECK-NEXT: move.l (%a0), %d0
// CHECK-NEXT: move.l %d0, %d1
// CHECK-NEXT: add.l #4, %d1
// CHECK-NEXT: move.l %d1, (%a0)
// CHECK-NEXT: move.l %d0, %a0
// CHECK-NEXT: move.l (%a0), %d0
// CHECK-NEXT: rts
ap.next_arg()
}

#[unsafe(no_mangle)]
unsafe extern "C" fn read_i64(ap: &mut VaList<'_>) -> i64 {
// CHECK-LABEL: read_i64
//
// CHECK: move.l (4,%sp), %a0
// CHECK-NEXT: move.l (%a0), %d0
// CHECK-NEXT: move.l %d0, %d1
// CHECK-NEXT: add.l #8, %d1
// CHECK-NEXT: move.l %d1, (%a0)
// CHECK-NEXT: move.l %d0, %a0
// CHECK-NEXT: move.l (%a0), %d0
// CHECK-NEXT: move.l (4,%a0), %d1
// CHECK-NEXT: rts
ap.next_arg()
}

#[unsafe(no_mangle)]
unsafe extern "C" fn read_ptr(ap: &mut VaList<'_>) -> *const u8 {
// CHECK: read_ptr = read_i32
ap.next_arg()
}
Loading