bug fixes for flows-to
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3766 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
24caeb7088
commit
4b34785700
|
@ -222,7 +222,7 @@ public abstract class AbstractPtrTest {
|
|||
|
||||
// find the single allocation site of FlowsToType, make an InstanceKey, and query it
|
||||
CGNode mainMethod = AbstractPtrTest.findMainMethod(dmp.getBaseCallGraph());
|
||||
InstanceKey keyToQuery = AbstractPtrTest.getFlowsToInstanceKey(mainMethod, dmp.getHeapModel());
|
||||
InstanceKey keyToQuery = getFlowsToInstanceKey(mainMethod, dmp.getHeapModel());
|
||||
Collection<PointerKey> flowsTo = dmp.getFlowsTo(keyToQuery).snd;
|
||||
return flowsTo;
|
||||
}
|
||||
|
@ -230,12 +230,14 @@ public abstract class AbstractPtrTest {
|
|||
/**
|
||||
* returns the instance key corresponding to the single allocation site of type FlowsToType
|
||||
*/
|
||||
private static InstanceKey getFlowsToInstanceKey(CGNode mainMethod, HeapModel heapModel) {
|
||||
private InstanceKey getFlowsToInstanceKey(CGNode mainMethod, HeapModel heapModel) {
|
||||
// TODO Auto-generated method stub
|
||||
TypeReference flowsToTypeRef = TypeReference.findOrCreate(ClassLoaderReference.Application, StringStuff
|
||||
.deployment2CanonicalTypeString("demandpa.FlowsToType"));
|
||||
final IR mainIR = mainMethod.getIR();
|
||||
// System.err.println(mainIR);
|
||||
if (debug) {
|
||||
System.err.println(mainIR);
|
||||
}
|
||||
for (NewSiteReference n : Iterator2Iterable.make(mainIR.iterateNewSites())) {
|
||||
if (n.getDeclaredType().equals(flowsToTypeRef)) {
|
||||
return heapModel.getInstanceKeyForAllocation(mainMethod, n);
|
||||
|
|
|
@ -109,4 +109,14 @@ public class RefineFieldsPtrTest extends AbstractPtrTest {
|
|||
return dmp;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlowsToFields() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
|
||||
doFlowsToSizeTest(TestInfo.FLOWSTO_TEST_FIELDS, 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlowsToFieldsHarder() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
|
||||
doFlowsToSizeTest(TestInfo.FLOWSTO_TEST_FIELDS_HARDER, 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1659,16 +1659,14 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
IFlowLabelVisitor predVisitor = new AbstractFlowLabelVisitor() {
|
||||
|
||||
@Override
|
||||
public void visitAssignGlobal(AssignGlobalLabel label, Object dst) {
|
||||
public void visitAssignGlobal(final AssignGlobalLabel label, Object dst) {
|
||||
for (Iterator<? extends Object> readIter = g.getReadsOfStaticField((StaticFieldKey) dst); readIter.hasNext();) {
|
||||
final PointerKey predPk = (PointerKey) readIter.next();
|
||||
doTransition(curState, AssignGlobalBarLabel.v(), new Function<State, Object>() {
|
||||
|
||||
public Object apply(State predPkState) {
|
||||
PointerKeyAndState predPkAndState = new PointerKeyAndState(predPk, predPkState);
|
||||
if (findOrCreate(pkToTrackedSet, predPkAndState).addAll(trackedSet)) {
|
||||
addToTrackedPToWorklist(predPkAndState);
|
||||
}
|
||||
handleTrackedPred(trackedSet, predPkAndState, AssignGlobalBarLabel.v());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1699,9 +1697,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
|
||||
public Object apply(State predPkState) {
|
||||
PointerKeyAndState predPkAndState = new PointerKeyAndState(predPk, predPkState);
|
||||
if (findOrCreate(pkToTrackedSet, predPkAndState).addAll(trackedSet)) {
|
||||
addToTrackedPToWorklist(predPkAndState);
|
||||
}
|
||||
handleTrackedPred(trackedSet, predPkAndState, MatchBarLabel.v());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1725,24 +1721,21 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
addEncounteredLoad(new LoadEdge(curPkAndState, field, loadedVal));
|
||||
if (needField) {
|
||||
InstanceFieldKeyAndState ifk = getInstFieldKey(ikAndState, field);
|
||||
if (findOrCreate(pkToTrackedSet, loadedVal).addAll(find(instFieldKeyToTrackedSet, ifk))) {
|
||||
addToTrackedPToWorklist(loadedVal);
|
||||
}
|
||||
// use an assign bar label with no filter here, since filtering only happens at casts
|
||||
handleTrackedPred(find(instFieldKeyToTrackedSet, ifk), loadedVal, AssignBarLabel.noFilter());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAssign(AssignLabel label, Object dst) {
|
||||
public void visitAssign(final AssignLabel label, Object dst) {
|
||||
final PointerKey predPk = (PointerKey) dst;
|
||||
doTransition(curState, AssignBarLabel.noFilter(), new Function<State, Object>() {
|
||||
doTransition(curState, label.bar(), new Function<State, Object>() {
|
||||
|
||||
public Object apply(State predPkState) {
|
||||
PointerKeyAndState predPkAndState = new PointerKeyAndState(predPk, predPkState);
|
||||
if (findOrCreate(pkToTrackedSet, predPkAndState).addAll(trackedSet)) {
|
||||
addToTrackedPToWorklist(predPkAndState);
|
||||
}
|
||||
handleTrackedPred(trackedSet, predPkAndState, label.bar());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1754,14 +1747,12 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
handleBackInterproc(curPkAndState, new CopyHandler() {
|
||||
|
||||
@Override
|
||||
void handle(PointerKeyAndState src, final PointerKey dst, IFlowLabel label) {
|
||||
void handle(PointerKeyAndState src, final PointerKey dst, final IFlowLabel label) {
|
||||
assert src == curPkAndState;
|
||||
doTransition(curState, label, new Function<State, Object>() {
|
||||
public Object apply(State dstState) {
|
||||
PointerKeyAndState dstAndState = new PointerKeyAndState(dst, dstState);
|
||||
if (findOrCreate(pkToTrackedSet, dstAndState).addAll(trackedSet)) {
|
||||
addToTrackedPToWorklist(dstAndState);
|
||||
}
|
||||
handleTrackedPred(trackedSet, dstAndState, label);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1876,6 +1867,19 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a predecessor when processing some tracked locations
|
||||
* @param curTrackedSet the tracked locations
|
||||
* @param predPkAndState the predecessor
|
||||
*/
|
||||
protected boolean handleTrackedPred(final MutableIntSet curTrackedSet, PointerKeyAndState predPkAndState, IFlowLabel label) {
|
||||
if (addAllToP2Set(pkToTrackedSet, predPkAndState, curTrackedSet, label)) {
|
||||
addToTrackedPToWorklist(predPkAndState);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private SSAAbstractInvokeInstruction[] getCallInstrs(CGNode node, CallSiteReference site) {
|
||||
|
@ -2401,8 +2405,8 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
PointerKey predPk = (PointerKey) pred;
|
||||
PointerKeyAndState predPkAndState = new PointerKeyAndState(predPk, queriedIkAndState.getState());
|
||||
theFlowsToSet.add(predPkAndState);
|
||||
findOrCreate(pkToP2Set, predPkAndState).add(queriedIkAndStateNum);
|
||||
addToPToWorklist(predPkAndState);
|
||||
findOrCreate(pkToTrackedSet, predPkAndState).add(queriedIkAndStateNum);
|
||||
addToTrackedPToWorklist(predPkAndState);
|
||||
}
|
||||
worklistLoop();
|
||||
}
|
||||
|
@ -2417,35 +2421,21 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleBackCopy(PointerKeyAndState curPkAndState, PointerKey predPk, IFlowLabel label) {
|
||||
// if curPkAndState can point to the queried instance key...
|
||||
final MutableIntSet curPkP2Set = find(pkToP2Set, curPkAndState);
|
||||
if (curPkP2Set.contains(queriedIkAndStateNum)) {
|
||||
// propagate back everywhere
|
||||
PointerKeyAndState predPkAndState = new PointerKeyAndState(predPk, stateMachine.transition(curPkAndState.getState(), label));
|
||||
if (addAllToP2Set(pkToP2Set, predPkAndState, curPkP2Set, label)) {
|
||||
theFlowsToSet.add(predPkAndState);
|
||||
addToPToWorklist(predPkAndState);
|
||||
}
|
||||
} else {
|
||||
// treat as usual
|
||||
super.handleBackCopy(curPkAndState, predPk, label);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* here, we want to add the graph unconditionally if pkAndState can point to the queried instance key
|
||||
* also update the flows-to set of interest if necessary
|
||||
*/
|
||||
@Override
|
||||
protected boolean calleeSubGraphMissingAndShouldNotBeAdded(boolean addGraphs, CGNode callee, PointerKeyAndState pkAndState) {
|
||||
if (find(pkToP2Set, pkAndState).contains(queriedIkAndStateNum)) {
|
||||
return false;
|
||||
} else {
|
||||
return super.calleeSubGraphMissingAndShouldNotBeAdded(addGraphs, callee, pkAndState);
|
||||
protected boolean handleTrackedPred(MutableIntSet curTrackedSet, PointerKeyAndState predPkAndState, IFlowLabel label) {
|
||||
boolean result = super.handleTrackedPred(curTrackedSet, predPkAndState, label);
|
||||
if (result && find(pkToTrackedSet,predPkAndState).contains(queriedIkAndStateNum)) {
|
||||
theFlowsToSet.add(predPkAndState);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue