-
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.
Merge pull request #17558 from hvitved/rust/cfg-consistency-queries
Rust: Enable CFG consistency checks
- Loading branch information
Showing
26 changed files
with
165 additions
and
121 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import rust | ||
import codeql.rust.controlflow.internal.ControlFlowGraphImpl::Consistency | ||
import codeql.rust.controlflow.internal.ControlFlowGraphImpl as CfgImpl | ||
import codeql.rust.controlflow.internal.Completion | ||
|
||
/** | ||
* All `Expr` nodes are `PostOrderTree`s | ||
*/ | ||
query predicate nonPostOrderExpr(Expr e, string cls) { | ||
cls = e.getPrimaryQlClasses() and | ||
not e instanceof LetExpr and | ||
not e instanceof LogicalAndExpr and // todo | ||
not e instanceof LogicalOrExpr and | ||
exists(AstNode last, Completion c | | ||
CfgImpl::last(e, last, c) and | ||
last != e and | ||
c instanceof NormalCompletion | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
private import codeql.rust.elements.Expr | ||
private import codeql.rust.elements.BinaryExpr | ||
private import codeql.rust.elements.PrefixExpr | ||
|
||
abstract private class LogicalOperationImpl extends Expr { | ||
abstract Expr getAnOperand(); | ||
} | ||
|
||
final class LogicalOperation = LogicalOperationImpl; | ||
|
||
abstract private class BinaryLogicalOperationImpl extends BinaryExpr, LogicalOperationImpl { | ||
override Expr getAnOperand() { result = [this.getLhs(), this.getRhs()] } | ||
} | ||
|
||
final class BinaryLogicalOperation = BinaryLogicalOperationImpl; | ||
|
||
final class LogicalAndExpr extends BinaryLogicalOperationImpl, BinaryExpr { | ||
LogicalAndExpr() { this.getOperatorName() = "&&" } | ||
} | ||
|
||
final class LogicalOrExpr extends BinaryLogicalOperationImpl { | ||
LogicalOrExpr() { this.getOperatorName() = "||" } | ||
} | ||
|
||
abstract private class UnaryLogicalOperationImpl extends PrefixExpr, LogicalOperationImpl { } | ||
|
||
final class UnaryLogicalOperation = UnaryLogicalOperationImpl; | ||
|
||
final class LogicalNotExpr extends UnaryLogicalOperationImpl { | ||
LogicalNotExpr() { this.getOperatorName() = "!" } | ||
|
||
override Expr getAnOperand() { result = this.getExpr() } | ||
} |
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
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
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
10 changes: 5 additions & 5 deletions
10
rust/ql/test/extractor-tests/generated/BinaryExpr/BinaryExpr.expected
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,5 +1,5 @@ | ||
| gen_binary_expr.rs:5:5:5:9 | BinaryExpr | getNumberOfAttrs: | 0 | hasLhs: | yes | hasOperatorName: | yes | hasRhs: | yes | | ||
| gen_binary_expr.rs:6:5:6:10 | BinaryExpr | getNumberOfAttrs: | 0 | hasLhs: | yes | hasOperatorName: | yes | hasRhs: | yes | | ||
| gen_binary_expr.rs:7:5:7:10 | BinaryExpr | getNumberOfAttrs: | 0 | hasLhs: | yes | hasOperatorName: | yes | hasRhs: | yes | | ||
| gen_binary_expr.rs:8:5:8:9 | BinaryExpr | getNumberOfAttrs: | 0 | hasLhs: | yes | hasOperatorName: | yes | hasRhs: | yes | | ||
| gen_binary_expr.rs:9:5:9:10 | BinaryExpr | getNumberOfAttrs: | 0 | hasLhs: | yes | hasOperatorName: | yes | hasRhs: | yes | | ||
| gen_binary_expr.rs:5:5:5:9 | ... + ... | getNumberOfAttrs: | 0 | hasLhs: | yes | hasOperatorName: | yes | hasRhs: | yes | | ||
| gen_binary_expr.rs:6:5:6:10 | ... && ... | getNumberOfAttrs: | 0 | hasLhs: | yes | hasOperatorName: | yes | hasRhs: | yes | | ||
| gen_binary_expr.rs:7:5:7:10 | ... <= ... | getNumberOfAttrs: | 0 | hasLhs: | yes | hasOperatorName: | yes | hasRhs: | yes | | ||
| gen_binary_expr.rs:8:5:8:9 | ... = ... | getNumberOfAttrs: | 0 | hasLhs: | yes | hasOperatorName: | yes | hasRhs: | yes | | ||
| gen_binary_expr.rs:9:5:9:10 | ... += ... | getNumberOfAttrs: | 0 | hasLhs: | yes | hasOperatorName: | yes | hasRhs: | yes | |
10 changes: 5 additions & 5 deletions
10
rust/ql/test/extractor-tests/generated/BinaryExpr/BinaryExpr_getLhs.expected
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,5 +1,5 @@ | ||
| gen_binary_expr.rs:5:5:5:9 | BinaryExpr | gen_binary_expr.rs:5:5:5:5 | PathExpr | | ||
| gen_binary_expr.rs:6:5:6:10 | BinaryExpr | gen_binary_expr.rs:6:5:6:5 | PathExpr | | ||
| gen_binary_expr.rs:7:5:7:10 | BinaryExpr | gen_binary_expr.rs:7:5:7:5 | PathExpr | | ||
| gen_binary_expr.rs:8:5:8:9 | BinaryExpr | gen_binary_expr.rs:8:5:8:5 | PathExpr | | ||
| gen_binary_expr.rs:9:5:9:10 | BinaryExpr | gen_binary_expr.rs:9:5:9:5 | PathExpr | | ||
| gen_binary_expr.rs:5:5:5:9 | ... + ... | gen_binary_expr.rs:5:5:5:5 | PathExpr | | ||
| gen_binary_expr.rs:6:5:6:10 | ... && ... | gen_binary_expr.rs:6:5:6:5 | PathExpr | | ||
| gen_binary_expr.rs:7:5:7:10 | ... <= ... | gen_binary_expr.rs:7:5:7:5 | PathExpr | | ||
| gen_binary_expr.rs:8:5:8:9 | ... = ... | gen_binary_expr.rs:8:5:8:5 | PathExpr | | ||
| gen_binary_expr.rs:9:5:9:10 | ... += ... | gen_binary_expr.rs:9:5:9:5 | PathExpr | |
10 changes: 5 additions & 5 deletions
10
rust/ql/test/extractor-tests/generated/BinaryExpr/BinaryExpr_getOperatorName.expected
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,5 +1,5 @@ | ||
| gen_binary_expr.rs:5:5:5:9 | BinaryExpr | + | | ||
| gen_binary_expr.rs:6:5:6:10 | BinaryExpr | && | | ||
| gen_binary_expr.rs:7:5:7:10 | BinaryExpr | <= | | ||
| gen_binary_expr.rs:8:5:8:9 | BinaryExpr | = | | ||
| gen_binary_expr.rs:9:5:9:10 | BinaryExpr | += | | ||
| gen_binary_expr.rs:5:5:5:9 | ... + ... | + | | ||
| gen_binary_expr.rs:6:5:6:10 | ... && ... | && | | ||
| gen_binary_expr.rs:7:5:7:10 | ... <= ... | <= | | ||
| gen_binary_expr.rs:8:5:8:9 | ... = ... | = | | ||
| gen_binary_expr.rs:9:5:9:10 | ... += ... | += | |
10 changes: 5 additions & 5 deletions
10
rust/ql/test/extractor-tests/generated/BinaryExpr/BinaryExpr_getRhs.expected
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,5 +1,5 @@ | ||
| gen_binary_expr.rs:5:5:5:9 | BinaryExpr | gen_binary_expr.rs:5:9:5:9 | PathExpr | | ||
| gen_binary_expr.rs:6:5:6:10 | BinaryExpr | gen_binary_expr.rs:6:10:6:10 | PathExpr | | ||
| gen_binary_expr.rs:7:5:7:10 | BinaryExpr | gen_binary_expr.rs:7:10:7:10 | PathExpr | | ||
| gen_binary_expr.rs:8:5:8:9 | BinaryExpr | gen_binary_expr.rs:8:9:8:9 | PathExpr | | ||
| gen_binary_expr.rs:9:5:9:10 | BinaryExpr | gen_binary_expr.rs:9:10:9:10 | PathExpr | | ||
| gen_binary_expr.rs:5:5:5:9 | ... + ... | gen_binary_expr.rs:5:9:5:9 | PathExpr | | ||
| gen_binary_expr.rs:6:5:6:10 | ... && ... | gen_binary_expr.rs:6:10:6:10 | PathExpr | | ||
| gen_binary_expr.rs:7:5:7:10 | ... <= ... | gen_binary_expr.rs:7:10:7:10 | PathExpr | | ||
| gen_binary_expr.rs:8:5:8:9 | ... = ... | gen_binary_expr.rs:8:9:8:9 | PathExpr | | ||
| gen_binary_expr.rs:9:5:9:10 | ... += ... | gen_binary_expr.rs:9:10:9:10 | PathExpr | |
4 changes: 2 additions & 2 deletions
4
rust/ql/test/extractor-tests/generated/ClosureExpr/ClosureExpr_getBody.expected
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,5 +1,5 @@ | ||
| gen_closure_expr.rs:5:5:5:13 | ClosureExpr | gen_closure_expr.rs:5:9:5:13 | BinaryExpr | | ||
| gen_closure_expr.rs:5:5:5:13 | ClosureExpr | gen_closure_expr.rs:5:9:5:13 | ... + ... | | ||
| gen_closure_expr.rs:6:5:6:34 | ClosureExpr | gen_closure_expr.rs:6:26:6:34 | BlockExpr | | ||
| gen_closure_expr.rs:7:5:7:27 | ClosureExpr | gen_closure_expr.rs:7:23:7:27 | BinaryExpr | | ||
| gen_closure_expr.rs:7:5:7:27 | ClosureExpr | gen_closure_expr.rs:7:23:7:27 | ... + ... | | ||
| gen_closure_expr.rs:8:6:9:15 | ClosureExpr | gen_closure_expr.rs:9:9:9:15 | YieldExpr | | ||
| gen_closure_expr.rs:10:6:11:23 | ClosureExpr | gen_closure_expr.rs:11:17:11:23 | YieldExpr | |
4 changes: 2 additions & 2 deletions
4
rust/ql/test/extractor-tests/generated/IfExpr/IfExpr_getCondition.expected
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,2 +1,2 @@ | ||
| gen_if_expr.rs:5:5:7:5 | IfExpr | gen_if_expr.rs:5:8:5:14 | BinaryExpr | | ||
| gen_if_expr.rs:8:13:12:5 | IfExpr | gen_if_expr.rs:8:16:8:20 | BinaryExpr | | ||
| gen_if_expr.rs:5:5:7:5 | IfExpr | gen_if_expr.rs:5:8:5:14 | ... == ... | | ||
| gen_if_expr.rs:8:13:12:5 | IfExpr | gen_if_expr.rs:8:16:8:20 | ... > ... | |
2 changes: 2 additions & 0 deletions
2
rust/ql/test/extractor-tests/generated/MatchArm/CONSISTENCY/CfgConsistency.expected
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
deadEnd | ||
| gen_match_arm.rs:10:20:10:25 | ... != ... | |
2 changes: 1 addition & 1 deletion
2
rust/ql/test/extractor-tests/generated/MatchArm/MatchArm_getExpr.expected
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,4 +1,4 @@ | ||
| gen_match_arm.rs:6:9:6:29 | MatchArm | gen_match_arm.rs:6:28:6:28 | PathExpr | | ||
| gen_match_arm.rs:7:9:7:26 | MatchArm | gen_match_arm.rs:7:25:7:25 | LiteralExpr | | ||
| gen_match_arm.rs:10:9:10:35 | MatchArm | gen_match_arm.rs:10:30:10:34 | BinaryExpr | | ||
| gen_match_arm.rs:10:9:10:35 | MatchArm | gen_match_arm.rs:10:30:10:34 | ... / ... | | ||
| gen_match_arm.rs:11:9:11:15 | MatchArm | gen_match_arm.rs:11:14:11:14 | LiteralExpr | |
2 changes: 2 additions & 0 deletions
2
rust/ql/test/extractor-tests/generated/MatchExpr/CONSISTENCY/CfgConsistency.expected
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
deadEnd | ||
| gen_match_expr.rs:10:20:10:25 | ... != ... | |
6 changes: 3 additions & 3 deletions
6
rust/ql/test/extractor-tests/generated/PrefixExpr/PrefixExpr.expected
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,3 +1,3 @@ | ||
| gen_prefix_expr.rs:5:13:5:15 | PrefixExpr | getNumberOfAttrs: | 0 | hasExpr: | yes | hasOperatorName: | yes | | ||
| gen_prefix_expr.rs:6:13:6:17 | PrefixExpr | getNumberOfAttrs: | 0 | hasExpr: | yes | hasOperatorName: | yes | | ||
| gen_prefix_expr.rs:7:13:7:16 | PrefixExpr | getNumberOfAttrs: | 0 | hasExpr: | yes | hasOperatorName: | yes | | ||
| gen_prefix_expr.rs:5:13:5:15 | - ... | getNumberOfAttrs: | 0 | hasExpr: | yes | hasOperatorName: | yes | | ||
| gen_prefix_expr.rs:6:13:6:17 | ! ... | getNumberOfAttrs: | 0 | hasExpr: | yes | hasOperatorName: | yes | | ||
| gen_prefix_expr.rs:7:13:7:16 | * ... | getNumberOfAttrs: | 0 | hasExpr: | yes | hasOperatorName: | yes | |
6 changes: 3 additions & 3 deletions
6
rust/ql/test/extractor-tests/generated/PrefixExpr/PrefixExpr_getExpr.expected
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,3 +1,3 @@ | ||
| gen_prefix_expr.rs:5:13:5:15 | PrefixExpr | gen_prefix_expr.rs:5:14:5:15 | LiteralExpr | | ||
| gen_prefix_expr.rs:6:13:6:17 | PrefixExpr | gen_prefix_expr.rs:6:14:6:17 | LiteralExpr | | ||
| gen_prefix_expr.rs:7:13:7:16 | PrefixExpr | gen_prefix_expr.rs:7:14:7:16 | PathExpr | | ||
| gen_prefix_expr.rs:5:13:5:15 | - ... | gen_prefix_expr.rs:5:14:5:15 | LiteralExpr | | ||
| gen_prefix_expr.rs:6:13:6:17 | ! ... | gen_prefix_expr.rs:6:14:6:17 | LiteralExpr | | ||
| gen_prefix_expr.rs:7:13:7:16 | * ... | gen_prefix_expr.rs:7:14:7:16 | PathExpr | |
6 changes: 3 additions & 3 deletions
6
rust/ql/test/extractor-tests/generated/PrefixExpr/PrefixExpr_getOperatorName.expected
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,3 +1,3 @@ | ||
| gen_prefix_expr.rs:5:13:5:15 | PrefixExpr | - | | ||
| gen_prefix_expr.rs:6:13:6:17 | PrefixExpr | ! | | ||
| gen_prefix_expr.rs:7:13:7:16 | PrefixExpr | * | | ||
| gen_prefix_expr.rs:5:13:5:15 | - ... | - | | ||
| gen_prefix_expr.rs:6:13:6:17 | ! ... | ! | | ||
| gen_prefix_expr.rs:7:13:7:16 | * ... | * | |
3 changes: 3 additions & 0 deletions
3
rust/ql/test/library-tests/controlflow/CONSISTENCY/CfgConsistency.expected
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
deadEnd | ||
| test.rs:124:28:124:33 | ... < ... | | ||
| test.rs:139:30:141:9 | BlockExpr | |
Oops, something went wrong.