-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Missoptimization of functions with C calling convention #33868
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Which target is this for? There are multiple calling conventions across operating systems and architectures after all. |
This is on x86_64-unknown-linux-gnu. |
I can confirm this for |
Works on stable. |
cc @eddyb could it be your call trans refactor? |
Seems like we invoke some UB: ; Function Attrs: noinline norecurse nounwind readnone uwtable
define i32 @test({ i64, i64 }) unnamed_addr #0 {
entry-block:
ret i32 undef
} is what the function ends up being optimised to. |
This is what I managed to reduce the issue to. |
This suffices: #[no_mangle]
pub extern "C" fn test(s: S) -> u32 {
s.c
} Bad IR:
|
The old, working functionality uses a shim:
|
We are storing 16 bytes of data in a 12-byte bag and that is killing us. |
For the reference, |
|
Ah, this is the problem @dotdash was aware of, isn't it? EDIT: That was actually more about calls, rather than definitions, and I can't get calls to misbehave (we do the same thing there that the old code does AFAICT). One thing that we might need to look into is MIR trans not doing a cast returned value |
The core team discussed this issue today and our conclusions were as follows:
|
When trying to look at how aggregates are passed to functions I came across the following:
The code presented below erroneously outputs
488447261
instead of20
.This is using the 1.9.0 preview release (or anything newer) and seems to be a regression from 1.8.0.
The behaviour only occurs when using the C calling conventions and optimizations, eliminating either factor gives the correct result.
The text was updated successfully, but these errors were encountered: