diff --git a/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflow2Model.java b/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflow2Model.java index 086a80fb..a8f60a9a 100644 --- a/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflow2Model.java +++ b/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflow2Model.java @@ -3139,6 +3139,26 @@ public void testReshape3() throws ClassHierarchyException, CancelException, IOEx test("tf2_test_reshape3.py", "f", 1, 1, 2); } + @Test + public void testCalls() throws ClassHierarchyException, CancelException, IOException { + test( + new String[] {"tf2_test_calls.py", "tf2_test_calls2.py", "tf2_test_calls3.py"}, + "tf2_test_calls.py", + "C.call", + "", + 1, + 1, + 3); + test( + new String[] {"tf2_test_calls.py", "tf2_test_calls2.py", "tf2_test_calls3.py"}, + "tf2_test_calls2.py", + "C.call", + "", + 1, + 1, + 3); + } + private void test( String filename, String functionName, diff --git a/com.ibm.wala.cast.python.test/data/tf2_test_calls.py b/com.ibm.wala.cast.python.test/data/tf2_test_calls.py new file mode 100644 index 00000000..02effc4a --- /dev/null +++ b/com.ibm.wala.cast.python.test/data/tf2_test_calls.py @@ -0,0 +1,11 @@ +import tensorflow as tf +from tf2_test_calls3 import g + + +class C(tf.keras.Model): + + def call(self, a): + assert isinstance(a, tf.Tensor) + + +g(C()) diff --git a/com.ibm.wala.cast.python.test/data/tf2_test_calls2.py b/com.ibm.wala.cast.python.test/data/tf2_test_calls2.py new file mode 100644 index 00000000..02effc4a --- /dev/null +++ b/com.ibm.wala.cast.python.test/data/tf2_test_calls2.py @@ -0,0 +1,11 @@ +import tensorflow as tf +from tf2_test_calls3 import g + + +class C(tf.keras.Model): + + def call(self, a): + assert isinstance(a, tf.Tensor) + + +g(C()) diff --git a/com.ibm.wala.cast.python.test/data/tf2_test_calls3.py b/com.ibm.wala.cast.python.test/data/tf2_test_calls3.py new file mode 100644 index 00000000..63998871 --- /dev/null +++ b/com.ibm.wala.cast.python.test/data/tf2_test_calls3.py @@ -0,0 +1,5 @@ +import tensorflow as tf + + +def g(b): + b(tf.constant(1)) 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 5b978870..8e457a8e 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 @@ -222,6 +222,8 @@ private IClass getCallable(CGNode caller, IClassHierarchy cha, PythonInvokeInstr PointerKey receiver = pkf.getPointerKeyForLocal(caller, call.getUse(0)); OrdinalSet objs = builder.getPointerAnalysis().getPointsToSet(receiver); + LOGGER.fine(() -> receiver + " points to " + objs.size() + " instance(s)."); + for (InstanceKey o : objs) { AllocationSiteInNode instanceKey = getAllocationSiteInNode(o); if (instanceKey != null) {