File: i128-x86-callconv.rs

package info (click to toggle)
rustc 1.86.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid
  • size: 913,560 kB
  • sloc: xml: 158,127; python: 35,921; javascript: 19,689; sh: 19,600; cpp: 18,906; ansic: 13,124; asm: 4,376; makefile: 708; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (79 lines) | stat: -rw-r--r-- 2,524 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Verify that Rust implements the expected calling convention for `i128`/`u128`.

// Eliminate intermediate instructions during `nop` tests
//@ compile-flags: -Copt-level=1

//@ add-core-stubs
//@ revisions: MSVC MINGW
//@ [MSVC] needs-llvm-components: x86
//@ [MINGW] needs-llvm-components: x86
//@ [MSVC] compile-flags: --target x86_64-pc-windows-msvc
//@ [MINGW] compile-flags: --target x86_64-pc-windows-gnu
//@ [MSVC] filecheck-flags: --check-prefix=WIN
//@ [MINGW] filecheck-flags: --check-prefix=WIN

#![crate_type = "lib"]
#![no_std]
#![no_core]
#![feature(no_core, lang_items)]

extern crate minicore;

extern "C" {
    fn extern_call(arg0: i128);
    fn extern_ret() -> i128;
}

#[no_mangle]
pub extern "C" fn pass(_arg0: u32, arg1: i128) {
    // CHECK-LABEL: @pass(
    // i128 is passed indirectly on Windows. It should load the pointer to the stack and pass
    // a pointer to that allocation.
    // WIN-SAME: %_arg0, ptr{{.*}} %arg1)
    // WIN: [[PASS:%[_0-9]+]] = alloca [16 x i8], align 16
    // WIN: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1
    // WIN: store i128 [[LOADED]], ptr [[PASS]]
    // WIN: call void @extern_call
    unsafe { extern_call(arg1) };
}

// Check that we produce the correct return ABI
#[no_mangle]
pub extern "C" fn ret(_arg0: u32, arg1: i128) -> i128 {
    // CHECK-LABEL: @ret(
    // i128 is returned in xmm0 on Windows
    // FIXME(#134288): This may change for the `-msvc` targets in the future.
    // WIN-SAME: i32{{.*}} %_arg0, ptr{{.*}} %arg1)
    // WIN: [[LOADED:%[_0-9]+]] = load <16 x i8>, ptr %arg1
    // WIN-NEXT: ret <16 x i8> [[LOADED]]
    arg1
}

// Check that we consume the correct return ABI
#[no_mangle]
pub extern "C" fn forward(dst: *mut i128) {
    // CHECK-LABEL: @forward
    // WIN-SAME: ptr{{.*}} %dst)
    // WIN: [[RETURNED:%[_0-9]+]] = tail call <16 x i8> @extern_ret()
    // WIN: store <16 x i8> [[RETURNED]], ptr %dst
    // WIN: ret void
    unsafe { *dst = extern_ret() };
}

#[repr(C)]
struct RetAggregate {
    a: i32,
    b: i128,
}

#[no_mangle]
pub extern "C" fn ret_aggregate(_arg0: u32, arg1: i128) -> RetAggregate {
    // CHECK-LABEL: @ret_aggregate(
    // Aggregates should also be returned indirectly
    // WIN-SAME: ptr{{.*}}sret([32 x i8]){{.*}}[[RET:%[_0-9]+]], i32{{.*}}%_arg0, ptr{{.*}}%arg1)
    // WIN: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1
    // WIN: [[GEP:%[_0-9]+]] = getelementptr{{.*}}, ptr [[RET]]
    // WIN: store i128 [[LOADED]], ptr [[GEP]]
    // WIN: ret void
    RetAggregate { a: 1, b: arg1 }
}