[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Soot bugs when first Unit is a target



Chris Pickett wrote:
> >>>Why not try and introduce (at the right time) fake heads (using NOP's?) 
> >>>before targets that are the first statement?
> >>
> >>NopEliminator would probably interfere with this plan; you'd have to 
> >>stop it from touching graph heads until you were done with Jimple, and 
> >>then go back and get rid of all those heads.  It could work, I think.
> > 
> > I tried it and it didn't work, even if I added the Nop's after
> > the jop phase had already run. Not sure why that didn't fix it,
> > but it didn't..
> 
> NopEliminator is part of jb, not jop, although that's probably not 
> relevant.  Are the Nop's still there when it dies?

Ah, yes now adding Nop's works. Before it wasn't working because
I didn't realize that when you insert a Stmt at the beginning of
a body, jumps to the old first Stmt are redirected to the new one.
So you have to do it like this:

    Unit first = (Unit)units.getFirst();
    Unit newFirst = Jimple.v().newNopStmt();
    units.insertBefore(newFirst, first);
    newFirst.redirectJumpsToThisTo(first);

Thanks for all the help.. at least now I can workaround the problem.
However, it still leaves the unanswered question as to what is going on.

For one thing, it's not clear to me what the definition of "head" is
in the context of a directed graph. Is a head equivalent to a node with
in-degree zero? (I don't think so, but..) If so, then BlockGraph.java is
broken, because the first statement is always marked as a head.

Otherwise, if a head is not required to have degree zero (seems more
likely to be the case), then it must be ArrayBoundsCheckerAnalysis.java
(at least) that has the bug, because it assumes that all heads have
in-degree zero.

At this point I'm stuck because I haven't studied the theory behind the
array check analysis enough to understand how it works.

FYI, below is my patch to fix related bugs found in the process of
investigating this one. Note there is a new fix not included in the
previous patch I posted. Maintainers, please review (and commit if
acceptable).

Thanks,
-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

diff -ur src.orig/soot/toolkits/graph/BlockGraph.java src/soot/toolkits/graph/BlockGraph.java
--- src.orig/soot/toolkits/graph/BlockGraph.java	Sat Nov 22 14:16:09 2003
+++ src/soot/toolkits/graph/BlockGraph.java	Thu Jul 15 16:49:19 2004
@@ -120,7 +120,9 @@
             // Get the leaders that bound exception contexts.
             if(type == ZONED) {              
               List predList = new ArrayList();
-              predList.add(mUnits.getPredOf(someTrap.getBeginUnit()));
+              if(mUnits.getPredOf(someTrap.getBeginUnit()) != null) {
+		  predList.add(mUnits.getPredOf(someTrap.getBeginUnit()));
+	      }
               leaders.put(someTrap.getBeginUnit(), predList);
 
               predList = new ArrayList();
@@ -189,7 +191,7 @@
                             predecessors= new LinkedList();
                             predecessors.add(currentUnit);
                             Unit targetPred = (Unit) mUnits.getPredOf(target);
-                            if(targetPred.fallsThrough())
+                            if(targetPred != null && targetPred.fallsThrough())
                                 predecessors.add(targetPred);
                                 
                             leaders.put(target, predecessors);
@@ -238,13 +240,15 @@
 
 		    if ((nextUnit != null) &&(stmt.containsArrayRef()))
 		    {
+			List predecessors;
 			if (!leaders.containsKey(nextUnit))
 		        {
-			    List predicessors = new LinkedList();
-			    predicessors.add(currentUnit);
-
-			    leaders.put(nextUnit, predicessors);
+			    predecessors = new LinkedList();
+			    leaders.put(nextUnit, predecessors);
+			} else {
+			    predecessors = (List)leaders.get(nextUnit);
 			}
+			predecessors.add(currentUnit);
 		    }
 		}
                 
@@ -264,7 +268,7 @@
                                 predecessors= new LinkedList();
                                 predecessors.add(currentUnit);
                                 Unit targetPred = (Unit) mUnits.getPredOf(target);
-                                if(targetPred.fallsThrough())
+                                if(targetPred != null && targetPred.fallsThrough())
                                     predecessors.add(targetPred);
                             
                                 leaders.put(target, predecessors);