Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing the print built-in function summary #93

Closed
khatchad opened this issue Oct 19, 2023 · 0 comments · Fixed by #95
Closed

Missing the print built-in function summary #93

khatchad opened this issue Oct 19, 2023 · 0 comments · Fixed by #95
Assignees
Labels
bug Something isn't working

Comments

@khatchad
Copy link
Collaborator

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));
}

@khatchad khatchad added the bug Something isn't working label Oct 19, 2023
khatchad added a commit to ponder-lab/Hybridize-Functions-Refactoring that referenced this issue Oct 19, 2023
@khatchad khatchad self-assigned this Oct 20, 2023
khatchad added a commit to ponder-lab/ML that referenced this issue Oct 20, 2023
Add print() built-in. Partially addresses wala#93.
khatchad added a commit to ponder-lab/ML that referenced this issue Oct 20, 2023
khatchad added a commit that referenced this issue Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant