Skip to content

Commit

Permalink
fix: use correct order in removeUnreachableBlocks (PR #2085)
Browse files Browse the repository at this point in the history
* Fixing wrong order in removeUnreachableBlocks
* Removing dead code in TestTernary4 test
* Do not clear instructions in detach blocks method
  • Loading branch information
Away-pp authored Jan 21, 2024
1 parent 61be1d8 commit a19aec9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,14 @@ private static void removeUnreachableBlocks(MethodNode mth) {
return;
}

toRemove.forEach(BlockSplitter::detachBlock);
mth.getBasicBlocks().removeAll(toRemove);
long notEmptyBlocks = toRemove.stream().filter(block -> !block.getInstructions().isEmpty()).count();
if (notEmptyBlocks != 0) {
int insnsCount = toRemove.stream().mapToInt(block -> block.getInstructions().size()).sum();
mth.addWarnComment("Unreachable blocks removed: " + notEmptyBlocks + ", instructions: " + insnsCount);
}

toRemove.forEach(BlockSplitter::detachBlock);
mth.getBasicBlocks().removeAll(toRemove);
}

private static void clearBlocksState(MethodNode mth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ static void detachBlock(BlockNode block) {
successor.getPredecessors().remove(block);
}
block.add(AFlag.REMOVE);
block.getInstructions().clear();
block.getPredecessors().clear();
block.getSuccessors().clear();
}
Expand Down
2 changes: 0 additions & 2 deletions jadx-core/src/test/smali/conditions/TestTernary4.smali
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@
.catchall {:try_start_14 .. :try_end_50} :catchall_4e

throw p1

return-void
.end method

.method private getValueObject(Ljava/lang/String;)Ljava/lang/Object;
Expand Down

0 comments on commit a19aec9

Please sign in to comment.