-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Calls from C to Rust get miscompiled on Windows 64 #24427
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
Looks like there a slight misunderstanding about the calling convention between GCC and LLVM.
The IR generated by rustc looks correct... unless I am missing some implication of the
Hmm... LLVM codegen bug? |
You forgot to specify the calling convention for your Rust function, so it is using the rust call convention which is different from the C calling convention. |
No, looking at the |
Okay, I tested this locally, made sure the calling conventions match up, and yet I can still reproduce this issue. |
This also was fixed by #29012, btw. |
Yay! |
Rust code:
C code:
Expected output:
Actual output:
I couldn't reproduce it with larger number of smaller arguments (eg. passing ten u64s), couldn't reproduce it on 32 bits either. Changing debug/optimization options has no effect.
Works correctly when calling C from C (eg. using this code).
It originally manifested on another 64 bit machine, but I don't have access to it at the moment, though I can get its enviroment too.
LLVM IR: here
Assembly: here
Gcc version: 4.9.2 x86_64-pc-msys (verbose output)
Rust version:
Compiled and ran with
gcc main.c -c -o libcmain.a && rustc main.rs -l cmain -L. && main.exe
The text was updated successfully, but these errors were encountered: