C#: Add tests for extractor fixes, and improve CFG for ConstCases#163
Merged
Conversation
- While statements - Object initializers
…andled. Move `getCondition` to `CaseStmt`. Implement the CFG and tests.
ce42d4d to
3718237
Compare
hvitved
requested changes
Sep 6, 2018
Contributor
hvitved
left a comment
There was a problem hiding this comment.
Very nice! Just a few remarks.
hvitved
reviewed
Sep 7, 2018
Contributor
hvitved
left a comment
There was a problem hiding this comment.
Two more comments, but nothing urgent, so happy to merge as is.
| // Flow from the last element of case expression to the condition | ||
| cfe = lastConstCaseExpr(cc, c) and | ||
| c.(MatchingCompletion).isMatch() and | ||
| result = first(cc.getCondition()) |
Contributor
There was a problem hiding this comment.
I am sure I wrote this originally, but github seems to have thrown my comment away:
I would replace
// Flow from last element of case expression to first element of statement
not exists(cc.getCondition()) and
cfe = lastConstCaseExpr(cc, c) and
c.(MatchingCompletion).isMatch() and
result = first(cc.getStmt())
or
// Flow from the last element of case expression to the condition
cfe = lastConstCaseExpr(cc, c) and
c.(MatchingCompletion).isMatch() and
result = first(cc.getCondition())
with
cfe = lastConstCaseExpr(cc, c) and
c.(MatchingCompletion).isMatch() and
if exists(cc.getCondition()) then
// Flow from the last element of case expression to the condition
result = first(cc.getCondition())
else
// Flow from last element of case expression to first element of statement
result = first(cc.getStmt())
| private ControlFlowElement lastCaseStmt(CaseStmt cs, Completion c) { | ||
| result = last(cs.(TypeCase).getStmt(), c) | ||
| or | ||
| result = last(cs.(ConstCase).getStmt(), c) |
Contributor
There was a problem hiding this comment.
Could replace with
result = last(cs.(LabeledStmt).getStmt(), c)
Feel free to change if you like.
Contributor
Author
There was a problem hiding this comment.
I did that initially but additional edges appeared.
hvitved
approved these changes
Sep 7, 2018
aibaars
added a commit
that referenced
this pull request
Oct 14, 2021
Ignore include/prepend statements in blocks
smowton
pushed a commit
to smowton/codeql
that referenced
this pull request
Jan 17, 2022
Kotlin: Add comments saying what generated TRAP files
MathiasVP
pushed a commit
to MathiasVP/ql
that referenced
this pull request
Aug 10, 2025
…brary-after-2.20.4 PS: Fixup CFG library in preparation for 2.20.4
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These tests will not pass until the corresponding extractor changes have been merged.
Move the
getCondition()predicate fromConstCasetoCaseStmt, because const cases can also havewhenparts, that were not previously extracted.Implement the CFG for
ConstCasesthat have awhenpart.Add some regression tests for extractor fixes.