-
Notifications
You must be signed in to change notification settings - Fork 348
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
Miri doesn't understand C-variadic functions #1892
Comments
Yeah, Miri probably does not support varargs at all currently. I assume this is another thing that is blocked on rust-lang/rust#56166. If you could provide a self-contained example demonstrating the problem, that would be helpful as a testcase. :) |
Sure thing. #![feature(c_variadic)]
use std::os::raw::c_char;
macro_rules! c_str {
($lit:expr) => {
concat!($lit, "\0").as_ptr() as *const c_char
};
}
#[allow(unused_unsafe)]
pub unsafe extern "C" fn variadic_fn(_: *const c_char, mut _args: ...) {
todo!()
}
fn main() {
unsafe {
variadic_fn(c_str!("c string"), 1, 2, 3);
}
} |
FWIW, rust-lang/rust#91342 should help with this. But actually implementing |
To be clear, I don't currently have plans to work on those platform-specific parts -- it will be a lot of work for very little gain, as such Rust-to-Rust calls of c-variadic functions are exceedingly rare, to my knowledge. An alternative for your usecase might be to use |
No worries, no worries, as a workaround I banished 99% of my C code (so I could also remove the C-variadic workaround for my tests), so this isn't important to me any more :) (I guess I should have said this earlier? Sorry 😳) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Could Miri report this as an unsupported operation, not UB? Would that close this issue? |
It does: However, the issue you reported is separately detected before and considered UB: Possibly we should remove that particular check. For our FFI implementation we ended up saying that we don't want to make a difference between variadic and non-variadic arguments, so this would make us more consistent. (But to my knowledge, at least on Apple's aarch64 targets, that is actually unsound.)
No, what would close this issue is actually getting the testcase to pass. |
Indeed. Variadic arguments are always passed on the stack even if the same argument would end up in a register for a non-variadic function. |
I have a program written in C and Rust. This program has a function that is variadic and written in C. To enable testing my Rust code, I needed to mock this function using the
#[feature(c_variadic)]
unstable feature.This means I have not a function in my test code defined like the following:
When running Miri on my test code, I'm greeted with the following error:
error: Undefined Behavior: calling a function with argument of type std::ffi::VaListImpl passing data of type *const i8
The text was updated successfully, but these errors were encountered: