Skip to content

Conversation

calumgrant
Copy link
Contributor

These tests will not pass until the corresponding extractor changes have been merged.

Move the getCondition() predicate from ConstCase to CaseStmt, because const cases can also have when parts, that were not previously extracted.

Implement the CFG for ConstCases that have a when part.

Add some regression tests for extractor fixes.

@calumgrant calumgrant added the C# label Sep 5, 2018
@calumgrant calumgrant added this to the 1.18 milestone Sep 5, 2018
@calumgrant calumgrant requested a review from hvitved September 5, 2018 16:11
@calumgrant calumgrant requested a review from a team as a code owner September 5, 2018 16:11
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Just a few remarks.

Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could replace with

result = last(cs.(LabeledStmt).getStmt(), c)

Feel free to change if you like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that initially but additional edges appeared.

@hvitved hvitved merged commit f3eed4a into github:rc/1.18 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants