Delegation incorrectly assumes VaListImpl<'_>
from ...
will correctly pass-through to ...
#127443
Labels
A-ABI
Area: Concerning the application binary interface (ABI)
A-FFI
Area: Foreign function interface (FFI)
C-bug
Category: This is a bug.
F-c_variadic
`#![feature(c_variadic)]`
F-fn_delegation
`#![feature(fn_delegation)]`
requires-incomplete-features
This issue requires the use of incomplete features.
To quote @petrochenkov in #127401 (comment)
Unfortunately,
...
andva_list
are different types for good reason: one is arguments that have not been "discovered" yet in the function, whereasva_list
is a structure that describes how to acquire those arguments, and may be acquired by rolling some or all of those arguments into the structure at the moment of its creation.This is why, in C, there are both of these functions.
They are not duplicates of each other, and attempting to treat them as such is a common source of UB in C programs written by people foolish enough to meddle with variadic functions in C. ( So, most of them, considering the existence of printf. )
When we receive arguments into
...
usingfeature(c_variadic)
, Rust currently implicitly creates aVaListImpl<'_>
, which approximately equates to C'sva_list
. We do this implicitly rather than requiring someone to callva_start
. We are not guaranteed to know, as far as I am aware, how many arguments were passed or their shape. Some ABIs pass the necessary knowledge as a hidden parameter. But others don't. If we could control the ABI, of course, we would have the ability to do so every time, but this feature is about interfacing with C ABIs.This interaction of features is thus currently incorrect and is undefined behavior even if a function with
...
arguments is correctly called by Rust, as long as it passes through a layer of delegation.What @petrochenkov describes is desirable, but I expect the answer will be "technically impossible, even over a reasonable subset of our supported platforms". I will do the necessary research either way. But until we confirm this, or apply the necessary changes to support delegating
unsafe extern "C" fn(...)
, or redesignfeature(c_variadic)
, whatever it would take to fix this, the following code must be rejected by the compiler:This bug is currently live in the most recent Rust nightlies.
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: