roterdam / crystalsaf

Automatically exported from code.google.com/p/crystalsaf
0 stars 0 forks source link

Infinite Recursion in Eclipse CFG Builder #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
There is a bug in Eclipse, in the CFG builder. Any time you run a data flow 
analysis on the await() method in the attached class, Crystal throws a 
StackOverflowException, because of an infinite recursion. I encountered the 
error by running LiveVariableAnalysis, but it seems to happen with any 
dataflow analysis. The stack trace is also attached.

Original issue reported on code.google.com by nels.bec...@gmail.com on 19 Feb 2010 at 3:23

Attachments:

GoogleCodeExporter commented 9 years ago
Okay, the problem actually may be quite straightforward. In the 
copySubgraphRecur 
method, there is nothing to detect a cycle; no markers to let us know that 
we've gone 
around the loop once already, so it will just go around forever. 
copySubgrpahRecur is 
only called for finally blocks, and therefore this bug will only occur if there 
is a 
finally block with a loop in it. This example finds the bug too:

void foo() {
        try {
            return;
        } finally {
            while(true) {
                System.out.println("Yes");
            }
        }
    }

Original comment by nels.bec...@gmail.com on 22 Feb 2010 at 6:31

GoogleCodeExporter commented 9 years ago
Here is a patch. Does this work?

Index: EclipseCFG.java
===================================================================
--- EclipseCFG.java (revision 289)
+++ EclipseCFG.java (working copy)
@@ -345,7 +345,13 @@
        clone.setName(current.getName());
        cloneMap.put(current, clone);

-       if (current == stopNode || node instanceof ReturnStatement
+       if( cloneMap.containsKey(current) ) {
+           if( cloneMap.get(current).equals(clone) ) {
+               // We've already been to this...
+               return clone;
+           }
+       }
+       else if (current == stopNode || node instanceof ReturnStatement
            || node instanceof ThrowStatement || node instanceof 
BreakStatement
            || node instanceof ContinueStatement) {
            for (EclipseCFGEdge edge : current.getOutputs()) {

Original comment by nels.bec...@gmail.com on 22 Feb 2010 at 6:36

GoogleCodeExporter commented 9 years ago
The previous patch does seem to work on 'foo()' example above...

Original comment by nels.bec...@gmail.com on 22 Feb 2010 at 6:37

GoogleCodeExporter commented 9 years ago
It breaks one of the existing tests though. I need to install the dot viewer on 
my new 
version of eclipse to find out what's going on.

Original comment by ciera.christopher on 22 Feb 2010 at 6:47

GoogleCodeExporter commented 9 years ago
My mistake on that test. Verified fix, and test is committed.

Original comment by ciera.christopher on 25 Feb 2010 at 10:33

GoogleCodeExporter commented 9 years ago
Awsum!

Original comment by nels.bec...@gmail.com on 26 Feb 2010 at 9:03