|
21 | 21 | extern crate minicore; |
22 | 22 | use minicore::*; |
23 | 23 |
|
24 | | -// Make sure the argument is always passed when explicitly requesting a Windows ABI. |
| 24 | +#[repr(C)] |
| 25 | +struct CZst; |
| 26 | + |
| 27 | +#[repr(transparent)] |
| 28 | +struct CZst2((), CZst, ()); |
| 29 | + |
| 30 | +// Make sure the argument is always passed when explicitly requesting a Windows ABI, |
| 31 | +// and it is `repr(C)` - but not if it is `repr(Rust)`. |
25 | 32 | // Our goal here is to match clang: <https://clang.godbolt.org/z/Wr4jMWq3P>. |
26 | 33 |
|
27 | | -// CHECK: define win64cc void @pass_zst_win64(ptr {{[^,]*}}) |
| 34 | +// CHECK: define win64cc void @pass_rust_zst_win64() |
| 35 | +#[no_mangle] |
| 36 | +extern "win64" fn pass_rust_zst_win64(_: ()) {} |
| 37 | + |
| 38 | +// CHECK: define win64cc void @pass_c_zst_win64(ptr {{[^,]*}}) |
| 39 | +#[no_mangle] |
| 40 | +extern "win64" fn pass_c_zst_win64(_: CZst) {} |
| 41 | + |
| 42 | +// CHECK: define win64cc void @pass_c_zst_2_win64(ptr {{[^,]*}}) |
| 43 | +#[no_mangle] |
| 44 | +extern "win64" fn pass_c_zst_2_win64(_: CZst2) {} |
| 45 | + |
| 46 | +// CHECK: define x86_vectorcallcc void @pass_rust_zst_vectorcall() |
| 47 | +#[no_mangle] |
| 48 | +extern "vectorcall" fn pass_rust_zst_vectorcall(_: ()) {} |
| 49 | + |
| 50 | +// CHECK: define x86_vectorcallcc void @pass_c_zst_vectorcall(ptr {{[^,]*}}) |
28 | 51 | #[no_mangle] |
29 | | -extern "win64" fn pass_zst_win64(_: ()) {} |
| 52 | +extern "vectorcall" fn pass_c_zst_vectorcall(_: CZst) {} |
30 | 53 |
|
31 | | -// CHECK: define x86_vectorcallcc void @pass_zst_vectorcall(ptr {{[^,]*}}) |
| 54 | +// CHECK: define x86_vectorcallcc void @pass_c_zst_2_vectorcall(ptr {{[^,]*}}) |
32 | 55 | #[no_mangle] |
33 | | -extern "vectorcall" fn pass_zst_vectorcall(_: ()) {} |
| 56 | +extern "vectorcall" fn pass_c_zst_2_vectorcall(_: CZst2) {} |
34 | 57 |
|
35 | | -// windows-gnu: define void @pass_zst_fastcall(ptr {{[^,]*}}) |
36 | | -// windows-msvc: define void @pass_zst_fastcall(ptr {{[^,]*}}) |
| 58 | +// windows-gnu: define void @pass_rust_zst_fastcall() |
| 59 | +// windows-msvc: define void @pass_rust_zst_fastcall() |
37 | 60 | #[no_mangle] |
38 | 61 | #[cfg(windows)] // "fastcall" is not valid on 64bit Linux |
39 | | -extern "fastcall" fn pass_zst_fastcall(_: ()) {} |
| 62 | +extern "fastcall" fn pass_rust_zst_fastcall(_: ()) {} |
| 63 | + |
| 64 | +// windows-gnu: define void @pass_c_zst_fastcall(ptr {{[^,]*}}) |
| 65 | +// windows-msvc: define void @pass_c_zst_fastcall(ptr {{[^,]*}}) |
| 66 | +#[no_mangle] |
| 67 | +#[cfg(windows)] // "fastcall" is not valid on 64bit Linux |
| 68 | +extern "fastcall" fn pass_c_zst_fastcall(_: CZst) {} |
| 69 | + |
| 70 | +// windows-gnu: define void @pass_c_zst_2_fastcall(ptr {{[^,]*}}) |
| 71 | +// windows-msvc: define void @pass_c_zst_2_fastcall(ptr {{[^,]*}}) |
| 72 | +#[no_mangle] |
| 73 | +#[cfg(windows)] // "fastcall" is not valid on 64bit Linux |
| 74 | +extern "fastcall" fn pass_c_zst_2_fastcall(_: CZst2) {} |
40 | 75 |
|
41 | 76 | // The sysv64 ABI ignores ZST. |
42 | 77 |
|
43 | | -// CHECK: define x86_64_sysvcc void @pass_zst_sysv64() |
| 78 | +// CHECK: define x86_64_sysvcc void @pass_rust_zst_sysv64() |
| 79 | +#[no_mangle] |
| 80 | +extern "sysv64" fn pass_rust_zst_sysv64(_: ()) {} |
| 81 | + |
| 82 | +// CHECK: define x86_64_sysvcc void @pass_c_zst_sysv64() |
| 83 | +#[no_mangle] |
| 84 | +extern "sysv64" fn pass_c_zst_sysv64(_: CZst) {} |
| 85 | + |
| 86 | +// CHECK: define x86_64_sysvcc void @pass_c_zst_2_sysv64() |
44 | 87 | #[no_mangle] |
45 | | -extern "sysv64" fn pass_zst_sysv64(_: ()) {} |
| 88 | +extern "sysv64" fn pass_c_zst_2_sysv64(_: CZst2) {} |
46 | 89 |
|
47 | 90 | // For `extern "C"` functions, ZST are ignored on Linux put passed on Windows. |
48 | 91 |
|
49 | | -// linux: define void @pass_zst_c() |
50 | | -// windows-msvc: define void @pass_zst_c(ptr {{[^,]*}}) |
51 | | -// windows-gnu: define void @pass_zst_c(ptr {{[^,]*}}) |
| 92 | +// linux: define void @pass_rust_zst_c() |
| 93 | +// windows-msvc: define void @pass_rust_zst_c() |
| 94 | +// windows-gnu: define void @pass_rust_zst_c() |
| 95 | +#[no_mangle] |
| 96 | +extern "C" fn pass_rust_zst_c(_: ()) {} |
| 97 | + |
| 98 | +// linux: define void @pass_c_zst_c() |
| 99 | +// windows-msvc: define void @pass_c_zst_c(ptr {{[^,]*}}) |
| 100 | +// windows-gnu: define void @pass_c_zst_c(ptr {{[^,]*}}) |
| 101 | +#[no_mangle] |
| 102 | +extern "C" fn pass_c_zst_c(_: CZst) {} |
| 103 | + |
| 104 | +// linux: define void @pass_c_zst_2_c() |
| 105 | +// windows-msvc: define void @pass_c_zst_2_c(ptr {{[^,]*}}) |
| 106 | +// windows-gnu: define void @pass_c_zst_2_c(ptr {{[^,]*}}) |
| 107 | +#[no_mangle] |
| 108 | +extern "C" fn pass_c_zst_2_c(_: CZst2) {} |
| 109 | + |
| 110 | +// Now check `repr(C)` return types. |
| 111 | +// Again, we seek to match clang: <https://clang.godbolt.org/z/hKv74ThnE> |
| 112 | + |
| 113 | +// CHECK: define win64cc void @ret_c_zst_win64(ptr {{[^,]*}}) |
| 114 | +#[no_mangle] |
| 115 | +extern "win64" fn ret_c_zst_win64() -> CZst { |
| 116 | + CZst |
| 117 | +} |
| 118 | + |
| 119 | +// CHECK: define x86_vectorcallcc void @ret_c_zst_vectorcall(ptr {{[^,]*}}) |
| 120 | +#[no_mangle] |
| 121 | +extern "vectorcall" fn ret_c_zst_vectorcall() -> CZst { |
| 122 | + CZst |
| 123 | +} |
| 124 | + |
| 125 | +// windows-gnu: define void @ret_c_zst_fastcall(ptr {{[^,]*}}) |
| 126 | +// windows-msvc: define void @ret_c_zst_fastcall(ptr {{[^,]*}}) |
| 127 | +#[no_mangle] |
| 128 | +#[cfg(windows)] // "fastcall" is not valid on 64bit Linux |
| 129 | +extern "fastcall" fn ret_c_zst_fastcall() -> CZst { |
| 130 | + CZst |
| 131 | +} |
| 132 | + |
| 133 | +// The sysv64 ABI ignores ZST. |
| 134 | + |
| 135 | +// CHECK: define x86_64_sysvcc void @ret_c_zst_sysv64() |
| 136 | +#[no_mangle] |
| 137 | +extern "sysv64" fn ret_c_zst_sysv64() -> CZst { |
| 138 | + CZst |
| 139 | +} |
| 140 | + |
| 141 | +// For `extern "C"` functions, ZST are ignored on Linux put reted on Windows. |
| 142 | + |
| 143 | +// linux: define void @ret_c_zst_c() |
| 144 | +// windows-msvc: define void @ret_c_zst_c(ptr {{[^,]*}}) |
| 145 | +// windows-gnu: define void @ret_c_zst_c(ptr {{[^,]*}}) |
52 | 146 | #[no_mangle] |
53 | | -extern "C" fn pass_zst_c(_: ()) {} |
| 147 | +extern "C" fn ret_c_zst_c() -> CZst { |
| 148 | + CZst |
| 149 | +} |
0 commit comments