Skip to content

Commit db9f5fd

Browse files
committed
Rust: Handle nested if expressions, address review comments
1 parent 2511986 commit db9f5fd

File tree

5 files changed

+375
-233
lines changed

5 files changed

+375
-233
lines changed

rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,30 @@ class BooleanCompletion extends ConditionalCompletion, TBooleanCompletion {
7777
override predicate isValidForSpecific(AstNode e) {
7878
e = any(IfExpr c).getCondition()
7979
or
80+
any(MatchArm arm).getGuard() = e
81+
or
8082
exists(BinaryExpr expr |
8183
expr.getOp() = ["&&", "||"] and
82-
e = [expr.getLhs(), expr.getRhs()]
84+
e = expr.getLhs()
8385
)
8486
or
85-
any(MatchArm arm).getGuard() = e
87+
exists(Expr parent | this.isValidForSpecific(parent) |
88+
parent =
89+
any(PrefixExpr expr |
90+
expr.getOp() = "!" and
91+
e = expr.getExpr()
92+
)
93+
or
94+
parent =
95+
any(BinaryExpr expr |
96+
expr.getOp() = ["&&", "||"] and
97+
e = expr.getRhs()
98+
)
99+
or
100+
parent = any(IfExpr ie | e = [ie.getThen(), ie.getElse()])
101+
or
102+
parent = any(BlockExpr be | e = be.getTail())
103+
)
86104
}
87105

88106
/** Gets the dual Boolean completion. */

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class LetStmtTree extends PreOrderTree instanceof LetStmt {
273273
LetStmtTree() { not trivialPat(super.getPat()) }
274274

275275
final override predicate propagatesAbnormal(AstNode child) {
276-
child = super.getInitializer() or child = super.getElse()
276+
child = [super.getInitializer(), super.getElse()]
277277
}
278278

279279
override predicate succ(AstNode pred, AstNode succ, Completion c) {

rust/ql/lib/codeql/rust/controlflow/internal/SuccessorType.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract private class ConditionalSuccessor extends SuccessorTypeImpl {
4141
final boolean getValue() { result = value }
4242
}
4343

44-
/** A boolean control flow successor for a boolean conditon. */
44+
/** A Boolean control flow successor for a boolean conditon. */
4545
final class BooleanSuccessor extends ConditionalSuccessor, TBooleanSuccessor {
4646
BooleanSuccessor() { this = TBooleanSuccessor(value) }
4747

0 commit comments

Comments
 (0)