11#![ crate_type = "staticlib" ]
22#![ feature( c_variadic) ]
3+ #![ feature( cfg_select) ]
34
4- use std:: ffi:: { CStr , CString , VaList , c_char, c_double, c_int, c_long, c_longlong} ;
5+ use std:: ffi:: { CStr , CString , VaList , VaListImpl , c_char, c_double, c_int, c_long, c_longlong} ;
56
67macro_rules! continue_if {
78 ( $cond: expr) => {
@@ -19,15 +20,15 @@ unsafe fn compare_c_str(ptr: *const c_char, val: &str) -> bool {
1920 }
2021}
2122
22- #[ no_mangle]
23+ #[ unsafe ( no_mangle) ]
2324pub unsafe extern "C" fn check_list_0 ( mut ap : VaList ) -> usize {
2425 continue_if ! ( ap. arg:: <c_longlong>( ) == 1 ) ;
2526 continue_if ! ( ap. arg:: <c_int>( ) == 2 ) ;
2627 continue_if ! ( ap. arg:: <c_longlong>( ) == 3 ) ;
2728 0
2829}
2930
30- #[ no_mangle]
31+ #[ unsafe ( no_mangle) ]
3132pub unsafe extern "C" fn check_list_1 ( mut ap : VaList ) -> usize {
3233 continue_if ! ( ap. arg:: <c_int>( ) == -1 ) ;
3334 continue_if ! ( ap. arg:: <c_int>( ) == 'A' as c_int) ;
@@ -39,7 +40,7 @@ pub unsafe extern "C" fn check_list_1(mut ap: VaList) -> usize {
3940 0
4041}
4142
42- #[ no_mangle]
43+ #[ unsafe ( no_mangle) ]
4344pub unsafe extern "C" fn check_list_2 ( mut ap : VaList ) -> usize {
4445 continue_if ! ( ap. arg:: <c_double>( ) . floor( ) == 3.14f64 . floor( ) ) ;
4546 continue_if ! ( ap. arg:: <c_long>( ) == 12 ) ;
@@ -51,7 +52,7 @@ pub unsafe extern "C" fn check_list_2(mut ap: VaList) -> usize {
5152 0
5253}
5354
54- #[ no_mangle]
55+ #[ unsafe ( no_mangle) ]
5556pub unsafe extern "C" fn check_list_copy_0 ( mut ap : VaList ) -> usize {
5657 continue_if ! ( ap. arg:: <c_double>( ) . floor( ) == 6.28f64 . floor( ) ) ;
5758 continue_if ! ( ap. arg:: <c_int>( ) == 16 ) ;
@@ -64,14 +65,14 @@ pub unsafe extern "C" fn check_list_copy_0(mut ap: VaList) -> usize {
6465 )
6566}
6667
67- #[ no_mangle]
68+ #[ unsafe ( no_mangle) ]
6869pub unsafe extern "C" fn check_varargs_0 ( _: c_int , mut ap: ...) -> usize {
6970 continue_if ! ( ap. arg:: <c_int>( ) == 42 ) ;
7071 continue_if ! ( compare_c_str( ap. arg:: <* const c_char>( ) , "Hello, World!" ) ) ;
7172 0
7273}
7374
74- #[ no_mangle]
75+ #[ unsafe ( no_mangle) ]
7576pub unsafe extern "C" fn check_varargs_1 ( _: c_int , mut ap: ...) -> usize {
7677 continue_if ! ( ap. arg:: <c_double>( ) . floor( ) == 3.14f64 . floor( ) ) ;
7778 continue_if ! ( ap. arg:: <c_long>( ) == 12 ) ;
@@ -80,12 +81,12 @@ pub unsafe extern "C" fn check_varargs_1(_: c_int, mut ap: ...) -> usize {
8081 0
8182}
8283
83- #[ no_mangle]
84+ #[ unsafe ( no_mangle) ]
8485pub unsafe extern "C" fn check_varargs_2 ( _: c_int , _ap: ...) -> usize {
8586 0
8687}
8788
88- #[ no_mangle]
89+ #[ unsafe ( no_mangle) ]
8990pub unsafe extern "C" fn check_varargs_3 ( _: c_int , mut ap: ...) -> usize {
9091 continue_if ! ( ap. arg:: <c_int>( ) == 1 ) ;
9192 continue_if ! ( ap. arg:: <c_int>( ) == 2 ) ;
@@ -100,7 +101,7 @@ pub unsafe extern "C" fn check_varargs_3(_: c_int, mut ap: ...) -> usize {
100101 0
101102}
102103
103- #[ no_mangle]
104+ #[ unsafe ( no_mangle) ]
104105pub unsafe extern "C" fn check_varargs_4 ( _: c_double , mut ap: ...) -> usize {
105106 continue_if ! ( ap. arg:: <c_double>( ) == 1.0 ) ;
106107 continue_if ! ( ap. arg:: <c_double>( ) == 2.0 ) ;
@@ -118,7 +119,7 @@ pub unsafe extern "C" fn check_varargs_4(_: c_double, mut ap: ...) -> usize {
118119 0
119120}
120121
121- #[ no_mangle]
122+ #[ unsafe ( no_mangle) ]
122123pub unsafe extern "C" fn check_varargs_5 ( _: c_int , mut ap: ...) -> usize {
123124 continue_if ! ( ap. arg:: <c_double>( ) == 1.0 ) ;
124125 continue_if ! ( ap. arg:: <c_int>( ) == 1 ) ;
@@ -148,3 +149,42 @@ pub unsafe extern "C" fn check_varargs_5(_: c_int, mut ap: ...) -> usize {
148149 continue_if ! ( ap. arg:: <c_double>( ) == 13.0 ) ;
149150 0
150151}
152+
153+ unsafe extern "C" {
154+ fn test_variadic ( _: c_int , ...) -> usize ;
155+ fn test_va_list_by_value ( _: VaList ) -> usize ;
156+ fn test_va_list_by_pointer ( _: * mut VaListImpl ) -> usize ;
157+ fn test_va_list_by_pointer_pointer ( _: * mut * mut VaListImpl ) -> usize ;
158+ }
159+
160+ #[ unsafe( no_mangle) ]
161+ extern "C" fn run_test_variadic ( ) -> usize {
162+ return unsafe { test_variadic ( 0 , 1 as c_longlong , 2 as c_int , 3 as c_longlong ) } ;
163+ }
164+
165+ #[ unsafe( no_mangle) ]
166+ extern "C" fn run_test_va_list_by_value ( ) -> usize {
167+ unsafe extern "C" fn helper ( mut ap: ...) -> usize {
168+ unsafe { test_va_list_by_value ( ap. as_va_list ( ) ) }
169+ }
170+
171+ unsafe { helper ( 1 as c_longlong , 2 as c_int , 3 as c_longlong ) }
172+ }
173+
174+ #[ unsafe( no_mangle) ]
175+ extern "C" fn run_test_va_list_by_pointer ( ) -> usize {
176+ unsafe extern "C" fn helper ( mut ap: ...) -> usize {
177+ unsafe { test_va_list_by_pointer ( & mut ap) }
178+ }
179+
180+ unsafe { helper ( 1 as c_longlong , 2 as c_int , 3 as c_longlong ) }
181+ }
182+
183+ #[ unsafe( no_mangle) ]
184+ extern "C" fn run_test_va_list_by_pointer_pointer ( ) -> usize {
185+ unsafe extern "C" fn helper ( mut ap: ...) -> usize {
186+ unsafe { test_va_list_by_pointer_pointer ( & mut ( & mut ap as * mut _ ) ) }
187+ }
188+
189+ unsafe { helper ( 1 as c_longlong , 2 as c_int , 3 as c_longlong ) }
190+ }
0 commit comments