Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem are you trying to solve?
Our taint analysis implementation in #493 in omitted the handling of conditional (and mutually exclusive) control flow. This leads to incorrect analysis:
For example:
The above program is currently treated as:
This leads to a flow graph that incorrectly believes the
y
at line 7 can never bealt1
because it always gets re-assigned toalt2
:What is your solution?
The technique chosen takes inspiration from static single-assignment (SSA) form and how it handles merge points in a control-flow graph (CFG).
Specifically, we introduce phi nodes to our flow graph. Phi nodes are able to encapsulate control flow constructs that have mutually exclusive branches (e.g
if/else
). Upon entering a control flow construct with branches, we record all assignments and treat them as possible. Then, when exiting the control flow construct, we reconcile/merge the possible assignments, and then redefine the variable as the phi node.Our graph then correctly becomes:
The above program represents an exhaustively-assigned variable. In the case where a variable isn't exhaustively assigned, the phi node references the definition of the variable before entering the control flow construct. For example:
Phi operands can be other phi nodes in the case of nested control flow:
Technical Details
Limitations
if (false) { y = alt1 }
will be treated as a possible execution path.Alternatives considered
What the reviewer should know
{ ... }
")