Skip to content
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

Fix handling of Annotations in Dex code & UnconditionalBranchFolder #2068

Merged
merged 6 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix UnconditionalBranchFolder breaking code
When a goto referenced a goto, which was touched by the condition inversion of
UnconditionalBranchFolder, that goto would not be updated.
Therefore, the other references to the goto point to the wrong effects of the
wrong if branch after the optimization.
  • Loading branch information
MarcMil committed Apr 16, 2024
commit 1e72bfc4952c9f21d5c091aa1aec11e719d3d505
12 changes: 12 additions & 0 deletions src/main/java/soot/jimple/BranchableStmt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package soot.jimple;

import soot.Unit;
import soot.UnitBox;

public interface BranchableStmt extends Stmt {
public Unit getTarget();

public void setTarget(Unit target);

public UnitBox getTargetBox();
}
2 changes: 1 addition & 1 deletion src/main/java/soot/jimple/GotoStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import soot.Unit;
import soot.UnitBox;

public interface GotoStmt extends Stmt {
public interface GotoStmt extends BranchableStmt {
public Unit getTarget();

public void setTarget(Unit target);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/soot/jimple/internal/JIfStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import soot.baf.Baf;
import soot.jimple.AbstractJimpleValueSwitch;
import soot.jimple.BinopExpr;
import soot.jimple.BranchableStmt;
import soot.jimple.ConvertToBaf;
import soot.jimple.EqExpr;
import soot.jimple.GeExpr;
Expand All @@ -50,7 +51,7 @@
import soot.jimple.StmtSwitch;
import soot.util.Switch;

public class JIfStmt extends AbstractStmt implements IfStmt {
public class JIfStmt extends AbstractStmt implements IfStmt, BranchableStmt {

protected final ValueBox conditionBox;
protected final UnitBox targetBox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import soot.Unit;
import soot.UnitBox;
import soot.Value;
import soot.jimple.BranchableStmt;
import soot.jimple.ConditionExpr;
import soot.jimple.GotoStmt;
import soot.jimple.IfStmt;
Expand Down Expand Up @@ -213,6 +214,37 @@ public Result transform() {
succAsGoto.setTarget(ifTarget);
stmtAsIfStmt.setTarget(gotoTarget);
ifTarget = gotoTarget;
// We need to check whether anyone has a goto to the "goto X", because this no has to also go
// to Y

// If we wouldn't do that, we would e.g. go from
// if $i0 == 6 goto label04;
// label03:
// goto label21;
// ...
// goto label3;

// to
// if $i0 != 6 goto label21;
// label03:
// goto label04;
// label04:
// ...
// goto label03;
// this would alter the semantics, since the previous go-tos now go to the other branch!
if (!succAsGoto.getBoxesPointingToThis().isEmpty()) {
// we cannot simply use getBoxesPointingToThis, because we do not want to update
// trap references
for (Unit i : units) {
if (i instanceof BranchableStmt) {
BranchableStmt b = (BranchableStmt) i;
if (b.getTarget() == succAsGoto) {
b.setTarget(gotoTarget);
}
}
}
}

// NOTE: No need to remove the goto [successor] because it
// is processed by the next iteration of the main loop.
// NOTE: Nothing is removed here, it is a simple refactoring.
Expand Down
Loading