From e57b2b798285853789e9a0d37d49441f873061e5 Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Sat, 19 Oct 2024 23:54:18 +0200 Subject: [PATCH 1/5] fix removeDefLocalsOf at many places --- .../DeadAssignmentEliminatorTest.class | Bin 731 -> 1190 bytes .../DeadAssignmentEliminatorTest.java | 10 ++++ .../java/sootup/core/jimple/basic/Local.java | 31 ++++++++++ .../src/main/java/sootup/core/model/Body.java | 10 +++- .../java/sootup/interceptors/Aggregator.java | 2 +- .../interceptors/CastAndReturnInliner.java | 2 +- .../interceptors/ConditionalBranchFolder.java | 2 +- .../DeadAssignmentEliminator.java | 4 +- .../java/sootup/interceptors/LocalPacker.java | 25 ++++---- .../UnreachableCodeEliminator.java | 2 +- .../DeadAssignmentEliminatorTest.java | 55 +++++++++++++++++- 11 files changed, 122 insertions(+), 21 deletions(-) diff --git a/shared-test-resources/bugfixes/DeadAssignmentEliminatorTest.class b/shared-test-resources/bugfixes/DeadAssignmentEliminatorTest.class index f9930c0f24066ceeeba279caadbe8d87a7e7903e..4c145afbb09307bb8c3a56eca19a50f590e20a32 100644 GIT binary patch delta 622 zcmZ9K&u-H|5XQf8oH`gI(Ex=)fl?qOg*reA1=1uXP^3x~MMdhNH)pkp5?s5i*Hv@M zL*&Gf3!HN)6$c)GSK!W5@NZT@B0`pSX21E(&Zm*TWj~y7zyA9C1waiiM(!CJl6(id+O@dY^ z$Hl}&4kZtZxJ@|Ok@}U2_odQ(LZP_X3l4&E7(|`&YpuG2s8cQdr?KSX0+u}ZC=;gS z+cXFh!nw)jtyWJ8T`lc8xJS4&@v0Q5>gxXbp^*E!8%HiGSa$Hh!$YhPrvIVMINk_l z5D}b%AWY>}n=n({o%F+qA=pp_k3Bp=mEg6;;*RMdWQxW_Z8%Rmc1DZJP}6dK6&5cU zutCUTiqAUVE^{P~*~L$w5hsKOpQdbbU~P;Jzf*%6!-BOk^ORKw^b@mWfaYHyv6dKk zZ(Sc4AP4$^vkor}c!oSbWu_(U!REM-spW6v3&$uP;ZE%%?3Z)z;M&Ky&p938QGLW6 z7Ea+b?s7DiF7g~;j&E03pXbU|Oye4V3osMU!~V@;#+k(`8zYB1-8F}|#QzZ2Ev)|m D^5Z=cfzSX0(%OA^mm$im%ZVQ;E%HLJ}CqX1Y0N1{5>Hc%IJR~(UAgOIDncg!&T qp getDefsForLocalUse(StmtGraph graph, Stmt stmt) { return defStmts; } + public List getLocalOccurrences(Collection stmts) { + List localOccurrences = new ArrayList<>(); + for (Stmt stmt : stmts) { + if (stmt instanceof AbstractDefinitionStmt) { + if (((AbstractDefinitionStmt) stmt).getLeftOp().equivTo(this)) { + localOccurrences.add(stmt); + } + ((AbstractDefinitionStmt) stmt) + .getUses() + .forEach( + use -> { + if (use instanceof Local && ((Local) use).equivTo(this)) { + localOccurrences.add(stmt); + } + }); + } else if (stmt instanceof JIfStmt) { + ((JIfStmt) stmt) + .getCondition() + .getUses() + .forEach( + value -> { + if (value instanceof Local && value.equivTo(this)) { + localOccurrences.add(stmt); + } + }); + } + } + return localOccurrences; + } + @Override public V accept(@Nonnull V v) { v.caseLocal(this); diff --git a/sootup.core/src/main/java/sootup/core/model/Body.java b/sootup.core/src/main/java/sootup/core/model/Body.java index 4cfc51f6565..a2eb3f3ef2f 100644 --- a/sootup.core/src/main/java/sootup/core/model/Body.java +++ b/sootup.core/src/main/java/sootup/core/model/Body.java @@ -459,12 +459,18 @@ public String toString() { } } - public void removeDefLocalsOf(@Nonnull Stmt stmt) { + public void removeDefLocalsOf(@Nonnull Stmt stmt, BodyBuilder builder) { stmt.getDef() .ifPresent( def -> { if (def instanceof Local) { - locals.remove(def); + List localOccurrences = + ((Local) def).getLocalOccurrences(builder.getStmts()); + // after removing stmt, if the local variable doesn't occur anywhere else then + // safely remove + if (localOccurrences.isEmpty()) { + locals.remove(def); + } } }); } diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/Aggregator.java b/sootup.interceptors/src/main/java/sootup/interceptors/Aggregator.java index aaa1cab3727..13c3d87f4ec 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/Aggregator.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/Aggregator.java @@ -235,7 +235,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) graph.setStartingStmt(newStartingStmt); } graph.removeNode(relevantDef); - builder.removeDefLocalsOf(relevantDef); + builder.removeDefLocalsOf(relevantDef, builder); } } } diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/CastAndReturnInliner.java b/sootup.interceptors/src/main/java/sootup/interceptors/CastAndReturnInliner.java index ba4d0672f37..c2da7ea7f6d 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/CastAndReturnInliner.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/CastAndReturnInliner.java @@ -120,7 +120,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) graph.removeNode(assign, false); if (graph.predecessors(retStmt).isEmpty()) { graph.removeNode(retStmt, false); - builder.removeDefLocalsOf(assign); + builder.removeDefLocalsOf(assign, builder); } } } diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/ConditionalBranchFolder.java b/sootup.interceptors/src/main/java/sootup/interceptors/ConditionalBranchFolder.java index e5fbe7b912a..ccf74e13ad0 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/ConditionalBranchFolder.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/ConditionalBranchFolder.java @@ -159,7 +159,7 @@ private void pruneExclusivelyReachableStmts( if (isExclusivelyReachable(stmtGraph, itStmt, reachedBranchingStmts)) { q.addAll(stmtGraph.successors(itStmt)); stmtGraph.removeNode(itStmt, false); - builder.removeDefLocalsOf(itStmt); + builder.removeDefLocalsOf(itStmt, builder); } } } diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/DeadAssignmentEliminator.java b/sootup.interceptors/src/main/java/sootup/interceptors/DeadAssignmentEliminator.java index a77a0df6bc8..5c68be652d6 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/DeadAssignmentEliminator.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/DeadAssignmentEliminator.java @@ -202,7 +202,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) if (!essentialStmts.contains(stmt)) { if (stmtGraph.containsNode(stmt)) { stmtGraph.removeNode(stmt); - builder.removeDefLocalsOf(stmt); + builder.removeDefLocalsOf(stmt, builder); } } } @@ -246,7 +246,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) Stmt newInvoke = Jimple.newInvokeStmt(assignStmt.getInvokeExpr().get(), assignStmt.getPositionInfo()); stmtGraph.replaceNode(assignStmt, newInvoke); - builder.removeDefLocalsOf(assignStmt); + builder.removeDefLocalsOf(assignStmt, builder); } } } diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/LocalPacker.java b/sootup.interceptors/src/main/java/sootup/interceptors/LocalPacker.java index 5112a61f983..c61d7049707 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/LocalPacker.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/LocalPacker.java @@ -92,6 +92,9 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) Value use = iterator.next(); if (use instanceof Local) { Local newLocal = localToNewLocal.get(use); + if (newLocal == null) { + continue; + } // assign a reasonable name if (!newLocals.contains(newLocal)) { int starPos = newLocal.getName().indexOf('*'); @@ -110,18 +113,20 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) if (defOpt.isPresent() && defOpt.get() instanceof Local) { Local def = (Local) defOpt.get(); Local newLocal = localToNewLocal.get(def); - // assign a reasonable name - if (!newLocals.contains(newLocal)) { - int starPos = newLocal.getName().indexOf('*'); - String reasonableName = newLocal.getName().substring(0, starPos) + newLocals.size(); - List oriLocals = newLocalToLocals.get(newLocal); - newLocal = newLocal.withName(reasonableName); - newLocals.add(newLocal); - for (Local ori : oriLocals) { - localToNewLocal.put(ori, newLocal); + if (newLocal != null) { + // assign a reasonable name + if (!newLocals.contains(newLocal)) { + int starPos = newLocal.getName().indexOf('*'); + String reasonableName = newLocal.getName().substring(0, starPos) + newLocals.size(); + List oriLocals = newLocalToLocals.get(newLocal); + newLocal = newLocal.withName(reasonableName); + newLocals.add(newLocal); + for (Local ori : oriLocals) { + localToNewLocal.put(ori, newLocal); + } } + newStmt = ((AbstractDefinitionStmt) newStmt).withNewDef(newLocal); } - newStmt = ((AbstractDefinitionStmt) newStmt).withNewDef(newLocal); } if (!stmt.equals(newStmt)) { stmtGraph.replaceNode(stmt, newStmt); diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/UnreachableCodeEliminator.java b/sootup.interceptors/src/main/java/sootup/interceptors/UnreachableCodeEliminator.java index 0dd52a6d474..6424abb37af 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/UnreachableCodeEliminator.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/UnreachableCodeEliminator.java @@ -72,7 +72,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) for (Stmt stmt : removeQ) { graph.removeNode(stmt, false); - builder.removeDefLocalsOf(stmt); + builder.removeDefLocalsOf(stmt, builder); } } } diff --git a/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java b/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java index 00e16ed1fed..c53aa8ad5c9 100644 --- a/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java +++ b/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java @@ -1,8 +1,5 @@ package sootup.java.bytecode.frontend.interceptors; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; @@ -27,12 +24,15 @@ import sootup.core.types.PrimitiveType; import sootup.core.util.Utils; import sootup.interceptors.DeadAssignmentEliminator; +import sootup.interceptors.LocalPacker; import sootup.java.bytecode.frontend.inputlocation.PathBasedAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.language.JavaJimple; import sootup.java.core.types.JavaClassType; import sootup.java.core.views.JavaView; +import static org.junit.jupiter.api.Assertions.*; + @Tag("Java8") public class DeadAssignmentEliminatorTest { @@ -229,4 +229,53 @@ public void testDeadAssignmentEliminator() { .collect(Collectors.toList()), Utils.filterJimple(body1.toString())); } + + @Test + public void testLocalCountAfterDAE() { + AnalysisInputLocation inputLocation = + new PathBasedAnalysisInputLocation.ClassFileBasedAnalysisInputLocation( + classFilePath, + "", + SourceType.Application, + Arrays.asList(new DeadAssignmentEliminator(), new LocalPacker())); + JavaView view = new JavaView(Collections.singletonList(inputLocation)); + final MethodSignature methodSignature = + view.getIdentifierFactory() + .getMethodSignature( + "DeadAssignmentEliminatorTest", + "tc3", + "void", + Collections.singletonList(PrimitiveType.getInt().getName())); + + Body body = view.getMethod(methodSignature).get().getBody(); + assertTrue(body.getLocals().size() == 5); + assertFalse(body.getStmts().isEmpty()); + assertEquals( + Stream.of( + "DeadAssignmentEliminatorTest this0", + "int l1", + "unknown $stack2, l3, l4", + "this0 := @this: DeadAssignmentEliminatorTest", + "l1 := @parameter0: int", + "label1:", + "$stack2 = \"true\"", + "l3 = staticinvoke (\"com.fasterxml.jackson.core.util.BufferRecyclers.trackReusableBuffers\")", + "l4 = virtualinvoke $stack2.(l3)", + "label2:", + "goto label4", + "label3:", + "l3 := @caughtexception", + "label4:", + "if l4 == 0 goto label5", + "l3 = staticinvoke (1)", + "goto label6", + "label5:", + "l3 = null", + "label6:", + "l3 = virtualinvoke l3.()", + "return", + "catch java.lang.SecurityException from label1 to label2 with label3") + .collect(Collectors.toList()), + Utils.filterJimple(body.toString())); + } } From 804c8ad51436c4cd5ad1a3cfe5edc17b6aa5e499 Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Sun, 20 Oct 2024 00:08:49 +0200 Subject: [PATCH 2/5] fix style --- .../frontend/interceptors/DeadAssignmentEliminatorTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java b/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java index c53aa8ad5c9..9740480a85c 100644 --- a/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java +++ b/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java @@ -1,5 +1,7 @@ package sootup.java.bytecode.frontend.interceptors; +import static org.junit.jupiter.api.Assertions.*; + import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; @@ -31,8 +33,6 @@ import sootup.java.core.types.JavaClassType; import sootup.java.core.views.JavaView; -import static org.junit.jupiter.api.Assertions.*; - @Tag("Java8") public class DeadAssignmentEliminatorTest { From 50ec855d9644cc86e162548eee20c46122816cf2 Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Sun, 20 Oct 2024 00:22:24 +0200 Subject: [PATCH 3/5] fix dae test locals --- .../frontend/interceptors/DeadAssignmentEliminatorTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java b/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java index 9740480a85c..e7820f412a1 100644 --- a/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java +++ b/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/DeadAssignmentEliminatorTest.java @@ -189,7 +189,7 @@ public void testDeadAssignmentEliminator() { assertEquals( Stream.of( "DeadAssignmentEliminatorTest this", - "unknown $stack3, $stack4, $stack5", + "unknown $stack3, $stack4, $stack5, l1, l2", "this := @this: DeadAssignmentEliminatorTest", "l1 = 30", "l2 = l1", @@ -216,7 +216,7 @@ public void testDeadAssignmentEliminator() { assertEquals( Stream.of( "DeadAssignmentEliminatorTest this", - "unknown $stack2, $stack3", + "unknown $stack2, $stack3, l1", "this := @this: DeadAssignmentEliminatorTest", "l1 = \"cde\"", "$stack2 = virtualinvoke l1.()", From f756e5c61e7f7311ba9199d27f272cdac8715505 Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Thu, 24 Oct 2024 15:18:11 +0200 Subject: [PATCH 4/5] updated changes --- .../java/sootup/core/jimple/basic/Local.java | 28 ++++--------------- .../src/main/java/sootup/core/model/Body.java | 4 +-- .../java/sootup/interceptors/Aggregator.java | 2 +- .../interceptors/CastAndReturnInliner.java | 2 +- .../interceptors/ConditionalBranchFolder.java | 2 +- .../DeadAssignmentEliminator.java | 4 +-- .../UnreachableCodeEliminator.java | 2 +- 7 files changed, 14 insertions(+), 30 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/jimple/basic/Local.java b/sootup.core/src/main/java/sootup/core/jimple/basic/Local.java index a6e85b4738f..f35f9380d38 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/basic/Local.java +++ b/sootup.core/src/main/java/sootup/core/jimple/basic/Local.java @@ -23,12 +23,12 @@ */ import java.util.*; +import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nonnull; import sootup.core.graph.StmtGraph; import sootup.core.jimple.Jimple; import sootup.core.jimple.common.stmt.AbstractDefinitionStmt; -import sootup.core.jimple.common.stmt.JIfStmt; import sootup.core.jimple.common.stmt.Stmt; import sootup.core.jimple.visitor.Acceptor; import sootup.core.jimple.visitor.ImmediateVisitor; @@ -154,31 +154,15 @@ public List getDefsForLocalUse(StmtGraph graph, Stmt stmt) { return defStmts; } - public List getLocalOccurrences(Collection stmts) { + public List getStmtsUsingthisLocal(Collection stmts, Stmt removedStmt) { List localOccurrences = new ArrayList<>(); for (Stmt stmt : stmts) { - if (stmt instanceof AbstractDefinitionStmt) { - if (((AbstractDefinitionStmt) stmt).getLeftOp().equivTo(this)) { + if (stmt.equivTo(removedStmt)) continue; + List stmtUses = stmt.getUsesAndDefs().collect(Collectors.toList()); + for (Value stmtUse : stmtUses) { + if (stmtUse instanceof Local && stmtUse.equivTo(this)) { localOccurrences.add(stmt); } - ((AbstractDefinitionStmt) stmt) - .getUses() - .forEach( - use -> { - if (use instanceof Local && ((Local) use).equivTo(this)) { - localOccurrences.add(stmt); - } - }); - } else if (stmt instanceof JIfStmt) { - ((JIfStmt) stmt) - .getCondition() - .getUses() - .forEach( - value -> { - if (value instanceof Local && value.equivTo(this)) { - localOccurrences.add(stmt); - } - }); } } return localOccurrences; diff --git a/sootup.core/src/main/java/sootup/core/model/Body.java b/sootup.core/src/main/java/sootup/core/model/Body.java index a2eb3f3ef2f..681cb001517 100644 --- a/sootup.core/src/main/java/sootup/core/model/Body.java +++ b/sootup.core/src/main/java/sootup/core/model/Body.java @@ -459,13 +459,13 @@ public String toString() { } } - public void removeDefLocalsOf(@Nonnull Stmt stmt, BodyBuilder builder) { + public void removeDefLocalsOf(@Nonnull Stmt stmt) { stmt.getDef() .ifPresent( def -> { if (def instanceof Local) { List localOccurrences = - ((Local) def).getLocalOccurrences(builder.getStmts()); + ((Local) def).getStmtsUsingthisLocal(this.graph.getStmts(), stmt); // after removing stmt, if the local variable doesn't occur anywhere else then // safely remove if (localOccurrences.isEmpty()) { diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/Aggregator.java b/sootup.interceptors/src/main/java/sootup/interceptors/Aggregator.java index 13c3d87f4ec..aaa1cab3727 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/Aggregator.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/Aggregator.java @@ -235,7 +235,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) graph.setStartingStmt(newStartingStmt); } graph.removeNode(relevantDef); - builder.removeDefLocalsOf(relevantDef, builder); + builder.removeDefLocalsOf(relevantDef); } } } diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/CastAndReturnInliner.java b/sootup.interceptors/src/main/java/sootup/interceptors/CastAndReturnInliner.java index c2da7ea7f6d..ba4d0672f37 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/CastAndReturnInliner.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/CastAndReturnInliner.java @@ -120,7 +120,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) graph.removeNode(assign, false); if (graph.predecessors(retStmt).isEmpty()) { graph.removeNode(retStmt, false); - builder.removeDefLocalsOf(assign, builder); + builder.removeDefLocalsOf(assign); } } } diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/ConditionalBranchFolder.java b/sootup.interceptors/src/main/java/sootup/interceptors/ConditionalBranchFolder.java index ccf74e13ad0..e5fbe7b912a 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/ConditionalBranchFolder.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/ConditionalBranchFolder.java @@ -159,7 +159,7 @@ private void pruneExclusivelyReachableStmts( if (isExclusivelyReachable(stmtGraph, itStmt, reachedBranchingStmts)) { q.addAll(stmtGraph.successors(itStmt)); stmtGraph.removeNode(itStmt, false); - builder.removeDefLocalsOf(itStmt, builder); + builder.removeDefLocalsOf(itStmt); } } } diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/DeadAssignmentEliminator.java b/sootup.interceptors/src/main/java/sootup/interceptors/DeadAssignmentEliminator.java index 5c68be652d6..a77a0df6bc8 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/DeadAssignmentEliminator.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/DeadAssignmentEliminator.java @@ -202,7 +202,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) if (!essentialStmts.contains(stmt)) { if (stmtGraph.containsNode(stmt)) { stmtGraph.removeNode(stmt); - builder.removeDefLocalsOf(stmt, builder); + builder.removeDefLocalsOf(stmt); } } } @@ -246,7 +246,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) Stmt newInvoke = Jimple.newInvokeStmt(assignStmt.getInvokeExpr().get(), assignStmt.getPositionInfo()); stmtGraph.replaceNode(assignStmt, newInvoke); - builder.removeDefLocalsOf(assignStmt, builder); + builder.removeDefLocalsOf(assignStmt); } } } diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/UnreachableCodeEliminator.java b/sootup.interceptors/src/main/java/sootup/interceptors/UnreachableCodeEliminator.java index 6424abb37af..0dd52a6d474 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/UnreachableCodeEliminator.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/UnreachableCodeEliminator.java @@ -72,7 +72,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) for (Stmt stmt : removeQ) { graph.removeNode(stmt, false); - builder.removeDefLocalsOf(stmt, builder); + builder.removeDefLocalsOf(stmt); } } } From 8a4b9ef5167707b4173a89b8e36c5d36d13cf62d Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Wed, 30 Oct 2024 11:45:52 +0100 Subject: [PATCH 5/5] renamed variables --- .../src/main/java/sootup/core/jimple/basic/Local.java | 6 +++--- sootup.core/src/main/java/sootup/core/model/Body.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/jimple/basic/Local.java b/sootup.core/src/main/java/sootup/core/jimple/basic/Local.java index f35f9380d38..f6f5a93f8d6 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/basic/Local.java +++ b/sootup.core/src/main/java/sootup/core/jimple/basic/Local.java @@ -154,12 +154,12 @@ public List getDefsForLocalUse(StmtGraph graph, Stmt stmt) { return defStmts; } - public List getStmtsUsingthisLocal(Collection stmts, Stmt removedStmt) { + public List getStmtsUsingOrDefiningthisLocal(Collection stmts, Stmt removedStmt) { List localOccurrences = new ArrayList<>(); for (Stmt stmt : stmts) { if (stmt.equivTo(removedStmt)) continue; - List stmtUses = stmt.getUsesAndDefs().collect(Collectors.toList()); - for (Value stmtUse : stmtUses) { + List stmtUsesAndDefs = stmt.getUsesAndDefs().collect(Collectors.toList()); + for (Value stmtUse : stmtUsesAndDefs) { if (stmtUse instanceof Local && stmtUse.equivTo(this)) { localOccurrences.add(stmt); } diff --git a/sootup.core/src/main/java/sootup/core/model/Body.java b/sootup.core/src/main/java/sootup/core/model/Body.java index 681cb001517..7e8606a9088 100644 --- a/sootup.core/src/main/java/sootup/core/model/Body.java +++ b/sootup.core/src/main/java/sootup/core/model/Body.java @@ -465,7 +465,7 @@ public void removeDefLocalsOf(@Nonnull Stmt stmt) { def -> { if (def instanceof Local) { List localOccurrences = - ((Local) def).getStmtsUsingthisLocal(this.graph.getStmts(), stmt); + ((Local) def).getStmtsUsingOrDefiningthisLocal(this.graph.getStmts(), stmt); // after removing stmt, if the local variable doesn't occur anywhere else then // safely remove if (localOccurrences.isEmpty()) {