|
| 1 | +//! Test calling variadic functions with various ABIs. |
| 2 | +//@ add-core-stubs |
| 3 | +//@ compile-flags: -Z merge-functions=disabled |
| 4 | +//@ revisions: x86_32 x86_32_win x86_64 aarch64 arm32 |
| 5 | +//@[x86_64] compile-flags: --target x86_64-unknown-linux-gnu |
| 6 | +//@[x86_64] needs-llvm-components: x86 |
| 7 | +//@[x86_32_win] compile-flags: --target i686-pc-windows-msvc |
| 8 | +//@[x86_32_win] needs-llvm-components: x86 |
| 9 | +//@[x86_32] compile-flags: --target i686-unknown-linux-gnu |
| 10 | +//@[x86_32] needs-llvm-components: x86 |
| 11 | +//@[aarch64] compile-flags: --target aarch64-unknown-linux-gnu |
| 12 | +//@[aarch64] needs-llvm-components: aarch64 |
| 13 | +//@[arm32] compile-flags: --target armv7-unknown-linux-gnueabihf |
| 14 | +//@[arm32] needs-llvm-components: arm |
| 15 | +#![crate_type = "lib"] |
| 16 | +#![feature(no_core)] |
| 17 | +#![no_core] |
| 18 | + |
| 19 | +extern crate minicore; |
| 20 | + |
| 21 | +// CHECK-LABEL: @c |
| 22 | +#[unsafe(no_mangle)] |
| 23 | +fn c(f: extern "C" fn(i32, ...)) { |
| 24 | + // CHECK: call void (i32, ...) |
| 25 | + f(22, 44); |
| 26 | +} |
| 27 | + |
| 28 | +// CHECK-LABEL: @system |
| 29 | +#[unsafe(no_mangle)] |
| 30 | +fn system(f: extern "system" fn(i32, ...)) { |
| 31 | + // Crucially, this is *always* the C calling convention, even on Windows. |
| 32 | + // CHECK: call void (i32, ...) |
| 33 | + f(22, 44); |
| 34 | +} |
| 35 | + |
| 36 | +// x86_32-LABEL: @cdecl |
| 37 | +#[unsafe(no_mangle)] |
| 38 | +#[cfg(target_arch = "x86")] |
| 39 | +fn cdecl(f: extern "cdecl" fn(i32, ...)) { |
| 40 | + // x86_32: call void (i32, ...) |
| 41 | + f(22, 44); |
| 42 | +} |
| 43 | + |
| 44 | +// x86_64-LABEL: @sysv |
| 45 | +#[unsafe(no_mangle)] |
| 46 | +#[cfg(target_arch = "x86_64")] |
| 47 | +fn sysv(f: extern "sysv64" fn(i32, ...)) { |
| 48 | + // x86_64: call x86_64_sysvcc void (i32, ...) |
| 49 | + f(22, 44); |
| 50 | +} |
| 51 | + |
| 52 | +// x86_64-LABEL: @win |
| 53 | +#[unsafe(no_mangle)] |
| 54 | +#[cfg(target_arch = "x86_64")] |
| 55 | +fn win(f: extern "win64" fn(i32, ...)) { |
| 56 | + // x86_64: call win64cc void (i32, ...) |
| 57 | + f(22, 44); |
| 58 | +} |
| 59 | + |
| 60 | +// CHECK-LABEL: @efiapi |
| 61 | +#[unsafe(no_mangle)] |
| 62 | +#[cfg(any( |
| 63 | + target_arch = "arm", |
| 64 | + target_arch = "aarch64", |
| 65 | + target_arch = "riscv32", |
| 66 | + target_arch = "riscv64", |
| 67 | + target_arch = "x86", |
| 68 | + target_arch = "x86_64" |
| 69 | +))] |
| 70 | +fn efiapi(f: extern "efiapi" fn(i32, ...)) { |
| 71 | + // x86_32: call void (i32, ...) |
| 72 | + // x86_32_win: call void (i32, ...) |
| 73 | + // x86_64: call win64cc void (i32, ...) |
| 74 | + // aarch64: call void (i32, ...) |
| 75 | + // arm32: call arm_aapcscc void (i32, ...) |
| 76 | + f(22, 44); |
| 77 | +} |
| 78 | + |
| 79 | +// arm32-LABEL: @aapcs |
| 80 | +#[unsafe(no_mangle)] |
| 81 | +#[cfg(target_arch = "arm")] |
| 82 | +fn aapcs(f: extern "aapcs" fn(i32, ...)) { |
| 83 | + // arm32: call arm_aapcscc void (i32, ...) |
| 84 | + f(22, 44); |
| 85 | +} |
0 commit comments