Skip to content

fix: copy a short return tail reached from a loop body and from before the loop - #3026

Open
HuzaifaChaudary wants to merge 1 commit into
skylot:masterfrom
HuzaifaChaudary:fix/loop-exit-to-shared-return
Open

HuzaifaChaudary wants to merge 1 commit into
skylot:masterfrom
HuzaifaChaudary:fix/loop-exit-to-shared-return

Conversation

@HuzaifaChaudary

Copy link
Copy Markdown
Contributor

Description

fixes #2781 . the method from the issue decompiled to code that keeps looping after str = "pass" and returns false , where the real method logs and returns true .

the loop body jumps to log(...); return true; , and the same two instructions are also reached from the else branch before the loop . the loop's normal exit goes to return false , so a break can't reach that tail , and the jump was dropped . splitReturn would copy the return for each predecessor , but the return sits in its own block after the log call , so the block with two predecessors isn't the return block .

this adds splitLoopExitTail next to splitReturn : if a return is preceded by a short straight tail (up to 4 instructions) that is reached both from a loop body exit and from outside the loop , the tail is copied for the loop side . it only fires when the tail is not the loop's normal exit , so a compound loop condition or a plain break keeps its current output . the issue method now comes out as

if (string.equals("abc")) {
    log("TAG", "pass");
    return true;
}

the new smali test is the issue's method with the android types swapped for java.lang ones , and it fails without the change . jadx-core tests : 1034 passed , 0 failed .

i also decompiled a 20 MB apk (the sample from #2892) with and without the change . nothing changed apart from throws clauses that already differ between two runs of the unchanged build , MethodThrowsVisitor hits a ConcurrentModificationException there with -j 8 .

spotlessCheck could not fetch its eclipse formatter here , so the formatting is checked by hand against the file .

Copilot AI balanced review requested due to automatic review settings October 22, 2026 00:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[core] Decompilation doesn't follow goto out of loop

2 participants