-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking issue for RFC 2137: Support defining C-compatible variadic functions in Rust (c_variadic) #44930
Copy link
Copy link
Open
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-c_variadic`#![feature(c_variadic)]``#![feature(c_variadic)]`S-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRStatus: This is ready to stabilize; it may need a stabilization report and a PRT-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-c_variadic`#![feature(c_variadic)]``#![feature(c_variadic)]`S-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRStatus: This is ready to stabilize; it may need a stabilization report and a PRT-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
View all comments
This is a tracking issue for the RFC "Support defining C-compatible variadic functions in Rust" (rust-lang/rfcs#2137).
Steps:
Unresolved questions
Resolved questions
Miri support
Has been added in #150601.
Continuing bikeshed on the
...syntaxThere has been no discussion of a different syntax in recent years.
When implementing this feature, we will need to determine whether the compiler can provide an appropriate lifetime that prevents a
VaListfrom outliving its corresponding variadic function.The compiler internally determines that lifetime, to make sure that a
VaList<'_>does not outlive the function that created it.Ensure that even when this gets stabilized for regular functions, it is still rejected on
const fn.This is tested in https://github.com/rust-lang/rust/blob/main/tests/ui/parser/variadic-ffi-semantic-restrictions.rs and gives the following error:
We reject c-variadic
asyncfunctions in a similar way.Issue #125431
...desugaring (VaListImpl<'_>) #125431The
VaListdefinition introduced in #141980 circumvents this issue.Issue #61275
This is an issue with c-variadic calls, not with c-variadic definitons.
Issue #141618
VaList<'_>does not carry its ABI in its type #141618We have some forwards-compatible ideas for how to potentially add the ABI to the type in the future. That is only required if we want to allow calling c-variadic functions with a non-system ABI. Because C only allows using the system ABI for c-variadic calls, that is unlikely to come up in practice.
What exactly are the ABI requirements around variadic calls? What are the ABI compatibility rules? Do we have to be concerned about LLVM target features affecting variadic ABI?
Variadic calls using the system ABI do not impose any additional constraints. We already handle some ABI compatibility issues using target modifiers.
Implementation history
va_argcodegenva_argfor x86_64 systemv #141538va_argforpowerpc#141622emit_ptr_va_arg#141623va_argassembly on arm targets #144549VaListand its layoutc_variadic: makeVaListabi-compatible with C #141980other
cfg_select!to select the rightVaListImpldefinition #141361c_variadic: Add future-incompatibility warning for...arguments without a pattern outside ofexternblocks #143619#[rustc_pass_indirectly_in_non_rustic_abis]#144529core::ffi::VaArgSafe#146521feature(c_variadic_naked_functions)#148770c-variadic adjacent
cmse-nonsecure-entryABI being both async and c-variadic #146551