-
Notifications
You must be signed in to change notification settings - Fork 958
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
Code with FDIVR decompiled wrong #293
Comments
for maybe later use. It was found that retdec decompiles the code containing FDIVR opcode the wrong way around... See avast/retdec#293.
I can confirm this is a bug. Operands are in an incorrect order at least in the following case:
I don't want to hotfix just this problem, because this might be an issue all across x86 FPU instructions. The thing is that in LLVM IR generation, operands are reversed as one would expect, but the output is still wrong: // X86_INS_FDIV
auto* fdiv = irb.CreateFDiv(op0, op1);
// X86_INS_FDIVR
auto* fdiv = irb.CreateFDiv(op1, op0); It may have something to do with an order of operands as get by Thanks for the report, this is potentially a major issue, I will do my best to properly fix it as soon as possible. |
This is a template how all other generation routines should be fixed and how unit tests should look like.
The current output looks different than the lines you posted, but I think these are the relevant lines: Before fix: *(float64_t *)(a1 + 24) = (float64_t)((float80_t)(v33 - 1) / v3); After fix: *(float64_t *)(a1 + 24) = (float64_t)(v3 / (float80_t)(v34 - 1)); As expected, there were problems with many instructions other than |
Hello,
it looks that code containing FDIVR is decompiled the same as FDIV, which lead to wrong results.
IDA shows me the following code:
Which is decompiled to something like this:
Correct would be something like this:
*v26 = v6 / (v30- 1.0); // pattern 'b/(a-1)'
Itt looks like the opcode FDIVR is decompiled like opcode FDIV.
Decompiled Function is here https://github.com/DennisD2/tomorrow/blob/master/src/morrow/orig/mtcsa32.dll.c, function_10001718(). Original DLL here: https://github.com/DennisD2/tomorrow/blob/master/src/morrow/orig/lib/Mtcsa32.dll .
The text was updated successfully, but these errors were encountered: