-
-
Notifications
You must be signed in to change notification settings - Fork 655
fix Issue 21515 extern(C) and extern(C++) returns creal in wrong order #12073
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
Conversation
Thanks for your pull request, @ibuclaw! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#12073" |
I am not capable of understanding whether the fix is correct, however, you should include the test so that we see whether it passes or not. |
It doesn't when it's implemented in D. I say this in my original post. ;-) |
Whatever it is fixing, it should have a test to not let reviewers guess what is the problem that is being fixed. As I understand, this PR is fixing the code generation for the first example that you are providing. If that is the case, then please, include the test. |
I don't consider it to be fixing anything at all, because it occurs at a place that affects every read of a complex number. There has to be a better place to tell the dmd backend to read a complex number backwards when it is returned from a function. This is why @WalterBright should have a look to see if the hint sparks any suggestions. |
Looks ok to me. Add the test! |
Isn't there any way to swap the re/im values earlier in codegen? It only needs to be done for
|
According to SYS V ABI for AMD64:
And if I understand
|
Inserting |
897668f
to
2732d81
Compare
12a25b4
to
c7c3fc0
Compare
@WalterBright added |
bfafe96
to
e33df3e
Compare
Not strictly block #12069, but this bug came up when I was testing complex number passing. |
@WalterBright OK? I've added more tests than strictly necessary, but wanted to be paranoid about changing the ABI for anything other than what is being targetted. |
In loadComplex and complex_eq87, the real part of x87 complex numbers are pushed to the FPU register stack first (ST1), then the imaginary part (ST0). However, on the I64 ABI, real part is instead returned in ST0 and the imaginary part in ST1. To handle this, FXCH is inserted before returning from, and after calling a complex long double function.
72 hours have pass. |
@WalterBright this works when the
extern(C)
orextern(C++)
function is external.i.e:
But fails when the function is implemented in D.
Is this enough of a hint to do the fix proper?