-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #58985 - dlrobertson:fix_58980, r=alexreg
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. r? @alexreg Fixes: #58980
- Loading branch information
Showing
3 changed files
with
27 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |