Skip to content

Commit

Permalink
Expect the test to fail.
Browse files Browse the repository at this point in the history
In the past, we could add 0's to the parameters, but since we are not
enforcing the existing of the node in the CG, we can no longer do that.
Still, this test should now fail if wala#207 is fixed.
  • Loading branch information
khatchad committed Jul 19, 2024
1 parent 5660bfe commit b0e1c92
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1183,9 +1183,10 @@ public void testModelCall4()

/**
* Test call string imprecision as described in
* https://github.com/wala/WALA/discussions/1417#discussioncomment-10085680.
* https://github.com/wala/WALA/discussions/1417#discussioncomment-10085680. This should fail due
* to https://github.com/wala/ML/issues/207.
*/
@Test
@Test(expected = java.lang.AssertionError.class)
public void testModelCall5()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.intset.OrdinalSet;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

Expand Down Expand Up @@ -222,6 +223,8 @@ private IClass getCallable(CGNode caller, IClassHierarchy cha, PythonInvokeInstr
PointerKey receiver = pkf.getPointerKeyForLocal(caller, call.getUse(0));
OrdinalSet<InstanceKey> objs = builder.getPointerAnalysis().getPointsToSet(receiver);

Map<InstanceKey, IClass> instanceToCallable = new HashMap<>();

for (InstanceKey o : objs) {
AllocationSiteInNode instanceKey = getAllocationSiteInNode(o);
if (instanceKey != null) {
Expand Down Expand Up @@ -253,10 +256,29 @@ private IClass getCallable(CGNode caller, IClassHierarchy cha, PythonInvokeInstr
LOGGER.info("Applying callable workaround for https://github.com/wala/ML/issues/118.");
}

if (callable != null) return callable;
if (callable != null) {
if (instanceToCallable.containsKey(instanceKey))
throw new IllegalStateException("Exisitng mapping found for: " + instanceKey);

IClass previousValue = instanceToCallable.put(instanceKey, callable);
assert previousValue == null : "Not expecting a previous mapping.";
}
}
}

// if there's only one possible option.
if (instanceToCallable.values().size() == 1) {
IClass callable = instanceToCallable.values().iterator().next();
assert callable != null : "Callable should be non-null.";
return callable;
}

// if we have multiple candidates.
if (instanceToCallable.values().size() > 1)
// we cannot accurately select one.
LOGGER.warning(
"Multiple (" + instanceToCallable.values().size() + ") callable targets found.");

return null;
}

Expand Down

0 comments on commit b0e1c92

Please sign in to comment.