Repository navigation
Guards: Support mid-block guards. - #23239
aschackmull wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The change leaves composite-expression guard outcomes unreported for position-zero after-value nodes and introduces Go guard-test results without updating the expected snapshots.
2 open issues
What changed in this PR
Extends shared guard analysis to recognize expression values encoded by control-flow nodes within basic blocks, with adapters for Java, Go, and C#.
Changes:
- Adds a default
nodeIsAfterValuehook to the shared input interface. - Incorporates mid-block guard facts into dominance and implication-based control analysis.
- Connects the three language adapters to their existing after-value predicates.
| File | Description |
|---|---|
shared/controlflow/codeql/controlflow/Guards.qll |
Adds mid-block guard recognition and propagation. |
java/ql/lib/semmle/code/java/controlflow/Guards.qll |
Supplies Java after-value facts. |
go/ql/lib/semmle/go/controlflow/Guards.qll |
Supplies Go after-value facts. |
csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll |
Supplies C# after-value facts. |
Review effort: Balanced (adaptive)
148dccb to
c8d8ce4
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Propagating mid-block facts through dominance, SSA/phi inference, and guard implications across Java, Go, and C# affects security-query suppression and requires deeper semantic review.
No open issues 🎉
2 resolved since last review
Review effort: Balanced (adaptive)
c8d8ce4 to
1ada892
Compare
1ada892 to
70d2fec
Compare
70d2fec to
c468304
Compare
|
I have started DCA runs. |
|
Thanks for starting those dca runs. Go is uneventful, but both Java and C# actually indicate that we'll want change notes there - we see general improvements for several different queries. Also, there's a slight performance regression for one Java project, which I can trace back to a bad join (it appears to have been present on main already, but it only explodes once the added disjunctive guards are added). |


This adds support for guards that aren't directly identified by a CFG branch point by using the
isAfterValuepredicate from the shared CFG. As-is this allows identification of conjunctions and disjunctions as guards, and once an expected refactor of pattern CFG lands it'll also support continued identification of pattern-instanceof checks as guards.This fixes a few spurious results for Go, which were introduced in the adoption of the Guards library and at the time left for follow-up work.