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

Information loss, if value is assigned within IF? #1149

Open
felixmaechtle opened this issue Nov 10, 2022 · 1 comment
Open

Information loss, if value is assigned within IF? #1149

felixmaechtle opened this issue Nov 10, 2022 · 1 comment

Comments

@felixmaechtle
Copy link

Hello,

given the following piece of code:

bar = num > 200 ? "some_string" : param;

This results in the following IR within WALA (excerpt from ir.toString()):

...
6   conditional branch(le, to iindex=9) v7,v8:#200(line 96)
BB2
8   goto (from iindex= 8 to iindex = 10)     (line 96)
BB3
BB4
           v10 = phi  v9:#some_string,v3
12   return v10                              (line 98) [10=[bar]]
...

I know that the IR is already optimised and does not contain the set of a value, so the then branch and the else branch are empty. Is it possible to know that v9 is from the then branch and v3 is from the else branch?

@msridhar
Copy link
Member

Hi @felixmaechtle, in a phi instruction, the uses are in the same order as the predecessor basic blocks in the control-flow graph. So, you can figure out which predecessor block sends v9 and which sends v3, by iterating predecessors using cfg.getPredNodes() and going in order.

Now, you want to know for each of these blocks, whether they correspond to the "then" or "else" case of the conditional branch. The cfg Util class may be of help here:

https://github.com/wala/WALA/blob/master/com.ibm.wala.core/src/main/java/com/ibm/wala/cfg/Util.java

It can help you find the taken and not-taken successors of a block. I hope this helps; please let me know if this solves your issue or if you have more questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants