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 and implement ConditionalBranchFolder, Unreachable Code Eliminator #1041

Draft
wants to merge 20 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9f9400a
fix ConditionalBranchFolder, forloop jimple order changed, fix try ca…
sahilagichani14 Aug 25, 2024
f3141e3
better approach
sahilagichani14 Aug 28, 2024
6a8c54f
fix and added test cases
sahilagichani14 Aug 29, 2024
7a40810
Merge branch 'refs/heads/develop' into 930-bug-conditionalbranchfolde…
sahilagichani14 Sep 2, 2024
a848013
added test case for ConditionalBranchFolder
sahilagichani14 Sep 3, 2024
4c6f99e
fix trap is not iterated exception in valid cases (i.e. there exists …
swissiety Sep 3, 2024
51f56cc
fix style
sahilagichani14 Sep 10, 2024
b801cd9
Merge branch 'refs/heads/develop' into 930-bug-conditionalbranchfolde…
sahilagichani14 Sep 10, 2024
626e249
fix exceptionial flow caused nontermination + order improvement
swissiety Sep 13, 2024
0452813
reduced more ordering issues
swissiety Sep 13, 2024
9a7555b
fix order for exceptions as well;
swissiety Sep 13, 2024
2424032
added tc
sahilagichani14 Sep 22, 2024
6577ab8
just 7 testcases of minimaltestsuite failing
swissiety Sep 17, 2024
92a3033
8 testcases of minimaltestsuite failing - exceptional ones
swissiety Sep 19, 2024
e39acf7
Merge branch 'refs/heads/develop' into 930-bug-conditionalbranchfolde…
sahilagichani14 Sep 30, 2024
5dad178
merged with develop
sahilagichani14 Sep 30, 2024
133a79f
Merge branch 'refs/heads/develop' into 930-bug-conditionalbranchfolde…
sahilagichani14 Oct 1, 2024
e0afcca
use UCE at the end, added a tc
sahilagichani14 Oct 2, 2024
dd5b793
Merge branch 'develop' into 930-bug-conditionalbranchfolder-removes-c…
stschott Oct 16, 2024
e517d7a
Merge branch 'refs/heads/develop' into 930-bug-conditionalbranchfolde…
sahilagichani14 Oct 25, 2024
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
Binary file not shown.
70 changes: 70 additions & 0 deletions shared-test-resources/bugfixes/ConditionalBranchFolderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
public class ConditionalBranchFolderTest {
void tc1() {
boolean bool = true;
if (!bool) {
System.out.println("False 1");
} else if (bool) {
if (bool){
System.out.println("lets see");
}
System.out.println("mid");
}
if (!bool) {
System.out.println("False 2");
}
}

void tc1_1() {
boolean bool = true;
if (!bool) {
System.out.println("False 1");
} else if (!bool) {
if (bool){
System.out.println("lets see");
}
System.out.println("mid");
}
if (bool) {
System.out.println("False 2");
}
}

void tc2() {
boolean bool = true;
try {
if (bool) {
throw new Exception("True");
}
} catch (Exception e) {
e.printStackTrace();
}
}

void tc3() {
boolean bool = false;
try {
if (bool) {
throw new Exception("True");
}
} catch (Exception e) {
e.printStackTrace();
}
}

void tc4() {
int x = 10;
boolean bool = true;
if(x > 5) {
try {
System.out.println("Try Block");
if (bool) {
System.out.println("True inside Try");
}
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("");
}

}
Binary file added shared-test-resources/bugfixes/LineIterator.class
Binary file not shown.
85 changes: 85 additions & 0 deletions shared-test-resources/bugfixes/LineIterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.Reader;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class LineIterator implements Iterator<String>, Closeable {
private final BufferedReader bufferedReader;
private String cachedLine;
private boolean finished;

public LineIterator(Reader reader) throws IllegalArgumentException {
if (reader == null) {
throw new IllegalArgumentException("Reader must not be null");
} else {
if (reader instanceof BufferedReader) {
this.bufferedReader = (BufferedReader)reader;
} else {
this.bufferedReader = new BufferedReader(reader);
}

}
}

public boolean hasNext() {
if (this.cachedLine != null) {
return true;
} else if (this.finished) {
return false;
} else {
try {
String line;
do {
line = this.bufferedReader.readLine();
if (line == null) {
this.finished = true;
return false;
}
} while(!this.isValidLine(line));

this.cachedLine = line;
return true;
} catch (IOException var2) {
IOException ioe = var2;
// IOUtils.closeQuietly(this, ioe::addSuppressed);
throw new IllegalStateException(ioe);
}
}
}

protected boolean isValidLine(String line) {
return true;
}

public String next() {
return this.nextLine();
}

public String nextLine() {
if (!this.hasNext()) {
throw new NoSuchElementException("No more lines");
} else {
String currentLine = this.cachedLine;
this.cachedLine = null;
return currentLine;
}
}

public void close() throws IOException {
this.finished = true;
this.cachedLine = null;
// IOUtils.close(this.bufferedReader);
}

public void remove() {
throw new UnsupportedOperationException("remove not supported");
}

/** @deprecated */
@Deprecated
public static void closeQuietly(LineIterator iterator) {
// IOUtils.closeQuietly(iterator);
}
}
25 changes: 25 additions & 0 deletions shared-test-resources/bugfixes/NestedTryCatchFinally.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.io.FileInputStream;
import java.io.File;
import java.io.ObjectInputStream;

public class NestedTryCatchFinally {

private static String test0(File storedResults) throws Exception {
try {
FileInputStream file = new FileInputStream(storedResults);
try {
ObjectInputStream stream = new ObjectInputStream(file);
try {
return (String) stream.readObject();
} finally {
stream.close();
}
} finally {
file.close();
}
} catch (Exception e) {
throw new Exception(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,22 @@ public void removeBlock(BasicBlock<?> block) {
blockOf.clearPredecessorBlocks();
blockOf.clearSuccessorBlocks();
blockOf.clearExceptionalSuccessorBlocks();

blocks.remove(blockOf);
}

@Override
public void replaceStmt(@Nonnull Stmt oldStmt, @Nonnull Stmt newStmt) {
Pair<Integer, MutableBasicBlock> blockPair = stmtToBlock.get(oldStmt);
if (blockPair == null) {
// Stmt does not exist in the graph
throw new IllegalArgumentException("splitStmt does not exist in this block!");
}
MutableBasicBlock block = blockPair.getRight();
block.replaceStmt(oldStmt, newStmt);
stmtToBlock.remove(oldStmt);
stmtToBlock.put(newStmt, blockPair);
}

@Override
public void addNode(@Nonnull Stmt stmt, @Nonnull Map<ClassType, Stmt> exceptions) {
Pair<Integer, MutableBasicBlock> blockPair = stmtToBlock.get(stmt);
Expand Down Expand Up @@ -1276,6 +1288,25 @@ protected void putEdge_internal(@Nonnull Stmt stmtA, int succesorIdx, @Nonnull S
}
}

@Override
public void unLinkNodes(@Nonnull Stmt from, @Nonnull Stmt to) {
Pair<Integer, MutableBasicBlock> blockOfFromPair = stmtToBlock.get(from);
if (blockOfFromPair == null) {
throw new IllegalArgumentException("stmt '" + from + "' does not exist in this StmtGraph!");
}
MutableBasicBlock blockOfFrom = blockOfFromPair.getRight();
Pair<Integer, MutableBasicBlock> blockOfToPair = stmtToBlock.get(to);
if (blockOfToPair == null) {
throw new IllegalArgumentException("stmt '" + to + "' does not exist in this StmtGraph!");
}
MutableBasicBlock blockOfTo = blockOfToPair.getRight();

// TODO: only works if "from" is the tail of a block
// Unlink 2 blocks
blockOfFrom.removeFromSuccessorBlocks(blockOfTo);
blockOfTo.removePredecessorBlock(blockOfFrom);
}

@Override
public List<Integer> removeEdge(@Nonnull Stmt from, @Nonnull Stmt to) {
Pair<Integer, MutableBasicBlock> blockOfFromPair = stmtToBlock.get(from);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public void addNode(@Nonnull Stmt stmt) {
addNode(stmt, Collections.emptyMap());
}

/** replace a "oldStmt" with "newStmt" in the StmtGraph */
public abstract void replaceStmt(@Nonnull Stmt oldStmt, @Nonnull Stmt newStmt);

/** inserts a "stmt" with exceptional flows "traps" into the StmtGraph */
public abstract void addNode(@Nonnull Stmt stmt, @Nonnull Map<ClassType, Stmt> traps);

Expand Down Expand Up @@ -107,6 +110,8 @@ public void setEdges(@Nonnull BranchingStmt from, @Nonnull Stmt... targets) {
setEdges(from, Arrays.asList(targets));
}

public abstract void unLinkNodes(@Nonnull Stmt from, @Nonnull Stmt to);

/**
* removes the current outgoing flows of "from" to "to"
*
Expand Down
Loading
Loading