Skip to content

Unified: Add Guards instantiation. - #23350

Open
aschackmull wants to merge 3 commits into
github:mainfrom
aschackmull:unified/guards
Open

aschackmull wants to merge 3 commits into
github:mainfrom
aschackmull:unified/guards

Conversation

@aschackmull

@aschackmull aschackmull commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

This instantiates the Guards library for unified.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The guard analysis can infer false nil states from ordinary null identifiers and conditional casts, and incorrectly transfer checks between parameters with repeated labels.

3 open issues
What changed in this PR

Adds Unified’s integration with the shared guard-analysis library to reason about conditions and the control flow they govern.

Changes:

  • Instantiates guard analysis with Unified expressions, control flow, SSA, and wrapper calls.
  • Adds AST helpers for bitwise operators, compound assignments, and equality tests.
File Description
unified/​ql/​lib/​codeql/​unified/​internal/​controlflow/​Guards.qll Connects Unified to shared guard analysis.
unified/​ql/​lib/​codeql/​unified/​internal/​AstExtra.qll Adds operator classifications used by guard analysis.

Review effort: Balanced (adaptive)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment on lines +100 to +105
class AndExpr extends BinaryExpr {
AndExpr() {
this instanceof BitwiseAndExpr or
this instanceof LogicalAndExpr or
this instanceof AssignBitwiseAndExpr or
this instanceof AssignLogicalAndExpr
Comment on lines +121 to +133
IdExpr() {
this instanceof AssignExpr
or
this instanceof TypeCastExpr and
// TODO: This is Swift-specific and needs to go through a plugin
not this.(TypeCastExpr).getOperator().getValue() = "as?"
}

Expr getEqualChildExpr() {
result = this.(AssignExpr).getValue()
or
result = this.(TypeCastExpr).getExpr()
}
Comment on lines +137 to +138
exists(U::EqualityTest eq | eq = eqtest |
eq.getLeft() = left and eq.getRight() = right and eq.getPolarity() = polarity
Comment on lines +136 to +139
predicate equalityTest(Expr eqtest, Expr left, Expr right, boolean polarity) {
exists(U::EqualityTest eq | eq = eqtest |
eq.getLeft() = left and eq.getRight() = right and eq.getPolarity() = polarity
)
Comment on lines +155 to +156
this instanceof ConstructorDeclaration or
this.(FunctionDeclaration).hasModifier("static") or
Comment on lines +166 to +167
result.getDeclaringCallable() = this and
ppos = getParameterPosition(result)
Comment on lines +64 to +67
private class StringConstant extends ConstantExpr {
StringConstant() { exists(this.getStringValue()) }

override ConstantValue asConstantValue() { result = TStringValue(this.getStringValue()) }
ppos = getParameterPosition(result)
}

Expr getAReturnExpr() { EP::isReturnedExpr(this, result) }
aschackmull and others added 2 commits December 4, 2026 13:45
Also, extend the test to cover more Swift cases.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Dec 4, 2026
@aschackmull
aschackmull marked this pull request as ready for review December 4, 2026 13:00
@aschackmull
aschackmull requested a review from a team as a code owner December 4, 2026 13:00

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants