Skip to content

Commit

Permalink
Allow "C-unwind" fn to have C variadics
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Jun 22, 2024
1 parent a0f01c3 commit 26dccad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ impl<'a> AstValidator<'a> {
(Some(FnCtxt::Foreign), _) => return,
(Some(FnCtxt::Free), Some(header)) => match header.ext {
Extern::Explicit(StrLit { symbol_unescaped: sym::C, .. }, _)
| Extern::Explicit(StrLit { symbol_unescaped: sym::C_dash_unwind, .. }, _)
| Extern::Implicit(_)
if matches!(header.safety, Safety::Unsafe(_)) =>
{
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ symbols! {
Break,
C,
CStr,
C_dash_unwind: "C-unwind",
CallOnceFuture,
CallRefFuture,
Capture,
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/abi/variadic-ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ pub unsafe extern "C" fn test_valist_forward(n: u64, mut ap: ...) -> f64 {
rust_valist_interesting_average(n, ap.as_va_list())
}

pub unsafe extern "C-unwind" fn c_unwind_can_forward(n: u64, mut ap: ...) -> f64 {
rust_valist_interesting_average(n, ap.as_va_list())
}

pub unsafe extern "C" fn test_va_copy(_: u64, mut ap: ...) {
let mut ap2 = ap.clone();
assert_eq!(rust_valist_interesting_average(2, ap2.as_va_list()) as i64, 30);
Expand Down Expand Up @@ -72,6 +76,10 @@ pub fn main() {
assert_eq!(test_valist_forward(2, 10i64, 10f64, 20i64, 20f64) as i64, 30);
}

unsafe {
assert_eq!(c_unwind_can_forward(2, 10i64, 10f64, 20i64, 20f64) as i64, 30);
}

unsafe {
test_va_copy(4, 10i64, 10f64, 20i64, 20f64, 30i64, 30f64, 40i64, 40f64);
}
Expand Down

0 comments on commit 26dccad

Please sign in to comment.