Skip to content

Missing the print built-in function summary #93

Closed
@khatchad

Description

@khatchad

Description

Consider the following example input program:

# A.py
def f(x):
  print("Traced with: " + str(x))


f(1)

This is the IR of f():

Node: <Code body of function Lscript A.py/f> Context: CallStringContext: [ script A.py.do()LRoot;@97 ]
<Code body of function Lscript A.py/f>
CFG:
BB0[-1..-2]
    -> BB1
BB1[0..2]
    -> BB2
    -> BB3
BB2[3..4]
    -> BB3
BB3[-1..-2]
Instructions:
BB0
BB1
0   v5 = lexical:print@Lscript A.py          A.py [2:2] -> [2:7]
1   v10 = lexical:str@Lscript A.py           A.py [2:26] -> [2:29]
2   v8 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v10,v2 @2 exception:v11A.py [2:26] -> [2:32] [2=[x]]
BB2
3   v6 = binaryop(add) v7:#Traced with:  , v8A.py [2:8] -> [2:32]
4   v3 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v5,v6 @4 exception:v12A.py [2:2] -> [2:33]
BB3

Above, v5 is the print() function, while v10 is the str() function. However, in the pointer analysis, I am seeing the following:

  [Node: <Code body of function Lscript A.py/f> Context: CallStringContext: [ script A.py.do()LRoot;@97 ], v5] ->
  [Node: <Code body of function Lscript A.py/f> Context: CallStringContext: [ script A.py.do()LRoot;@97 ], v10] ->
     [com.ibm.wala.cast.python.ipa.summaries.BuiltinFunctions$BuiltinFunction@1724e9f5]

The points-to set for v5 in f() of A.py is empty, while the points-to set of v10 contains the built-in.

Regression

I believe that the print() function needs to be added here:

static {
// builtinFunctions.put("enumerate", Either.forLeft(PythonTypes.enumerate));
builtinFunctions.put("enumerate", Either.forRight(2));
builtinFunctions.put("int", Either.forLeft(TypeReference.Int));
builtinFunctions.put("round", Either.forLeft(TypeReference.Int));
builtinFunctions.put("len", Either.forLeft(TypeReference.Int));
builtinFunctions.put("list", Either.forLeft(PythonTypes.list));
builtinFunctions.put("range", Either.forLeft(PythonTypes.list));
builtinFunctions.put("sorted", Either.forLeft(PythonTypes.list));
builtinFunctions.put("str", Either.forLeft(PythonTypes.string));
builtinFunctions.put("sum", Either.forLeft(TypeReference.Int));
builtinFunctions.put("type", Either.forLeft(PythonTypes.object));
builtinFunctions.put("zip", Either.forLeft(PythonTypes.list));
builtinFunctions.put("slice", Either.forRight(2));
builtinFunctions.put("__delete__", Either.forRight(2));
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions