-
Notifications
You must be signed in to change notification settings - Fork 1.9k
JS: recognize more conditionals in useless-conditional #404
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
ghost
left a comment
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.
That is an impressive amount of new alerts, well spotted!
I have one suggestion for additional alerts, but given the current PR pressure on the js/trivial-conditional query, we may want to wait with that.
| e = cond.(LogOrExpr).getLeftOperand() | ||
| e = cond.(LogicalBinaryExpr).getLeftOperand() or | ||
| // Include `z` in `if (x && z)`. | ||
| isConditional(_, cond) and e = cond.(LogicalBinaryExpr).getRightOperand() |
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.
I think we should squeeze this syntactic pattern a bit more: cond.getUnderlyingValue().(LogicalBinaryExpr).getRightOperand().
xiemaisi
left a comment
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.
LGTM, one suggestion.
| predicate isConditional(ASTNode cond, Expr e) { | ||
| e = cond.(IfStmt).getCondition() or | ||
| e = cond.(WhileStmt).getExpr() or | ||
| e = cond.(ForStmt).getTest() or |
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 about just generalising all the way to LoopStmt.getTest()? Or do we not want this to cover DoWhileStmt.getTest()?
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.
I noticed EphemeralLoop.ql whitelists do-while because of Emscripten, so I thought we'd run into the same issue 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.
That's entirely possible.
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.
Actually it looks like I got that backwards. EphemeralLoop.ql whitelists Emscripten-generated files because of do {} while(0), but this query already whitelists constants, so it shouldn't be a problem.
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.
Updated to use LoopStmt
|
Conflicts. |
96948b0 to
87e0027
Compare
|
Rebased. I've also opened ODASA-7450 for the change note, to be authored once all the changes to UselessConditional are in. |
Reimplements the following two improvements to Useless Conditional from #380:
zinif (x && z)as a conditional. Previously onlyxandx && zwere recognised.Evaluation.