-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Enable CFG consistency checks #17558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3bd5c6e
8c956e8
f428fdc
d299380
cbc2389
79620c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
private import codeql.rust.elements.Expr | ||
Check warningCode scanning / CodeQL Redundant import Warning
Redundant import, the module is already imported inside
codeql.rust.elements.BinaryExpr Error loading related location Loading Redundant import, the module is already imported inside codeql.rust.elements.PrefixExpr Error loading related location Loading |
||
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() } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// generated by codegen, remove this comment if you wish to edit this file | ||
/** | ||
* This module provides a hand-modifiable wrapper around the generated class `BinaryExpr`. | ||
* | ||
|
@@ -12,6 +11,7 @@ private import codeql.rust.elements.internal.generated.BinaryExpr | |
* be referenced directly. | ||
*/ | ||
module Impl { | ||
// the following QLdoc is generated: if you need to edit it, do it in the schema file | ||
/** | ||
* A binary operation expression. For example: | ||
* ```rust | ||
|
@@ -22,5 +22,7 @@ module Impl { | |
* x += y; | ||
* ``` | ||
*/ | ||
class BinaryExpr extends Generated::BinaryExpr { } | ||
class BinaryExpr extends Generated::BinaryExpr { | ||
override string toString() { result = "... " + this.getOperatorName() + " ..." } | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should perhaps allow specifying a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is that easier than doing it here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of editing many files, you can do it all in one file. We may even be able to generate pretty sensible default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sensible default |
||
} |
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 | |
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 | |
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 | ... += ... | += | |
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 | |
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 | |
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 | ... > ... | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
deadEnd | ||
| gen_match_arm.rs:10:20:10:25 | ... != ... | |
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 | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
deadEnd | ||
| gen_match_expr.rs:10:20:10:25 | ... != ... | |
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 | |
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 | |
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 | * ... | * | |
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 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
LogicalNotExpr
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet modeled in the CFG.