From 5fe2b79c05d3090da4f72c41ccea3b5bf52ede1b Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Sun, 21 Jul 2024 11:27:51 -0400 Subject: [PATCH] Use a set to track callable candidates. We don't the instance key that produces the callable right now. --- ...nstanceMethodTrampolineTargetSelector.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonInstanceMethodTrampolineTargetSelector.java b/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonInstanceMethodTrampolineTargetSelector.java index 41ed1ee3..7b997fe4 100644 --- a/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonInstanceMethodTrampolineTargetSelector.java +++ b/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonInstanceMethodTrampolineTargetSelector.java @@ -42,8 +42,9 @@ 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.HashSet; import java.util.Map; +import java.util.Set; import java.util.logging.Logger; public class PythonInstanceMethodTrampolineTargetSelector @@ -223,7 +224,8 @@ private IClass getCallable(CGNode caller, IClassHierarchy cha, PythonInvokeInstr PointerKey receiver = pkf.getPointerKeyForLocal(caller, call.getUse(0)); OrdinalSet objs = builder.getPointerAnalysis().getPointsToSet(receiver); - Map instanceToCallable = new HashMap<>(); + // The set of potential callables to be returned. + Set callableSet = new HashSet<>(); for (InstanceKey o : objs) { AllocationSiteInNode instanceKey = getAllocationSiteInNode(o); @@ -256,28 +258,21 @@ private IClass getCallable(CGNode caller, IClassHierarchy cha, PythonInvokeInstr LOGGER.info("Applying callable workaround for https://github.com/wala/ML/issues/118."); } - 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."; - } + callableSet.add(callable); } } // if there's only one possible option. - if (instanceToCallable.values().size() == 1) { - IClass callable = instanceToCallable.values().iterator().next(); + if (callableSet.size() == 1) { + IClass callable = callableSet.iterator().next(); assert callable != null : "Callable should be non-null."; return callable; } // if we have multiple candidates. - if (instanceToCallable.values().size() > 1) + if (callableSet.size() > 1) // we cannot accurately select one. - LOGGER.warning( - "Multiple (" + instanceToCallable.values().size() + ") callable targets found."); + LOGGER.warning("Multiple (" + callableSet.size() + ") callable targets found."); return null; }