-
Notifications
You must be signed in to change notification settings - Fork 13k
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
The improper_ctypes lint is very weak #36464
Comments
The enum should be caught, but the extern declarations should not, because code like following is entirely valid:
To explain, making functions be called using non-Rust calling convention does not invalidate passing rust data types back into Rust for functions implemented with non-Rust calling convention. |
|
@nagisa: I agree that your code is valid, but you typed Oddly, the actual x86_64 psABI does seem to think that arrays can be passed:
and I haven't found an example of Rust deviating from the psABI document, but I still suspect that almost (or maybe even exactly) 100% of cases where someone has actually attempted to pass an array into an |
|
Wow, somehow I assumed the default was the Rust calling convention.
|
@nagisa (I know I'm a bit late, what can you do) In your example, rustc actually will warn on the |
The
Will it? All types in the example are |
Ah I guess there is still the case with sized arrays. |
Did #66305 fix this case? Can it be closed now? |
The following code doesn't trigger #[repr(transparent)]
pub struct Array([u64; 2]);
#[no_mangle]
pub unsafe extern "C" fn function(arg: Array) -> Array {
arg
} Referred to in this issue |
I guess the question above is: do arrays and structs follow the same calling convention? If no, then |
I believe this the ctypes lint isn't working correctly on that transparent array input, yes. |
I have opened #116959 to cover the second case mentioned, because it is separate-ish. Closing. |
This code compiles without warnings. I think that the improper_ctypes lint should catch both of the extern declarations.
The array case (
foo
) is particularly nasty. On brief, insufficiently careful inspection, it looks like it matches:But it actually doesn't match that and instead seems to try to pass the array in packed form in
xmm0
on x86_64. This is extra nasty because I think I've caughtrust-bindgen
generating bindings like this.The text was updated successfully, but these errors were encountered: