Skip to content

Commit

Permalink
corrected DAE, modify pom
Browse files Browse the repository at this point in the history
  • Loading branch information
sahilagichani14 committed Sep 13, 2024
1 parent 23cd80b commit d23c92f
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 72 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.13</version>
<version>${slf4j-simple.version}</version>
<scope>test</scope>
</dependency>
<!-- adds `@Nullable` and `@Nonnull` annotations -->
Expand Down
Binary file not shown.
16 changes: 16 additions & 0 deletions shared-test-resources/bugfixes/DeadAssignmentEliminatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class DeadAssignmentEliminatorTest {
void tc1() {
int x = 10;
x = 30;
int temp = x;
if (temp > 5) {
x = 40;
System.out.println(x);
temp = temp;
}
System.out.println(x);
x = 20;
temp = 30;
System.out.println(temp);
}
}
5 changes: 0 additions & 5 deletions sootup.analysis.intraprocedural/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.bytecode.frontend</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.sourcecode.frontend</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions sootup.apk.frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@
</properties>

<dependencies>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
<version>1.3.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
<version>1.3.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.smali</groupId>
Expand Down
6 changes: 1 addition & 5 deletions sootup.codepropertygraph/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
<dependencies>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
<artifactId>sootup.analysis.interprocedural</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
Expand Down
8 changes: 0 additions & 8 deletions sootup.examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
<groupId>org.soot-oss</groupId>
<artifactId>sootup.callgraph</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.bytecode.frontend</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions sootup.interceptors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.analysis.intraprocedural</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
*/

import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import sootup.analysis.intraprocedural.reachingdefs.ReachingDefs;
import sootup.core.graph.MutableStmtGraph;
import sootup.core.jimple.Jimple;
import sootup.core.jimple.basic.LValue;
Expand Down Expand Up @@ -63,6 +65,7 @@ public DeadAssignmentEliminator(boolean eliminateOnlyStackLocals) {
@Override
public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) {
MutableStmtGraph stmtGraph = builder.getStmtGraph();
Map<Stmt, List<Stmt>> reachingDefs = (new ReachingDefs(stmtGraph)).getReachingDefs();
// refactor.. why already here - getNodes as well
List<Stmt> stmts = builder.getStmts();
Deque<Stmt> deque = new ArrayDeque<>(stmts.size());
Expand All @@ -84,7 +87,6 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view)

// Stmt is of the form a = a which is useless
if (lhs == rhs && lhs instanceof Local) {
iterator.remove();
continue;
}

Expand Down Expand Up @@ -185,6 +187,8 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view)
if (value instanceof Local) {
Local local = (Local) value;
Collection<Stmt> defs = allDefs.get(local);
List<Stmt> reachableDefs = reachingDefs.get(stmt);
defs = defs.stream().filter(reachableDefs::contains).collect(Collectors.toList());
if (defs != null) {
deque.addAll(defs);
}
Expand Down
9 changes: 1 addition & 8 deletions sootup.java.bytecode.frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
</parent>

<dependencies>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.interceptors</artifactId>
Expand Down Expand Up @@ -61,6 +53,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
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.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import sootup.core.graph.MutableStmtGraph;
import sootup.core.graph.StmtGraph;
import sootup.core.inputlocation.AnalysisInputLocation;
import sootup.core.jimple.basic.Local;
import sootup.core.jimple.basic.NoPositionInformation;
import sootup.core.jimple.basic.StmtPositionInfo;
Expand All @@ -16,8 +22,12 @@
import sootup.core.jimple.common.stmt.JIfStmt;
import sootup.core.jimple.common.stmt.Stmt;
import sootup.core.model.Body;
import sootup.core.model.SourceType;
import sootup.core.signatures.MethodSignature;
import sootup.core.types.PrimitiveType;
import sootup.core.util.Utils;
import sootup.interceptors.DeadAssignmentEliminator;
import sootup.java.bytecode.frontend.inputlocation.PathBasedAnalysisInputLocation;
import sootup.java.core.JavaIdentifierFactory;
import sootup.java.core.language.JavaJimple;
import sootup.java.core.types.JavaClassType;
Expand All @@ -26,6 +36,9 @@
@Tag("Java8")
public class DeadAssignmentEliminatorTest {

Path classFilePath =
Paths.get("../shared-test-resources/bugfixes/DeadAssignmentEliminatorTest.class");

/**
*
*
Expand Down Expand Up @@ -156,4 +169,42 @@ private static Body.BodyBuilder createBody(boolean essentialOption) {

return builder;
}

@Test
public void testDeadAssignmentEliminator() {
AnalysisInputLocation inputLocation =
new PathBasedAnalysisInputLocation.ClassFileBasedAnalysisInputLocation(
classFilePath,
"",
SourceType.Application,
Collections.singletonList(new DeadAssignmentEliminator()));
JavaView view = new JavaView(Collections.singletonList(inputLocation));

final MethodSignature methodSignature =
view.getIdentifierFactory()
.getMethodSignature(
"DeadAssignmentEliminatorTest", "tc1", "void", Collections.emptyList());
Body body = view.getMethod(methodSignature).get().getBody();
assertFalse(body.getStmts().isEmpty());
assertEquals(
Stream.of(
"DeadAssignmentEliminatorTest this",
"unknown $stack3, $stack4, $stack5",
"this := @this: DeadAssignmentEliminatorTest",
"l1 = 30",
"l2 = l1",
"if l2 <= 5 goto label1",
"l1 = 40",
"$stack5 = <java.lang.System: java.io.PrintStream out>",
"virtualinvoke $stack5.<java.io.PrintStream: void println(int)>(l1)",
"label1:",
"$stack3 = <java.lang.System: java.io.PrintStream out>",
"virtualinvoke $stack3.<java.io.PrintStream: void println(int)>(l1)",
"l2 = 30",
"$stack4 = <java.lang.System: java.io.PrintStream out>",
"virtualinvoke $stack4.<java.io.PrintStream: void println(int)>(l2)",
"return")
.collect(Collectors.toList()),
Utils.filterJimple(body.toString()));
}
}
4 changes: 0 additions & 4 deletions sootup.java.sourcecode.frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
Expand Down
10 changes: 0 additions & 10 deletions sootup.jimple.frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@
</build>

<dependencies>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
</dependency>

<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.sourcecode.frontend</artifactId>
</dependency>

<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
Expand Down
8 changes: 0 additions & 8 deletions sootup.qilin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
</parent>

<dependencies>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.bytecode.frontend</artifactId>
Expand Down
19 changes: 3 additions & 16 deletions sootup.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,20 @@
</parent>

<dependencies>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.interceptors</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.bytecode.frontend</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.sourcecode.frontend</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.jimple.frontend</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.callgraph</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down

0 comments on commit d23c92f

Please sign in to comment.