-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rust: Add a few control flow tree classes
- Loading branch information
Showing
4 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,47 @@ | ||
private import rust | ||
import ControlFlowGraphImplSpecific::CfgImpl | ||
import Completion | ||
|
||
class CallTree extends StandardPostOrderTree instanceof Call { | ||
override ControlFlowTree getChildNode(int i) { result = super.getArg(i) } | ||
} | ||
|
||
class BinaryOpTree extends StandardPostOrderTree instanceof BinaryOp { | ||
override ControlFlowTree getChildNode(int i) { | ||
i = 0 and result = super.getLhs() | ||
or | ||
i = 1 and result = super.getRhs() | ||
} | ||
} | ||
|
||
class IfTree extends PostOrderTree instanceof If { | ||
override predicate first(AstNode node) { first(super.getCondition(), node) } | ||
|
||
override predicate propagatesAbnormal(AstNode child) { none() } | ||
|
||
override predicate succ(AstNode pred, AstNode succ, Completion c) { | ||
// Edges from the condition to each branch | ||
last(super.getCondition(), pred, c) and | ||
( | ||
first(super.getThen(), succ) and c.(BooleanCompletion).getValue() = true | ||
or | ||
first(super.getElse(), succ) and c.(BooleanCompletion).getValue() = false | ||
) | ||
or | ||
// An edge from the then branch to the last node | ||
last(super.getThen(), pred, c) and | ||
succ = this and | ||
completionIsSimple(c) | ||
or | ||
// An edge from the else branch to the last node | ||
last(super.getElse(), pred, c) and | ||
succ = this and | ||
completionIsSimple(c) | ||
} | ||
} | ||
|
||
class LetTree extends StandardPostOrderTree instanceof Let { | ||
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() } | ||
} | ||
|
||
class LiteralTree extends LeafTree instanceof Literal { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
rust/ql/lib/codeql/rust/controlflow/internal/SuccessorType.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters