Fix for bug reported by Ravi Chandran on the mailing list (10/01/2010). Properly add edges from method entry in the PDG

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3965 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
msridhar1 2010-10-05 18:45:43 +00:00
parent ed889de199
commit 029b1fc1fd
4 changed files with 79 additions and 7 deletions

View File

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2006 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package slice;
public class TestCD5 {
/**
*
* @param args
*/
public static void main(String[] args) {
int i = 0;
while (someBool()) {
++i;
if (i >= 3) {
return;
}
}
}
public static boolean someBool() {
return false;
}
}

View File

@ -38,6 +38,7 @@ import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ipa.slicer.MethodEntryStatement;
import com.ibm.wala.ipa.slicer.NormalStatement;
import com.ibm.wala.ipa.slicer.SDG;
import com.ibm.wala.ipa.slicer.Slicer;
@ -371,6 +372,30 @@ public class SlicerTest {
dumpSlice(slice);
Assert.assertEquals(1, countConditionals(slice));
}
@Test
public void testTestCD5() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
AnalysisScope scope = findOrCreateAnalysisScope();
IClassHierarchy cha = findOrCreateCHA(scope);
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha,
TestConstants.SLICE_TESTCD5);
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
CallGraphBuilder builder = Util.makeZeroOneCFABuilder(options, new AnalysisCache(), cha, scope);
CallGraph cg = builder.makeCallGraph(options, null);
CGNode main = findMainMethod(cg);
Statement s = new MethodEntryStatement(main);
System.err.println("Statement: " + s);
// compute a no-data slice
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, builder.getPointerAnalysis(), DataDependenceOptions.NONE,
ControlDependenceOptions.FULL);
dumpSlice(slice);
Assert.assertTrue(slice.size() > 1);
}
@Test
public void testTestId() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {

View File

@ -109,6 +109,8 @@ public interface TestConstants {
public final static String SLICE_TESTCD4 = "Lslice/TestCD4";
public final static String SLICE_TESTCD5 = "Lslice/TestCD5";
public final static String SLICE_TESTID = "Lslice/TestId";
public final static String SLICE_TESTARRAYS = "Lslice/TestArrays";

View File

@ -295,15 +295,27 @@ public class PDG implements NumberedGraph<Statement> {
// the CDG does not represent control dependences from the entry node.
// add these manually
// We add control dependences to all instructions in all basic blocks B that _must_ execute.
// A basic block is in B iff (1) it is the entry or (2) it is the sole successor of a block
// in B
Statement methodEntry = new MethodEntryStatement(node);
for (Iterator<? extends ISSABasicBlock> it = cdg.iterator(); it.hasNext();) {
ISSABasicBlock bb = it.next();
if (cdg.getPredNodeCount(bb) == 0) {
// this is control dependent on the method entry.
for (SSAInstruction st : bb) {
Statement dest = ssaInstruction2Statement(st, ir, instructionIndices);
delegate.addEdge(methodEntry, dest);
ISSABasicBlock curBB = controlFlowGraph.entry();
Set<ISSABasicBlock> handledBlocks = HashSetFactory.make(2);
handledBlocks.add(curBB);
while (curBB != null) {
for (SSAInstruction st : curBB) {
Statement dest = ssaInstruction2Statement(st, ir, instructionIndices);
delegate.addEdge(methodEntry, dest);
}
if (controlFlowGraph.getSuccNodeCount(curBB) == 1) {
ISSABasicBlock succBlock = controlFlowGraph.getSuccNodes(curBB).next();
if (handledBlocks.add(succBlock)) {
curBB = succBlock;
} else {
curBB = null;
}
} else {
curBB = null;
}
}
// add CD from method entry to all callee parameter assignments