Decompiler: Optimise do-while
inside if
with same condition to while-do
#8165
Labels
do-while
inside if
with same condition to while-do
#8165
Is your feature request related to a problem? Please describe.
Ghidra fails to recognise that a
do-while
loop depending on the same condition as the enclosing "proper"if
(i.e. it has noelse
clause), is actually awhile
loop.An example:
Describe the solution you'd like
Ghidra should recognise that the condition of the
if
anddo-while
are the same, and these should be combined into a singlewhile
loop.So the output should look like:
Describe alternatives you've considered
Keeping the decompiler output the way it is now, while correct, is unnecessarily verbose, and it is not clear at first sight that this is performing a
while
loop, especially when the loop body is long enough for thedo-while
condition to not be on the same screen as theif
statement.Additional context
The debug xml can be found inside this zip: ifdowhile.zip
From loading the xml in
decomp_dbg
:Even though the conditions of the
CBRANCH
ops in blocks 0 and 1 are not identical in the (optimised) p-code, (Block 0 checksr3(i)
, while Block 1 checksr31(0x00000034:46)
), both varnodes correspond to the same high variable (namelyparam_1
), so they are still equivalent in some sense.The text was updated successfully, but these errors were encountered: