|
42 | 42 | import com.ibm.wala.util.collections.HashMapFactory;
|
43 | 43 | import com.ibm.wala.util.collections.Pair;
|
44 | 44 | import com.ibm.wala.util.intset.OrdinalSet;
|
| 45 | +import java.util.HashMap; |
45 | 46 | import java.util.Map;
|
46 | 47 | import java.util.logging.Logger;
|
47 | 48 |
|
@@ -222,6 +223,8 @@ private IClass getCallable(CGNode caller, IClassHierarchy cha, PythonInvokeInstr
|
222 | 223 | PointerKey receiver = pkf.getPointerKeyForLocal(caller, call.getUse(0));
|
223 | 224 | OrdinalSet<InstanceKey> objs = builder.getPointerAnalysis().getPointsToSet(receiver);
|
224 | 225 |
|
| 226 | + Map<InstanceKey, IClass> instanceToCallable = new HashMap<>(); |
| 227 | + |
225 | 228 | for (InstanceKey o : objs) {
|
226 | 229 | AllocationSiteInNode instanceKey = getAllocationSiteInNode(o);
|
227 | 230 | if (instanceKey != null) {
|
@@ -253,10 +256,29 @@ private IClass getCallable(CGNode caller, IClassHierarchy cha, PythonInvokeInstr
|
253 | 256 | LOGGER.info("Applying callable workaround for https://github.com/wala/ML/issues/118.");
|
254 | 257 | }
|
255 | 258 |
|
256 |
| - if (callable != null) return callable; |
| 259 | + if (callable != null) { |
| 260 | + if (instanceToCallable.containsKey(instanceKey)) |
| 261 | + throw new IllegalStateException("Exisitng mapping found for: " + instanceKey); |
| 262 | + |
| 263 | + IClass previousValue = instanceToCallable.put(instanceKey, callable); |
| 264 | + assert previousValue == null : "Not expecting a previous mapping."; |
| 265 | + } |
257 | 266 | }
|
258 | 267 | }
|
259 | 268 |
|
| 269 | + // if there's only one possible option. |
| 270 | + if (instanceToCallable.values().size() == 1) { |
| 271 | + IClass callable = instanceToCallable.values().iterator().next(); |
| 272 | + assert callable != null : "Callable should be non-null."; |
| 273 | + return callable; |
| 274 | + } |
| 275 | + |
| 276 | + // if we have multiple candidates. |
| 277 | + if (instanceToCallable.values().size() > 1) |
| 278 | + // we cannot accurately select one. |
| 279 | + LOGGER.warning( |
| 280 | + "Multiple (" + instanceToCallable.values().size() + ") callable targets found."); |
| 281 | + |
260 | 282 | return null;
|
261 | 283 | }
|
262 | 284 |
|
|
0 commit comments