Help understanding SlitherIR SSA form in loops with if/else branches #2763
Replies: 1 comment
|
I dug into the SSA builder source ( Why the first example works cleanlyYour first example has a textbook phi: What's happening in the second exampleTwo things are combining to produce confusing output: 1. Slither's SSA builder treats these differently. For locals, phi nodes are placed at dominance frontiers of definition sites — the classic algorithm. For state variables, the phi placement uses a slightly different path (lines 139-142 and 153-158 in For a state variable like 2. The The printed output shows IR in source order, but the actual CFG nodes have structure — there's a loop header node, branch nodes, and a merge point. The phi Is this a bug?Partially. The condition The root cause is in If you need correct SSA for loop analysis, one workaround is to check whether the non-SSA IR's |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
I'm trying to understand how Slither builds its SSA form in the presence of loops with internal branching. I have two simple examples and I would appreciate clarification on how the IR is constructed.
First example (simple while loop)
Command:
Output:
This makes sense to me: there's a phi node
x_2that merges the initial valuex_1and the updated onex_3, and it is used in the condition and body.Second example (loop with if/else)
Command:
Output:
In this second case, I'm trying to understand how the loop semantics are handled. Specifically:
x_4merges the two branches, but it doesn't appear to be used afterward.x > 0and the arithmetic expressions usex_1instead of a value from a phi node representing the updated value across iterations, like in the first example.In my understanding, this structure seems a bit confusing since the loop condition and arithmetic expressions continue to use the initial value x_1, it looks like the updated value (x_4) from the if/else branch isn't actually used in subsequent iterations.
Thanks in advance for any help understanding this case!
All reactions