]> git.lizzy.rs Git - rust.git/blob - tests/codegen/c-variadic-opt.rs
Rollup merge of #106446 - bzEq:fix-unwind-lsda, r=Amanieu
[rust.git] / tests / codegen / c-variadic-opt.rs
1 // compile-flags: -C opt-level=3
2
3 #![crate_type = "lib"]
4 #![feature(c_variadic)]
5 #![no_std]
6 use core::ffi::VaList;
7
8 extern "C" {
9     fn vprintf(fmt: *const i8, ap: VaList) -> i32;
10 }
11
12 // Ensure that `va_start` and `va_end` are properly injected even
13 // when the "spoofed" `VaListImpl` is not used.
14 #[no_mangle]
15 pub unsafe extern "C" fn c_variadic_no_use(fmt: *const i8, mut ap: ...) -> i32 {
16     // CHECK: call void @llvm.va_start
17     vprintf(fmt, ap.as_va_list())
18     // CHECK: call void @llvm.va_end
19 }
20
21 // Check that `VaListImpl::clone` gets inlined into a direct call to `llvm.va_copy`
22 #[no_mangle]
23 pub unsafe extern "C" fn c_variadic_clone(fmt: *const i8, mut ap: ...) -> i32 {
24     // CHECK: call void @llvm.va_start
25     let mut ap2 = ap.clone();
26     // CHECK: call void @llvm.va_copy
27     let res = vprintf(fmt, ap2.as_va_list());
28     res
29     // CHECK: call void @llvm.va_end
30 }