Incorrect for loop decompilation
See original GitHub issueCFR version
a913e06
Compiler
JDK 14, or what ever special compiler IntelliJ uses
Description
The code doesn’t produce the same result after decompilation:
public static void main(String[] args) {
int n = 15;
for (float i = 0; i < n; i++, i*= 2, System.out.println(i), i -= 2, i *= 1.2, i += 0.5) {
}
}
prints
2.0
3.0
5.4
11.16
24.984
Decompiled code:
public static void main(String[] args) {
int n = 15;
for (float i = 0.0f; i < (float)n; i -= 2.0f) {
i += 1.0f;
System.out.println(i *= 2.0f);
i = (float)((double)i * 1.2);
i = (float)((double)i + 0.5);
}
}
prints
2.0
3.8000002
8.120001
18.488003
Edit: Not an IDE bug
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
[core] incorrect decompilation for loops like while(++i < XX ... - GitHub
Describe error Hi. I have found several decompilation failures that the decompilation may silently change the semantics of the source code.
Read more >Incorrect decompilation for group assignment in |for| loop
The new behavior looks correct. The group assignment stays inside the loop now. Status: NEW → RESOLVED. Closed: 11 years ago. Resolution: ---...
Read more >Disable optimization of for loops in Hex Rays Decompiler
Are there any good ways of splitting up a very long for loop or if statement in IDA into larger chunks to make...
Read more >Bartosz Adamczewski on Twitter: "When we decompile this code we ...
When we decompile this code we see that it uses a single register to handle the entire loop and emits a bounds checking...
Read more >How does Reflector decompile code? - Stack Overflow
A common technique for implementing decompilation is to use something called "Interval Analysis" for identifying the extent of loops.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, it’s a decompiler issue. I can’t speak for the others, as CFR shares 0 heritage with them, but what’s happening for me is that the accounting on the -2 mutation is wrong, at a guess.
Good spot.
It’s the difference between the * and the - looking like (due to the double casts) they can be treated as mutations or not that does it. (slightly different accounting paths.)
Fun one, will try to get to that soonish.