WALA icon indicating copy to clipboard operation
WALA copied to clipboard

Information loss, if value is assigned within IF?

Open felixmaechtle opened this issue 3 years ago • 1 comments

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?

felixmaechtle avatar Nov 10 '22 08:11 felixmaechtle

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.

msridhar avatar Dec 20 '22 23:12 msridhar