Skip to content

Commit a107ea1

Browse files
committed
c-variadic: check that inline attributes are accepted on c-variadic functions
they don't do anything, because LLVM is unable to inline c-variadic functions (on most targets, anyway)
1 parent d28c31a commit a107ea1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//@ compile-flags: -C opt-level=3
2+
#![feature(c_variadic)]
3+
4+
// Test that the inline attributes are accepted on C-variadic functions.
5+
//
6+
// Currently LLVM is unable to inline C-variadic functions, but that is valid because despite
7+
// the name even `#[inline(always)]` is just a hint.
8+
9+
#[inline(always)]
10+
unsafe extern "C" fn inline_always(mut ap: ...) -> u32 {
11+
ap.arg::<u32>()
12+
}
13+
14+
#[inline]
15+
unsafe extern "C" fn inline(mut ap: ...) -> u32 {
16+
ap.arg::<u32>()
17+
}
18+
19+
#[inline(never)]
20+
unsafe extern "C" fn inline_never(mut ap: ...) -> u32 {
21+
ap.arg::<u32>()
22+
}
23+
24+
#[cold]
25+
unsafe extern "C" fn cold(mut ap: ...) -> u32 {
26+
ap.arg::<u32>()
27+
}
28+
29+
#[unsafe(no_mangle)]
30+
#[inline(never)]
31+
fn helper() {
32+
// CHECK-LABEL: helper
33+
// CHECK-LABEL: call c_variadic_inline::inline_always
34+
// CHECK-LABEL: call c_variadic_inline::inline
35+
// CHECK-LABEL: call c_variadic_inline::inline_never
36+
// CHECK-LABEL: call c_variadic_inline::cold
37+
unsafe {
38+
inline_always(1);
39+
inline(2);
40+
inline_never(3);
41+
cold(4);
42+
}
43+
}
44+
45+
fn main() {
46+
helper()
47+
}

0 commit comments

Comments
 (0)