-
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
Conversation
@@ -0,0 +1,33 @@ | |||
private import codeql.rust.elements.Expr |
Check warning
Code scanning / CodeQL
Redundant import Warning
codeql.rust.elements.BinaryExpr
Redundant import, the module is already imported inside
codeql.rust.elements.PrefixExpr
16c74aa
to
0b0b87e
Compare
0b0b87e
to
cbc2389
Compare
@@ -22,5 +21,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 comment
The reason will be displayed to describe this comment to others. Learn more.
We should perhaps allow specifying a toString
implementation in the schema
so they can be generated.
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.
How is that easier than doing it here?
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.
Instead of editing many files, you can do it all in one file. We may even be able to generate pretty sensible default toString
implementations from the rust.ungram
file.
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.
Sensible default toString
s would be nice. However, I think this would be the right place to override them; this is also where one would add additional predicates.
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.
Looks good to me. Some minor suggestions and questions.
If you want you could also run the consistency queries against rustlang/rust
at some point. Their test suite is rather extensive covering all of the language.
@@ -73,7 +73,7 @@ class BecomeExprTree extends StandardPostOrderTree instanceof BecomeExpr { | |||
} | |||
|
|||
class BinaryOpExprTree extends StandardPostOrderTree instanceof BinaryExpr { | |||
BinaryOpExprTree() { super.getOperatorName() != "&&" and super.getOperatorName() != "||" } | |||
BinaryOpExprTree() { not this instanceof LogicalOrExpr and not this instanceof LogicalAndExpr } |
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.
This would be slightly shorter, not sure if it is better though.
BinaryOpExprTree() { not this instanceof LogicalOrExpr and not this instanceof LogicalAndExpr } | |
BinaryOpExprTree() { not this instanceof LogicalOperation } |
query predicate nonPostOrderExpr(Expr e, string cls) { | ||
cls = e.getPrimaryQlClasses() and | ||
not e instanceof LetExpr and | ||
not e instanceof LogicalAndExpr and // todo |
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.
@@ -22,5 +21,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 comment
The 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 toString
implementations from the rust.ungram
file.
Commit-by-commit review suggested.