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:
parent
f22dca0a1b
commit
1d72037dd3
3 changed files with 27 additions and 9 deletions
19
src/test/codegen/c-variadic-opt.rs
Normal file
19
src/test/codegen/c-variadic-opt.rs
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue