Skip to content

Commit 07f6685

Browse files
hvitvedCopilot
andcommitted
Fix Rust shared CFG CI failures
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fd06e4a commit 07f6685

9 files changed

Lines changed: 153 additions & 157 deletions

File tree

‎rust/ql/lib/codeql/rust/controlflow/BasicBlocks.qll‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,30 @@ private import internal.ControlFlowGraphImpl as CfgImpl
77

88
class BasicBlock = CfgImpl::Cfg::BasicBlock;
99

10+
/** A basic block containing the entry node of a callable. */
1011
final class EntryBasicBlock extends BasicBlock {
1112
EntryBasicBlock() { this.getFirstNode() instanceof CfgImpl::ControlFlow::EntryNode }
1213
}
1314

15+
/** A basic block containing the final exit node of a callable. */
1416
final class ExitBasicBlock extends BasicBlock {
1517
ExitBasicBlock() { this.getLastNode() instanceof CfgImpl::ControlFlow::ExitNode }
1618
}
1719

20+
/** A basic block containing an annotated normal or exceptional exit node. */
1821
final class AnnotatedExitBasicBlock extends BasicBlock {
19-
AnnotatedExitBasicBlock() {
20-
this.getANode() instanceof CfgImpl::ControlFlow::AnnotatedExitNode
21-
}
22+
AnnotatedExitBasicBlock() { this.getANode() instanceof CfgImpl::ControlFlow::AnnotatedExitNode }
2223

2324
/** Holds if this block represents normal exit. */
24-
predicate isNormal() {
25-
this.getANode() instanceof CfgImpl::ControlFlow::NormalExitNode
26-
}
25+
predicate isNormal() { this.getANode() instanceof CfgImpl::ControlFlow::NormalExitNode }
2726
}
2827

28+
/** A basic block whose last node is a condition. */
2929
final class ConditionBasicBlock extends BasicBlock {
3030
ConditionBasicBlock() { this.getLastNode().(ControlFlowGraph::CfgNode).isCondition() }
3131
}
3232

33+
/** A basic block whose first node joins multiple predecessors. */
3334
final class JoinBasicBlock extends BasicBlock {
3435
JoinBasicBlock() { this.getFirstNode().(ControlFlowGraph::CfgNode).isJoin() }
3536

@@ -46,6 +47,7 @@ final class JoinBasicBlock extends BasicBlock {
4647
}
4748
}
4849

50+
/** A predecessor basic block of a join block. */
4951
final class JoinPredecessorBasicBlock extends BasicBlock {
5052
JoinPredecessorBasicBlock() { this.getASuccessor() instanceof JoinBasicBlock }
5153
}

‎rust/ql/lib/codeql/rust/controlflow/CfgNodes.qll‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class AstCfgNode extends CfgNode {
1818
AstNode getAstNode() { this.injects(result) }
1919
}
2020

21-
class ExitCfgNode extends CfgNode instanceof ControlFlow::ExitNode {
22-
}
21+
/** A CFG node representing the final exit from a callable. */
22+
class ExitCfgNode extends CfgNode instanceof ControlFlow::ExitNode { }
2323

24-
class AnnotatedExitCfgNode extends CfgNode instanceof ControlFlow::AnnotatedExitNode {
25-
}
24+
/** A CFG node representing a normal or exceptional exit from a callable. */
25+
class AnnotatedExitCfgNode extends CfgNode instanceof ControlFlow::AnnotatedExitNode { }
2626

2727
/** A variable access. */
2828
final class VariableAccessCfgNode extends PathExprBaseCfgNode {

‎rust/ql/lib/codeql/rust/controlflow/ControlFlowGraph.qll‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class CfgNode extends CfgImpl::ControlFlowNode {
1313
CfgScope getScope() { result = this.getEnclosingCallable() }
1414

1515
/** Holds if this node has conditional successors. */
16-
predicate isCondition() {
17-
exists(this.getASuccessor(any(ConditionalSuccessor t)))
18-
}
16+
predicate isCondition() { exists(this.getASuccessor(any(ConditionalSuccessor t))) }
1917

2018
/** Holds if this node has more than one predecessor. */
2119
predicate isJoin() { strictcount(this.getAPredecessor()) > 1 }

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ private predicate successfullyExtractedFile(File f) {
1313
not exists(ExtractionWarning warning | warning.getLocation().getFile() = f)
1414
}
1515

16-
query predicate missingCfgChild(
17-
CfgImpl::ControlFlowNode parent, string pred, int i, AstNode child
18-
) {
16+
query predicate missingCfgChild(CfgImpl::ControlFlowNode parent, string pred, int i, AstNode child) {
1917
CfgNodes::missingCfgChild(parent, pred, i, child) and
2018
successfullyExtractedFile(child.getLocation().getFile())
2119
}

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,19 @@ class MatchExprChildMapping extends ParentAstNode, MatchExpr {
3434
}
3535

3636
class BlockExprChildMapping extends ParentAstNode, BlockExpr {
37-
override predicate relevantChild(AstNode child) {
38-
child = this.getStmtList().getTailExpr()
39-
}
37+
override predicate relevantChild(AstNode child) { child = this.getStmtList().getTailExpr() }
4038
}
4139

4240
class BreakExprTargetChildMapping extends ParentAstNode, Expr {
43-
override predicate relevantChild(AstNode child) {
44-
child.(BreakExpr).getTarget() = this
45-
}
41+
override predicate relevantChild(AstNode child) { child.(BreakExpr).getTarget() = this }
4642
}
4743

4844
class CallExprChildMapping extends ParentAstNode, CallExpr {
49-
override predicate relevantChild(AstNode child) {
50-
child = this.getArgList().getAnArg()
51-
}
45+
override predicate relevantChild(AstNode child) { child = this.getArgList().getAnArg() }
5246
}
5347

5448
class MethodCallExprChildMapping extends ParentAstNode, MethodCallExpr {
55-
override predicate relevantChild(AstNode child) {
56-
child = this.getArgList().getAnArg()
57-
}
49+
override predicate relevantChild(AstNode child) { child = this.getArgList().getAnArg() }
5850
}
5951

6052
class StructExprChildMapping extends ParentAstNode, StructExpr {
@@ -70,9 +62,7 @@ class StructPatChildMapping extends ParentAstNode, StructPat {
7062
}
7163

7264
class MacroCallChildMapping extends ParentAstNode, MacroCall {
73-
override predicate relevantChild(AstNode child) {
74-
child = this.getMacroCallExpansion()
75-
}
65+
override predicate relevantChild(AstNode child) { child = this.getMacroCallExpansion() }
7666
}
7767

7868
class FormatArgsExprChildMapping extends ParentAstNode, FormatArgsExpr {
@@ -104,9 +94,7 @@ class AssignmentExprChildMapping extends ParentAstNode, AssignmentExpr {
10494
}
10595

10696
private class ChildMappingImpl extends ChildMapping {
107-
override predicate hasCfgChild(
108-
AstNode parent, AstNode child, AstCfgNode cfn, AstCfgNode cfnChild
109-
) {
97+
override predicate hasCfgChild(AstNode parent, AstNode child, AstCfgNode cfn, AstCfgNode cfnChild) {
11098
Stages::CfgStage::ref() and
11199
this.relevantChild(parent, child) and
112100
cfn.getAstNode() = CfgNodesInput::getDesugared(parent) and

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

Lines changed: 30 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ private module Ast implements AstSig<Location> {
279279
result = parent.(Rust::TupleStructPat).getField(index)
280280
}
281281

282-
AstNode getChild(AstNode parent, int index) {
283-
result = desugar(runtimeChild(parent, index))
284-
}
282+
AstNode getChild(AstNode parent, int index) { result = desugar(runtimeChild(parent, index)) }
285283

286284
private Callable getEnclosingCallableImpl(Rust::AstNode node) {
287285
exists(Rust::AstNode parent | parent = node.getParentNode() |
@@ -302,8 +300,7 @@ private module Ast implements AstSig<Location> {
302300

303301
Callable getEnclosingCallable(AstNode node) { result = getEnclosingCallableImpl(node) }
304302

305-
class Callable extends AstNode instanceof Scope::CfgScope {
306-
}
303+
class Callable extends AstNode instanceof Scope::CfgScope { }
307304

308305
AstNode callableGetBody(Callable c) {
309306
result = c.(Rust::Callable).getBody()
@@ -426,8 +423,7 @@ private module Ast implements AstSig<Location> {
426423
BreakStmt() { none() }
427424
}
428425

429-
class ContinueStmt extends Stmt instanceof Rust::ContinueExpr {
430-
}
426+
class ContinueStmt extends Stmt instanceof Rust::ContinueExpr { }
431427

432428
class GotoStmt extends Stmt {
433429
GotoStmt() { none() }
@@ -503,11 +499,9 @@ private module Ast implements AstSig<Location> {
503499
Expr getRightOperand() { result = desugar(this.(Rust::BinaryExpr).getRhs()) }
504500
}
505501

506-
class LogicalAndExpr extends BinaryExpr instanceof Rust::LogicalAndExpr {
507-
}
502+
class LogicalAndExpr extends BinaryExpr instanceof Rust::LogicalAndExpr { }
508503

509-
class LogicalOrExpr extends BinaryExpr instanceof Rust::LogicalOrExpr {
510-
}
504+
class LogicalOrExpr extends BinaryExpr instanceof Rust::LogicalOrExpr { }
511505

512506
class NullCoalescingExpr extends BinaryExpr {
513507
NullCoalescingExpr() { none() }
@@ -517,17 +511,13 @@ private module Ast implements AstSig<Location> {
517511
Expr getOperand() { result = desugar(this.(Rust::PrefixExpr).getExpr()) }
518512
}
519513

520-
class LogicalNotExpr extends UnaryExpr instanceof Rust::LogicalNotExpr {
521-
}
514+
class LogicalNotExpr extends UnaryExpr instanceof Rust::LogicalNotExpr { }
522515

523-
class Assignment extends BinaryExpr instanceof Rust::AssignmentOperation {
524-
}
516+
class Assignment extends BinaryExpr instanceof Rust::AssignmentOperation { }
525517

526-
class AssignExpr extends Assignment instanceof Rust::AssignmentExpr {
527-
}
518+
class AssignExpr extends Assignment instanceof Rust::AssignmentExpr { }
528519

529-
class CompoundAssignment extends Assignment instanceof Rust::CompoundAssignmentExpr {
530-
}
520+
class CompoundAssignment extends Assignment instanceof Rust::CompoundAssignmentExpr { }
531521

532522
class AssignLogicalAndExpr extends CompoundAssignment {
533523
AssignLogicalAndExpr() { none() }
@@ -608,15 +598,11 @@ private predicate guaranteedMatch(Rust::Pat pat) {
608598
private module Input implements InputSig1, InputSig2 {
609599
private import codeql.util.Void
610600

611-
predicate cfgCachedStageRef() {
612-
CfgCachedStage::ref()
613-
}
601+
predicate cfgCachedStageRef() { CfgCachedStage::ref() }
614602

615603
private newtype TLabel =
616604
TTarget(Rust::Expr target) or
617-
TTargetValue(Rust::Expr target, boolean value) {
618-
value = true or value = false
619-
}
605+
TTargetValue(Rust::Expr target, boolean value) { value = true or value = false }
620606

621607
class Label extends TLabel {
622608
string toString() {
@@ -804,17 +790,12 @@ private module Input implements InputSig1, InputSig2 {
804790
)
805791
}
806792

807-
private predicate isAfterMatch(
808-
PreControlFlowNode n, Rust::AstNode ast, boolean value
809-
) {
810-
n.isAfterValue(Ast::desugar(ast),
811-
any(MatchingSuccessor t | t.getValue() = value))
793+
private predicate isAfterMatch(PreControlFlowNode n, Rust::AstNode ast, boolean value) {
794+
n.isAfterValue(Ast::desugar(ast), any(MatchingSuccessor t | t.getValue() = value))
812795
}
813796

814797
private predicate parameterStep(PreControlFlowNode n1, PreControlFlowNode n2) {
815-
exists(Rust::ParamBase p, Ast::AstNode child |
816-
child = Ast::getChild(p, _)
817-
|
798+
exists(Rust::ParamBase p, Ast::AstNode child | child = Ast::getChild(p, _) |
818799
n1.isBefore(p) and n2.isBefore(child)
819800
or
820801
p instanceof Rust::Param and
@@ -864,15 +845,11 @@ private module Input implements InputSig1, InputSig2 {
864845
)
865846
}
866847

867-
private predicate matchArmStart(
868-
Rust::MatchExpr match, int index, PreControlFlowNode n
869-
) {
848+
private predicate matchArmStart(Rust::MatchExpr match, int index, PreControlFlowNode n) {
870849
n.isBefore(Ast::desugar(match.getArm(index).getPat()))
871850
}
872851

873-
private predicate matchArmBodyStart(
874-
Rust::MatchArm arm, PreControlFlowNode n
875-
) {
852+
private predicate matchArmBodyStart(Rust::MatchArm arm, PreControlFlowNode n) {
876853
n.isBefore(Ast::desugar(arm.getGuard().getCondition()))
877854
or
878855
not arm.hasGuard() and n.isBefore(Ast::desugar(arm.getExpr()))
@@ -914,9 +891,7 @@ private module Input implements InputSig1, InputSig2 {
914891
)
915892
}
916893

917-
private predicate genericPatternStep(
918-
Rust::Pat pat, PreControlFlowNode n1, PreControlFlowNode n2
919-
) {
894+
private predicate genericPatternStep(Rust::Pat pat, PreControlFlowNode n1, PreControlFlowNode n2) {
920895
not pat instanceof Rust::IdentPat and
921896
not pat instanceof Rust::LiteralPat and
922897
not pat instanceof Rust::OrPat and
@@ -981,9 +956,7 @@ private module Input implements InputSig1, InputSig2 {
981956
n1.isIn(pat) and not guaranteedMatch(pat) and isAfterMatch(n2, pat, false)
982957
}
983958

984-
private predicate orPatternStep(
985-
Rust::OrPat pat, PreControlFlowNode n1, PreControlFlowNode n2
986-
) {
959+
private predicate orPatternStep(Rust::OrPat pat, PreControlFlowNode n1, PreControlFlowNode n2) {
987960
n1.isBefore(pat) and n2.isBefore(Ast::desugar(getRankedPatternChild(pat, 1)))
988961
or
989962
exists(int i, Rust::Pat child | child = getRankedPatternChild(pat, i) |
@@ -1002,13 +975,16 @@ private module Input implements InputSig1, InputSig2 {
1002975

1003976
private predicate patternStep(PreControlFlowNode n1, PreControlFlowNode n2) {
1004977
exists(Rust::Pat pat |
1005-
genericPatternStep(pat, n1, n2)
1006-
or
1007-
literalPatternStep(pat, n1, n2)
1008-
or
1009-
identPatternStep(pat, n1, n2)
1010-
or
1011-
orPatternStep(pat, n1, n2)
978+
Ast::desugar(pat) = pat and
979+
(
980+
genericPatternStep(pat, n1, n2)
981+
or
982+
literalPatternStep(pat, n1, n2)
983+
or
984+
identPatternStep(pat, n1, n2)
985+
or
986+
orPatternStep(pat, n1, n2)
987+
)
1012988
)
1013989
}
1014990

@@ -1110,15 +1086,11 @@ private module Input implements InputSig1, InputSig2 {
11101086
always = true
11111087
}
11121088

1113-
private predicate targetChild(
1114-
Rust::Expr target, Ast::AstNode child
1115-
) {
1089+
private predicate targetChild(Rust::Expr target, Ast::AstNode child) {
11161090
child = Ast::getChild(target, _)
11171091
}
11181092

1119-
predicate endAbruptCompletion(
1120-
Ast::AstNode ast, PreControlFlowNode n, AbruptCompletion c
1121-
) {
1093+
predicate endAbruptCompletion(Ast::AstNode ast, PreControlFlowNode n, AbruptCompletion c) {
11221094
exists(Rust::Expr target |
11231095
targetChild(target, ast) and
11241096
c.getSuccessorType() instanceof BreakSuccessor

‎rust/ql/src/queries/unusedentities/UnreachableCode.ql‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,13 @@ private AstNode desugar(AstNode n) {
3030
*
3131
* The shared control-flow library only creates nodes for reachable code.
3232
*/
33-
private predicate reachable(AstNode n) {
34-
any(CfgNode cfg).getAstNode() = desugar(n)
35-
}
33+
private predicate reachable(AstNode n) { any(CfgNode cfg).getAstNode() = desugar(n) }
3634

3735
/** Holds if normal execution of `n` reaches its after-node. */
38-
private predicate reachesAfter(AstNode n) {
39-
any(CfgNode cfg).isAfter(desugar(n))
40-
}
36+
private predicate reachesAfter(AstNode n) { any(CfgNode cfg).isAfter(desugar(n)) }
4137

4238
/** Holds if `n` is a direct element of a statement list. */
43-
private predicate statementListElement(AstNode n) {
44-
n = any(StmtList list).getStmtOrExpr(_)
45-
}
39+
private predicate statementListElement(AstNode n) { n = any(StmtList list).getStmtOrExpr(_) }
4640

4741
/** Holds if `n` is a statement-list element that executes at runtime. */
4842
private predicate runtimeStatementListElement(AstNode n) {

0 commit comments

Comments
 (0)