Skip to content

Commit cafa4bf

Browse files
committed
wip
1 parent 52dd410 commit cafa4bf

3 files changed

Lines changed: 222 additions & 459 deletions

File tree

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

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,12 @@ private module Ast implements AstSig<Location> {
291291
}
292292

293293
class Parameter extends AstNode instanceof Rust::ParamBase {
294-
AstNode getPattern() { result = this }
294+
AstNode getPattern() {
295+
result = this.(Rust::Param).getPat()
296+
or
297+
not this instanceof Rust::Param and
298+
result = this
299+
}
295300

296301
Expr getDefaultValue() { none() }
297302
}
@@ -608,35 +613,19 @@ private module Input implements InputSig1, InputSig2 {
608613

609614
class CallableContext = Void;
610615

611-
private predicate valueContext(Rust::AstNode n, ConditionKind kind) {
616+
predicate propagatesValue(Ast::AstNode child, Ast::AstNode parent) {
617+
child = parent.(Rust::BlockExpr).getStmtList().getTailExpr()
618+
or
619+
child = parent.(Rust::MatchExpr).getAnArm().getExpr()
620+
}
621+
622+
predicate inConditionalContext(Ast::AstNode n, ConditionKind kind) {
612623
kind.isBoolean() and
613624
(
614-
n = any(Rust::IfExpr e).getCondition()
615-
or
616625
n = any(Rust::WhileExpr e).getCondition()
617626
or
618627
n = any(Rust::MatchGuard g).getCondition()
619-
or
620-
n = any(Rust::BinaryLogicalOperation e).getLhs()
621-
)
622-
or
623-
exists(Rust::Expr parent | valueContext(parent, kind) |
624-
n = parent.(Rust::LogicalNotExpr).getExpr()
625-
or
626-
n = parent.(Rust::BinaryLogicalOperation).getRhs()
627-
or
628-
n = parent.(Rust::IfExpr).getABranch()
629-
or
630-
n = parent.(Rust::MatchExpr).getAnArm().getExpr()
631-
or
632-
n = parent.(Rust::BlockExpr).getStmtList().getTailExpr()
633-
or
634-
n = any(Rust::BreakExpr b | b.getTarget() = parent).getExpr()
635628
)
636-
}
637-
638-
predicate inConditionalContext(Ast::AstNode n, ConditionKind kind) {
639-
valueContext(n, kind)
640629
or
641630
kind.isMatching() and
642631
(
@@ -670,12 +659,6 @@ private module Input implements InputSig1, InputSig2 {
670659

671660
private string breakTag() { result = "[break]" }
672661

673-
private string breakValueTag(boolean value) {
674-
value = true and result = "[break-true]"
675-
or
676-
value = false and result = "[break-false]"
677-
}
678-
679662
private string tryReturnTag() { result = "[try-return]" }
680663

681664
private string patternStartTag() { result = "[pattern-start]" }
@@ -684,21 +667,12 @@ private module Input implements InputSig1, InputSig2 {
684667

685668
private string letElseDivergeTag() { result = "[let-else-diverge]" }
686669

687-
private predicate conditionalBreak(Rust::BreakExpr b) {
688-
exists(b.getExpr()) and
689-
valueContext(b.getTarget(), any(ConditionKind kind | kind.isBoolean()))
690-
}
691-
692670
predicate additionalNode(Ast::AstNode n, string tag, NormalSuccessor t) {
693671
(
694672
t instanceof DirectSuccessor and
695673
(
696674
n instanceof Rust::BreakExpr and
697-
(
698-
conditionalBreak(n) and tag = breakValueTag(_)
699-
or
700-
not conditionalBreak(n) and tag = breakTag()
701-
)
675+
tag = breakTag()
702676
or
703677
n instanceof Rust::TryExpr and tag = tryReturnTag()
704678
or
@@ -866,7 +840,6 @@ private module Input implements InputSig1, InputSig2 {
866840
n2.isAfterValue(match, t)
867841
)
868842
or
869-
not valueContext(match, _) and
870843
n1.isAfter(arm.getExpr()) and
871844
n2.isAfter(match)
872845
)
@@ -1008,13 +981,6 @@ private module Input implements InputSig1, InputSig2 {
1008981
not exists(break.getExpr()) and n2.isAdditional(break, breakTag())
1009982
)
1010983
or
1011-
conditionalBreak(break) and
1012-
exists(BooleanSuccessor t |
1013-
n1.isAfterValue(break.getExpr(), t) and
1014-
n2.isAdditional(break, breakValueTag(t.getValue()))
1015-
)
1016-
or
1017-
not conditionalBreak(break) and
1018984
n1.isAfter(break.getExpr()) and
1019985
n2.isAdditional(break, breakTag())
1020986
)
@@ -1041,11 +1007,6 @@ private module Input implements InputSig1, InputSig2 {
10411007
(
10421008
n.isAdditional(break, breakTag()) and
10431009
c.hasLabel(TTarget(break.getTarget()))
1044-
or
1045-
exists(boolean value |
1046-
n.isAdditional(break, breakValueTag(value)) and
1047-
c.hasLabel(TTargetValue(break.getTarget(), value))
1048-
)
10491010
)
10501011
)
10511012
or

0 commit comments

Comments
 (0)