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

corrected DAE, modify pom #1070

Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,12 @@
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
Binary file not shown.
26 changes: 26 additions & 0 deletions shared-test-resources/bugfixes/DeadAssignmentEliminatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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);
}

void tc2() {
String x = "abc";
x = "cde";
if (x.length() > 2) {
x = "3";
x = "if";
}
System.out.println(x);
}
}
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
16 changes: 4 additions & 12 deletions sootup.apk.frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
</properties>

<dependencies>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.core</artifactId>
</dependency>
<dependency>
<groupId>org.soot-oss</groupId>
<artifactId>sootup.java.core</artifactId>
Expand All @@ -43,17 +39,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<!-- mockito version 5 doesn't support java 8, it needs java 11 -->
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

import java.io.File;
import java.nio.file.Paths;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import sootup.apk.frontend.main.AndroidVersionInfo;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class AndroidVersionInfoTest {

@Mock private File mockJarsFile;
Expand All @@ -25,7 +25,7 @@ public class AndroidVersionInfoTest {

public AndroidVersionInfoTest() {}

@Before
@BeforeEach
public void setUp() {
// Setting up mocks
mockJarsFile = mock(File.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package sootup.apk.frontend;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import sootup.core.model.ClassModifier;
import sootup.core.model.SootClass;
import sootup.core.model.SootMethod;
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
8 changes: 0 additions & 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
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,64 @@ 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()));

final MethodSignature methodSignature1 =
view.getIdentifierFactory()
.getMethodSignature(
"DeadAssignmentEliminatorTest", "tc2", "void", Collections.emptyList());
Body body1 = view.getMethod(methodSignature1).get().getBody();
assertFalse(body1.getStmts().isEmpty());
assertEquals(
Stream.of(
"DeadAssignmentEliminatorTest this",
"unknown $stack2, $stack3",
"this := @this: DeadAssignmentEliminatorTest",
"l1 = \"cde\"",
"$stack2 = virtualinvoke l1.<java.lang.String: int length()>()",
"if $stack2 <= 2 goto label1",
"l1 = \"if\"",
"label1:",
"$stack3 = <java.lang.System: java.io.PrintStream out>",
"virtualinvoke $stack3.<java.io.PrintStream: void println(java.lang.String)>(l1)",
"return")
.collect(Collectors.toList()),
Utils.filterJimple(body1.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
Loading
Loading