Commit 79114520 authored by Skylot's avatar Skylot

Fix endless loop in path existence check

parent d3c2496f
...@@ -70,7 +70,7 @@ public class BlockUtils { ...@@ -70,7 +70,7 @@ public class BlockUtils {
} }
/** /**
* Check if insn contains in block (use == for comparison, not equals) * Check if instruction contains in block (use == for comparison, not equals)
*/ */
public static boolean blockContains(BlockNode block, InsnNode insn) { public static boolean blockContains(BlockNode block, InsnNode insn) {
for (InsnNode bi : block.getInstructions()) { for (InsnNode bi : block.getInstructions()) {
...@@ -81,7 +81,7 @@ public class BlockUtils { ...@@ -81,7 +81,7 @@ public class BlockUtils {
} }
/** /**
* Return position of instruction in block (use == for comparison, not equals) * Return instruction position in block (use == for comparison, not equals)
*/ */
public static int insnIndex(BlockNode block, InsnNode insn) { public static int insnIndex(BlockNode block, InsnNode insn) {
int size = block.getInstructions().size(); int size = block.getInstructions().size();
...@@ -128,7 +128,7 @@ public class BlockUtils { ...@@ -128,7 +128,7 @@ public class BlockUtils {
} }
/** /**
* Return first successor which not exception handler or followed by loop back edge * Return first successor which not exception handler and not follow loop back edge
*/ */
public static BlockNode getNextBlock(BlockNode block) { public static BlockNode getNextBlock(BlockNode block) {
List<BlockNode> s = block.getCleanSuccessors(); List<BlockNode> s = block.getCleanSuccessors();
...@@ -155,13 +155,20 @@ public class BlockUtils { ...@@ -155,13 +155,20 @@ public class BlockUtils {
} }
} }
private static boolean addSuccessorsUntil(BlockNode from, BlockNode until) { private static boolean traverseSuccessorsUntil(BlockNode from, BlockNode until, Set<BlockNode> checked) {
if (from == until)
return true;
for (BlockNode s : from.getCleanSuccessors()) { for (BlockNode s : from.getCleanSuccessors()) {
if (addSuccessorsUntil(s, until)) if (s == until)
return true; return true;
if (!checked.contains(s)) {
checked.add(s);
if (until.isDominator(s))
return true;
if (traverseSuccessorsUntil(s, until, checked))
return true;
}
} }
return false; return false;
} }
...@@ -173,8 +180,7 @@ public class BlockUtils { ...@@ -173,8 +180,7 @@ public class BlockUtils {
if (end.isDominator(start)) if (end.isDominator(start))
return true; return true;
return addSuccessorsUntil(start, end); return traverseSuccessorsUntil(start, end, new HashSet<BlockNode>());
// return addPredcessorsUntil(new HashSet<BlockNode>(), end, start);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment