Skip to content

Conversation

@owen-mc
Copy link
Contributor

@owen-mc owen-mc commented Nov 26, 2025

This PR makes the data flow consistency checks run in CI, along with the existing consistency query UnexpectedFrontendErrors.ql. It also adds some non-controversial exclusions to the tests.

There is no particular need to review the .expected files, as they are just recording the current state of affairs. Fixing the go library to remove some of the results will be done in a follow-up PR. Hopefully we will eventually be able to remove all of the expected results for the data flow consistency checks.

One change is made to the shared library: allowing exclusions to the localFlowIsLocal query.

Copilot AI review requested due to automatic review settings November 26, 2025 11:13
@owen-mc owen-mc requested review from a team as code owners November 26, 2025 11:13
@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label Nov 26, 2025
Copilot finished reviewing on behalf of owen-mc November 26, 2025 11:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables data flow consistency checks to run in CI for the Go codebase. The main changes include:

  • Adding a new localFlowIsLocalExclude predicate to the shared data flow consistency library
  • Implementing Go-specific exclusions for known consistency check violations
  • Moving consistency queries to a new ql/consistency-queries directory
  • Adding .expected files documenting current violations (to be fixed in future PRs)

Reviewed changes

Copilot reviewed 71 out of 72 changed files in this pull request and generated no comments.

Show a summary per file
File Description
shared/dataflow/codeql/dataflow/internal/DataFlowImplConsistency.qll Adds localFlowIsLocalExclude predicate to allow language-specific exclusions for the localFlowIsLocal consistency check
go/ql/lib/semmle/go/dataflow/internal/DataFlowImplConsistency.qll Implements Go-specific exclusion predicates for consistency checks including localFlowIsLocalExclude, missingLocationExclude, uniqueNodeLocationExclude, and argHasPostUpdateExclude
go/ql/consistency-queries/UnexpectedFrontendErrors.ql New consistency query that reports all frontend extraction errors
go/Makefile Updates test target to use new consistency query location ql/consistency-queries instead of ql/test/consistency
go/ql/test/consistency/dummy.ql Adds dummy query to ensure consistency tests run in the test directory
go/ql/test/consistency/dummy.expected Expected output for the dummy query
go/ql/test/consistency/UnexpectedFrontendErrors.expected Removed (moved to CONSISTENCY subdirectory)
Multiple DataFlowConsistency.expected files Documents current data flow consistency violations across test cases (reverseRead and identityLocalStep issues)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@owen-mc owen-mc removed documentation no-change-note-required This PR does not need a change note labels Nov 26, 2025
predicate uniqueNodeLocationExclude(DataFlow::Node n) { missingLocationExclude(n) }

predicate localFlowIsLocalExclude(DataFlow::Node n1, DataFlow::Node n2) {
n1 instanceof DataFlow::FunctionNode and exists(n2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thats a large CP. Also, can you elaborate what such steps are for?

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've fixed the CP by adding the constraint simpleLocalFlowStep(n1, n2, _), which is in the only place that this predicate is used.

I didn't immediatley know why we have these steps, but after thinking for a little bit I think I have figured it out. In go you can assign functions to variables and pass them around. It isn't that common but we should deal with it, at least locally. So we use local data flow to find possible callees - for example if you click through Function.getACall() you will get to this line. It's very useful to have steps from function definitions to uses of them as part of the local flow relation so that we can do this without having to use global flow.

@@ -0,0 +1 @@
select "This is a dummy query which is only needed so that the consistency tests will run"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why this is needed; consistency queries are supposed to run on all QL tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test folder exists just to check that UnexpectedFrontendErrors.ql, which used to be the only consistency query, is working, so there are no other .ql files in the folder, and by moving UnexpectedFrontendErrors.ql to be in the same folder as the data flow consistency queries I was leaving the folder without a test query file. I tried without adding another test query and it said it found no tests. I guess it needs a .ql or .qlref file to exist so that it will build a db and run a test, and then run the consistency queries on the db as well.

predicate argHasPostUpdateExclude(DataFlow::ArgumentNode n) {
not DataFlow::insnHasPostUpdateNode(n.asInstruction())
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you forget to add the DataFlowConsistency.ql file?

Copy link
Contributor Author

@owen-mc owen-mc Nov 26, 2025

Choose a reason for hiding this comment

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

It already exists, so you won't see it in this PR. I made it a while ago but didn't set up CI to run it because there were so many results due to not using use-use flow at the time.

This is needed because a PR to another repo is needed to update the
location of the consistency queries, and until that PR is merged we
don't want to runny dummy.ql as a consistency query. After that PR is
merged we should reinstate these files so that consistency tests are
run on this test folder.
@owen-mc owen-mc added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Nov 26, 2025
@owen-mc
Copy link
Contributor Author

owen-mc commented Nov 26, 2025

I didn't realise this, but the path to the consistency queries also needs to be updated in an internal PR. Until that is merged I have deleted dummy.ql, as some of the CI checks think that that is the consistency query. I will reinstate it afterwards so that tests are run in that folder.

@owen-mc owen-mc removed the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Nov 26, 2025
@owen-mc owen-mc requested a review from hvitved November 26, 2025 21:15
@owen-mc
Copy link
Contributor Author

owen-mc commented Nov 27, 2025

Correction: the consistency checks used in CI are set in an internal repository, so the change made to the makefile here is only relevant for local testing. However, the companion PR to this in the internal repo has all the go tests passing, which is evidence that I have committed the correct DataFlowConsistency.expected files. I think it works to merge this PR, then merge that one to actually change what consistency checks are running in CI.

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.

2 participants