1
Fork 0

Fix segfaults in release build C-variadic fns

`va_start` and `va_end` must be called to initialize/cleanup the
"spoofed" `VaList` in a Rust defined C-variadic function even if
the `VaList` is not used.
This commit is contained in:
Dan Robertson 2019-03-07 03:50:50 +00:00
parent f22dca0a1b
commit 1d72037dd3
No known key found for this signature in database
GPG key ID: 45C4A652C47E42A5
3 changed files with 27 additions and 9 deletions

View file

@ -0,0 +1,19 @@
// compile-flags: -C opt-level=3
#![crate_type = "lib"]
#![feature(c_variadic)]
#![no_std]
use core::ffi::VaList;
extern "C" {
fn vprintf(fmt: *const i8, ap: VaList) -> i32;
}
// Ensure that `va_start` and `va_end` are properly injected even
// when the "spoofed" `VaList` is not used.
#[no_mangle]
pub unsafe extern "C" fn c_variadic_no_use(fmt: *const i8, mut ap: ...) -> i32 {
// CHECK: call void @llvm.va_start
vprintf(fmt, ap)
// CHECK: call void @llvm.va_end
}