|
| 1 | +//! Verify that Rust implements the expected calling convention for `i128`/`u128`. |
| 2 | +
|
| 3 | +// Eliminate intermediate instructions during `nop` tests |
| 4 | +//@ compile-flags: -Copt-level=1 |
| 5 | + |
| 6 | +//@ add-core-stubs |
| 7 | +//@ revisions: MSVC MINGW |
| 8 | +//@ [MSVC] needs-llvm-components: x86 |
| 9 | +//@ [MINGW] needs-llvm-components: x86 |
| 10 | +//@ [MSVC] compile-flags: --target x86_64-pc-windows-msvc |
| 11 | +//@ [MINGW] compile-flags: --target x86_64-pc-windows-gnu |
| 12 | +//@ [MSVC] filecheck-flags: --check-prefix=WIN |
| 13 | +//@ [MINGW] filecheck-flags: --check-prefix=WIN |
| 14 | + |
| 15 | +#![crate_type = "lib"] |
| 16 | +#![no_std] |
| 17 | +#![no_core] |
| 18 | +#![feature(no_core, lang_items)] |
| 19 | + |
| 20 | +extern crate minicore; |
| 21 | + |
| 22 | +extern "C" { |
| 23 | + fn extern_call(arg0: i128); |
| 24 | + fn extern_ret() -> i128; |
| 25 | +} |
| 26 | + |
| 27 | +#[no_mangle] |
| 28 | +pub extern "C" fn pass(_arg0: u32, arg1: i128) { |
| 29 | + // CHECK-LABEL: @pass( |
| 30 | + // i128 is passed indirectly on Windows. It should load the pointer to the stack and pass |
| 31 | + // a pointer to that allocation. |
| 32 | + // WIN-SAME: %_arg0, ptr{{.*}} %arg1) |
| 33 | + // WIN: [[PASS:%[_0-9]+]] = alloca [16 x i8], align 16 |
| 34 | + // WIN: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1 |
| 35 | + // WIN: store i128 [[LOADED]], ptr [[PASS]] |
| 36 | + // WIN: call void @extern_call |
| 37 | + unsafe { extern_call(arg1) }; |
| 38 | +} |
| 39 | + |
| 40 | +// Check that we produce the correct return ABI |
| 41 | +#[no_mangle] |
| 42 | +pub extern "C" fn ret(_arg0: u32, arg1: i128) -> i128 { |
| 43 | + // CHECK-LABEL: @ret( |
| 44 | + // i128 is returned in xmm0 on Windows |
| 45 | + // FIXME(#134288): This may change for the `-msvc` targets in the future. |
| 46 | + // WIN-SAME: i32{{.*}} %_arg0, ptr{{.*}} %arg1) |
| 47 | + // WIN: [[LOADED:%[_0-9]+]] = load <16 x i8>, ptr %arg1 |
| 48 | + // WIN-NEXT: ret <16 x i8> [[LOADED]] |
| 49 | + arg1 |
| 50 | +} |
| 51 | + |
| 52 | +// Check that we consume the correct return ABI |
| 53 | +#[no_mangle] |
| 54 | +pub extern "C" fn forward(dst: *mut i128) { |
| 55 | + // CHECK-LABEL: @forward |
| 56 | + // WIN-SAME: ptr{{.*}} %dst) |
| 57 | + // WIN: [[RETURNED:%[_0-9]+]] = tail call <16 x i8> @extern_ret() |
| 58 | + // WIN: store <16 x i8> [[RETURNED]], ptr %dst |
| 59 | + // WIN: ret void |
| 60 | + unsafe { *dst = extern_ret() }; |
| 61 | +} |
| 62 | + |
| 63 | +#[repr(C)] |
| 64 | +struct RetAggregate { |
| 65 | + a: i32, |
| 66 | + b: i128, |
| 67 | +} |
| 68 | + |
| 69 | +#[no_mangle] |
| 70 | +pub extern "C" fn ret_aggregate(_arg0: u32, arg1: i128) -> RetAggregate { |
| 71 | + // CHECK-LABEL: @ret_aggregate( |
| 72 | + // Aggregates should also be returned indirectly |
| 73 | + // WIN-SAME: ptr{{.*}}sret([32 x i8]){{.*}}[[RET:%[_0-9]+]], i32{{.*}}%_arg0, ptr{{.*}}%arg1) |
| 74 | + // WIN: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1 |
| 75 | + // WIN: [[GEP:%[_0-9]+]] = getelementptr{{.*}}, ptr [[RET]] |
| 76 | + // WIN: store i128 [[LOADED]], ptr [[GEP]] |
| 77 | + // WIN: ret void |
| 78 | + RetAggregate { a: 1, b: arg1 } |
| 79 | +} |
0 commit comments