Skip to content

Go: Add and use exprRefersToNil predicate#21466

Merged
owen-mc merged 1 commit intogithub:mainfrom
owen-mc:go/add-nil-helper-predicate
Mar 12, 2026
Merged

Go: Add and use exprRefersToNil predicate#21466
owen-mc merged 1 commit intogithub:mainfrom
owen-mc:go/add-nil-helper-predicate

Conversation

@owen-mc
Copy link
Contributor

@owen-mc owen-mc commented Mar 12, 2026

This PR adds a help predicate for expressions which refer to the built-in constant nil. This was done in several places in the code, but I think having a helper predicate will make it more discoverable, and give it an explanatory QLDoc.

Also, we tweak the QL used to specify that the Expr will be a ConstantName, which makes life slightly easier for the evaluator (but not enough to be noticeable in DCA).

@owen-mc owen-mc requested a review from a team March 12, 2026 13:39
@owen-mc owen-mc requested a review from a team as a code owner March 12, 2026 13:39
Copilot AI review requested due to automatic review settings March 12, 2026 13:39
@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label Mar 12, 2026
@github-actions github-actions bot added the Go label Mar 12, 2026
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 factors out repeated checks for expressions referring to Go’s built-in nil into a shared helper predicate (exprRefersToNil) in the Go standard library, and updates existing queries/libs to use it. This improves discoverability and centralizes the definition used across multiple analyses.

Changes:

  • Add exprRefersToNil(Expr) (with QLDoc) to the Go expression library.
  • Replace several direct Builtin::nil().getAReference() comparisons with the new helper predicate.
  • Slightly tighten the pattern used for nil references by routing through the ConstantName representation.

Reviewed changes

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

Show a summary per file
File Description
go/ql/src/experimental/CWE-203/Timing.ql Uses the shared helper to exclude nil comparisons in timing-attack sink logic.
go/ql/src/RedundantCode/UnreachableStatement.ql Uses the helper when allowlisting return nil-style unreachable returns.
go/ql/lib/semmle/go/dataflow/internal/TaintTrackingUtil.qll Uses the helper in taint-tracking utilities when reasoning about nil return expressions.
go/ql/lib/semmle/go/dataflow/internal/DataFlowUtil.qll Uses the helper in return-value reasoning predicates (nil/non-nil).
go/ql/lib/semmle/go/dataflow/Properties.qll Uses the helper for the IsNil property check on expressions.
go/ql/lib/semmle/go/Expr.qll Introduces exprRefersToNil predicate with documentation and uses it in type-expression logic.

You can also share your feedback on Copilot code review. Take the survey.

@owen-mc
Copy link
Contributor Author

owen-mc commented Mar 12, 2026

DCA was uneventful.

Copy link
Member

@igfoo igfoo left a comment

Choose a reason for hiding this comment

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

LGTM

@owen-mc owen-mc merged commit 0bb6ff5 into github:main Mar 12, 2026
28 checks passed
@owen-mc owen-mc deleted the go/add-nil-helper-predicate branch March 12, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Go no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants