Skip to content

Commit 321a76b

Browse files
committed
c-variadic: test that unsupported c-variadic ABIs are reported correctly
1 parent 01e83ad commit 321a76b

File tree

2 files changed

+468
-0
lines changed

2 files changed

+468
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
//@ add-core-stubs
2+
//@ needs-llvm-components: x86
3+
//@ compile-flags: --target=i686-pc-windows-gnu --crate-type=rlib
4+
#![no_core]
5+
#![feature(no_core, lang_items, c_variadic)]
6+
7+
// Test that ABIs for which C-variadics are not supported report an error.
8+
9+
extern crate minicore;
10+
use minicore::*;
11+
12+
#[rustfmt::skip]
13+
mod foreign {
14+
extern "Rust" { fn rust_foreign_explicit(_: ...); }
15+
//~^ ERROR C-variadic functions with the "Rust" calling convention are not supported
16+
extern "C" { fn c_foreign(_: ...); }
17+
extern "C-unwind" { fn c_unwind_foreign(_: ...); }
18+
extern "cdecl" { fn cdecl_foreign(_: ...); }
19+
extern "cdecl-unwind" { fn cdecl_unwind_foreign(_: ...); }
20+
extern "stdcall" { fn stdcall_foreign(_: ...); }
21+
//~^ ERROR C-variadic functions with the "stdcall" calling convention are not supported
22+
extern "stdcall-unwind" { fn stdcall_unwind_foreign(_: ...); }
23+
//~^ ERROR C-variadic functions with the "stdcall-unwind" calling convention are not supported
24+
extern "thiscall" { fn thiscall_foreign(_: ...); }
25+
//~^ ERROR C-variadic functions with the "thiscall" calling convention are not supported
26+
extern "thiscall-unwind" { fn thiscall_unwind_foreign(_: ...); }
27+
//~^ ERROR C-variadic functions with the "thiscall-unwind" calling convention are not supported
28+
}
29+
30+
#[lang = "va_list"]
31+
struct VaList(*mut u8);
32+
33+
unsafe fn rust_free(_: ...) {}
34+
//~^ ERROR `...` is not supported for non-extern functions
35+
unsafe extern "Rust" fn rust_free_explicit(_: ...) {}
36+
//~^ ERROR `...` is not supported for `extern "Rust"` functions
37+
38+
unsafe extern "C" fn c_free(_: ...) {}
39+
unsafe extern "C-unwind" fn c_unwind_free(_: ...) {}
40+
41+
unsafe extern "cdecl" fn cdecl_free(_: ...) {}
42+
//~^ ERROR `...` is not supported for `extern "cdecl"` functions
43+
unsafe extern "cdecl-unwind" fn cdecl_unwind_free(_: ...) {}
44+
//~^ ERROR `...` is not supported for `extern "cdecl-unwind"` functions
45+
unsafe extern "stdcall" fn stdcall_free(_: ...) {}
46+
//~^ ERROR `...` is not supported for `extern "stdcall"` functions
47+
unsafe extern "stdcall-unwind" fn stdcall_unwind_free(_: ...) {}
48+
//~^ ERROR `...` is not supported for `extern "stdcall-unwind"` functions
49+
unsafe extern "thiscall" fn thiscall_free(_: ...) {}
50+
//~^ ERROR `...` is not supported for `extern "thiscall"` functions
51+
unsafe extern "thiscall-unwind" fn thiscall_unwind_free(_: ...) {}
52+
//~^ ERROR `...` is not supported for `extern "thiscall-unwind"` functions
53+
54+
struct S;
55+
56+
impl S {
57+
unsafe fn rust_method(_: ...) {}
58+
//~^ ERROR `...` is not supported for non-extern functions
59+
unsafe extern "Rust" fn rust_method_explicit(_: ...) {}
60+
//~^ ERROR `...` is not supported for `extern "Rust"` functions
61+
62+
unsafe extern "C" fn c_method(_: ...) {}
63+
unsafe extern "C-unwind" fn c_unwind_method(_: ...) {}
64+
65+
unsafe extern "cdecl" fn cdecl_method(_: ...) {}
66+
//~^ ERROR `...` is not supported for `extern "cdecl"` functions
67+
unsafe extern "cdecl-unwind" fn cdecl_unwind_method(_: ...) {}
68+
//~^ ERROR `...` is not supported for `extern "cdecl-unwind"` functions
69+
unsafe extern "stdcall" fn stdcall_method(_: ...) {}
70+
//~^ ERROR `...` is not supported for `extern "stdcall"` functions
71+
unsafe extern "stdcall-unwind" fn stdcall_unwind_method(_: ...) {}
72+
//~^ ERROR `...` is not supported for `extern "stdcall-unwind"` functions
73+
unsafe extern "thiscall" fn thiscall_method(_: ...) {}
74+
//~^ ERROR `...` is not supported for `extern "thiscall"` functions
75+
unsafe extern "thiscall-unwind" fn thiscall_unwind_method(_: ...) {}
76+
//~^ ERROR `...` is not supported for `extern "thiscall-unwind"` functions
77+
}
78+
79+
trait T {
80+
unsafe fn rust_trait_method(_: ...) {}
81+
//~^ ERROR `...` is not supported for non-extern functions
82+
unsafe extern "Rust" fn rust_trait_method_explicit(_: ...) {}
83+
//~^ ERROR `...` is not supported for `extern "Rust"` functions
84+
85+
unsafe extern "C" fn c_trait_method(_: ...) {}
86+
unsafe extern "C-unwind" fn c_unwind_trait_method(_: ...) {}
87+
88+
unsafe extern "cdecl" fn cdecl_trait_method(_: ...) {}
89+
//~^ ERROR `...` is not supported for `extern "cdecl"` functions
90+
unsafe extern "cdecl-unwind" fn cdecl_unwind_trait_method(_: ...) {}
91+
//~^ ERROR `...` is not supported for `extern "cdecl-unwind"` functions
92+
unsafe extern "stdcall" fn stdcall_trait_method(_: ...) {}
93+
//~^ ERROR `...` is not supported for `extern "stdcall"` functions
94+
unsafe extern "stdcall-unwind" fn stdcall_unwind_trait_method(_: ...) {}
95+
//~^ ERROR `...` is not supported for `extern "stdcall-unwind"` functions
96+
unsafe extern "thiscall" fn thiscall_trait_method(_: ...) {}
97+
//~^ ERROR `...` is not supported for `extern "thiscall"` functions
98+
unsafe extern "thiscall-unwind" fn thiscall_unwind_trait_method(_: ...) {}
99+
//~^ ERROR `...` is not supported for `extern "thiscall-unwind"` functions
100+
}
101+
102+
impl T for S {
103+
unsafe fn rust_trait_method(_: ...) {}
104+
//~^ ERROR `...` is not supported for non-extern functions
105+
unsafe extern "Rust" fn rust_trait_method_explicit(_: ...) {}
106+
//~^ ERROR `...` is not supported for `extern "Rust"` functions
107+
108+
unsafe extern "C" fn c_trait_method(_: ...) {}
109+
unsafe extern "C-unwind" fn c_unwind_trait_method(_: ...) {}
110+
111+
unsafe extern "cdecl" fn cdecl_trait_method(_: ...) {}
112+
//~^ ERROR `...` is not supported for `extern "cdecl"` functions
113+
unsafe extern "cdecl-unwind" fn cdecl_unwind_trait_method(_: ...) {}
114+
//~^ ERROR `...` is not supported for `extern "cdecl-unwind"` functions
115+
unsafe extern "stdcall" fn stdcall_trait_method(_: ...) {}
116+
//~^ ERROR `...` is not supported for `extern "stdcall"` functions
117+
unsafe extern "stdcall-unwind" fn stdcall_unwind_trait_method(_: ...) {}
118+
//~^ ERROR `...` is not supported for `extern "stdcall-unwind"` functions
119+
unsafe extern "thiscall" fn thiscall_trait_method(_: ...) {}
120+
//~^ ERROR `...` is not supported for `extern "thiscall"` functions
121+
unsafe extern "thiscall-unwind" fn thiscall_unwind_trait_method(_: ...) {}
122+
//~^ ERROR `...` is not supported for `extern "thiscall-unwind"` functions
123+
}

0 commit comments

Comments
 (0)