-
Notifications
You must be signed in to change notification settings - Fork 13.4k
VaList<'_>
does not carry its ABI in its type
#141618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The |
Even so, we'd still need T-lang to formally decide that we want to close off the road of being more flexible than clang. But given that clang does not support per-abi |
Happy to rule things out if we want. Our |
I ask about that because I'm wondering if we'd have to error on the definition existing at all, in effect. I know sometimes C functions are declared with variable arguments but they don't actually "use" them in a traditional sense, but I'm not sure we'd have that same leeway. |
Yes, the current desugaring is equivalent to creating a stack value of type va_list foo;
va_start(foo); We also automatically add a call to (the equivalent of) the |
This was very briefly discussed in T-lang's meeting on May 28th and @joshtriplett suggested that we could handle this in the future if we wanted to add such support by using new types. This offers the choice of
...and both seem basically fine to me. |
Note that we probably shouldn't even support, even when compiling for x86_64-unknown-linux, the following, without deciding on how we are addressing this issue (closing the door or what), one way or another: pub extern "sysv64" fn has_varargs(args: ...) {
let args = args; // this needs to already have the final type we want picked for it
} So we should only support these for now: pub extern "C" fn has_varargs(args: ...) {
}
pub extern "C-unwind" fn unwind_with_varargs(args: ...) {
} |
Uh oh!
There was an error while loading. Please reload this page.
Consider the following code that will be valid with
extended_varargs_abi_support
andc_variadic
:For
VaList<'_>
, part of thec_variadic
feature, the type does not contain the ABI it is used with. However, if we want to support defining functions with...
, that useVaList<'_>
internally, for every ABI that we would accept with declarations of functions that accept...
, like so:then we have two problems:
VaList
implementation, but in actuality it can have an implementation for each ABI it supports!VaList
that we construct can now be passed to a function likevsnprintf
(or the previousnix_valist
andwin_valist
) which accepts theVaList
as a parameter. BecauseVaList
does not include the ABI it is constructed with in its type, it is valid to pass it to a function that will assume it uses a different varargs ABI. This can cause incorrect behavior in programs that otherwise take sensible precautions with using variable arguments, like using other data to transfer argument counts and types.While this is not yet decided as behavior we wish to support, and the relevant functions of
VaList
are currentlyunsafe
, it may be wise to consider embedding the ABI inVaList
to address these problems. The goal would be to have something equivalent toVaList<'_, extern "sysv64">
.@rustbot label: +F-c_variadic +T-lang +T-libs-api
The text was updated successfully, but these errors were encountered: