Repository navigation
Unified: Add Guards instantiation. - #23350
Open
aschackmull wants to merge 3 commits into
Open
aschackmull wants to merge 3 commits into
aschackmull wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 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)
aschackmull
force-pushed
the
unified/guards
branch
from
December 4, 2026 12:13
63904ba to
d8d1f86
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Multiple critical Swift guard-inference errors can falsely establish non-null and Boolean facts, making analysis results unsound.
8 open issues
Overloaded Boolean operators can produce unsound guard facts · New Optional-to-Any cast falsely implies the source is non-null · New Nullable Boolean comparison derives an incorrect true fact · New Overloaded equality operators can produce unsound nullness facts · New Delegated failable initializers can cause incorrect wrapper inference · New Repeated external labels can mark unchecked parameters non-null · New String escape spellings are mistaken for distinct values · New Single-statement returns produce an untracked extra return expression · New
3 resolved since last review
Review effort: Max (adaptive)
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) } |
Also, extend the test to cover more Swift cases. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
aschackmull
force-pushed
the
unified/guards
branch
from
December 4, 2026 12:46
d8d1f86 to
625face
Compare
aschackmull
marked this pull request as ready for review
December 4, 2026 13:00
This branch has not been deployed
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.


This instantiates the Guards library for unified.