Repository navigation
C#: Extract defining accesses for local declarations - #23210
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
The new C# declaration-access nodes affect interacting AST, assignable read/write, CFG, SSA/data-flow, and jump-to-definition contracts, requiring broader semantic review than automated approval supports.
No open issues 🎉
What changed in this PR
This PR makes local declaration accesses more consistent across the C# extractor and CodeQL libraries, supporting definition tracking and data-flow analysis without treating declarations as jump-to-definition uses.
Changes:
- Extract defining accesses for uninitialized locals, deconstruction,
foreach, andcatchvariables. - Connect these accesses to assignable definitions and exclude declaration accesses from navigation uses.
- Add focused regression coverage, separate tuple path and inline tests, and update affected baselines.
| File | Description |
|---|---|
csharp/ql/test/library-tests/definitions/PrintAst.expected |
Updates catch and foreach declaration ASTs. |
csharp/ql/test/library-tests/defining-accesses/PrintAst.qlref |
Enables focused AST testing. |
csharp/ql/test/library-tests/defining-accesses/PrintAst.expected |
Records declaration-access AST coverage. |
csharp/ql/test/library-tests/defining-accesses/options |
Configures C# 8 and LINQ support. |
csharp/ql/test/library-tests/defining-accesses/Flow.ql |
Checks source-to-sink data flow. |
csharp/ql/test/library-tests/defining-accesses/Flow.expected |
Records expected declaration-related flows. |
csharp/ql/test/library-tests/defining-accesses/definitions.qlref |
Enables navigation-use testing. |
csharp/ql/test/library-tests/defining-accesses/definitions.expected |
Records uses excluding defining accesses. |
csharp/ql/test/library-tests/defining-accesses/DefiningAccesses.ql |
Checks access targets, classification, and definitions. |
csharp/ql/test/library-tests/defining-accesses/DefiningAccesses.expected |
Records expected defining-access associations. |
csharp/ql/test/library-tests/defining-accesses/DefiningAccesses.cs |
Adds varied declaration and flow fixtures. |
csharp/ql/test/library-tests/dataflow/tuples/TuplesInline.ql |
Separately runs inline flow assertions. |
csharp/ql/test/library-tests/dataflow/tuples/TuplesInline.expected |
Adds an empty inline-failure baseline. |
csharp/ql/test/library-tests/dataflow/tuples/Tuples.ql |
Separates path output from inline assertions. |
csharp/ql/test/library-tests/dataflow/tuples/Tuples.expected |
Updates paths through defining accesses. |
csharp/ql/test/library-tests/dataflow/tuples/PrintAst.expected |
Adds tuple declaration access nodes. |
csharp/ql/test/library-tests/dataflow/tuples/DataFlowStep.expected |
Updates tuple definition flow steps. |
csharp/ql/test/library-tests/dataflow/local/TaintTrackingStep.expected |
Updates a declaration-related taint step. |
csharp/ql/test/library-tests/dataflow/local/DataFlowStep.expected |
Updates a declaration-related flow step. |
csharp/ql/test/library-tests/csharp9/PrintAst.expected |
Updates foreach and deconstruction ASTs. |
csharp/ql/test/library-tests/csharp8/switchexprcontrolflow.expected |
Updates declaration control-flow nodes. |
csharp/ql/test/library-tests/csharp8/PrintAst.expected |
Updates foreach, tuple, and catch ASTs. |
csharp/ql/test/library-tests/csharp7/TaintReaches.expected |
Records taint reaching defining accesses. |
csharp/ql/test/library-tests/csharp7/PrintAst.expected |
Adds defining accesses across declaration forms. |
csharp/ql/test/library-tests/csharp7/LocalTaintFlow.expected |
Updates deconstruction taint-flow steps. |
csharp/ql/test/library-tests/csharp11/PrintAst.expected |
Adds an uninitialized local’s defining access. |
csharp/ql/test/library-tests/controlflow/graph/EntryElement.expected |
Updates declaration entry elements. |
csharp/ql/test/library-tests/controlflow/graph/EnclosingCallable.expected |
Records enclosing callables for new nodes. |
csharp/ql/test/library-tests/controlflow/graph/Condition.expected |
Updates condition relationships for declaration blocks. |
csharp/ql/test/library-tests/controlflow/graph/BasicBlock.expected |
Updates block boundaries and node counts. |
csharp/ql/test/library-tests/assignables/AssignableDefinition.expected |
Adds definition-to-access associations. |
csharp/ql/test/library-tests/assignables/AssignableAccess.expected |
Records new accesses as writes. |
csharp/ql/lib/semmle/code/csharp/Assignable.qll |
Associates local and tuple definitions with accesses. |
csharp/ql/lib/definitions.qll |
Excludes defining accesses from navigation uses. |
csharp/ql/lib/change-notes/2026-11-23-all-local-defining-accesses.md |
Documents expanded defining-access extraction. |
csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs |
Creates defining accesses for additional declaration forms. |
csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Query.cs |
Preserves separate range-variable access creation. |
csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Patterns/RecursivePattern.cs |
Uses default defining-access creation. |
csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Patterns/Pattern.cs |
Updates pattern callers to the revised API. |
Review effort: Balanced (adaptive)
ff9c444 to
d0bc5b9
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
d0bc5b9 to
e57b5f7
Compare
michaelnebel
left a comment
There was a problem hiding this comment.
Changes looks good to me, but it is hard to say exactly what the full impact is.
A couple of questions.
- It looks like we see more expressions with unknown types for many buildless projects? I suppose this is because we extract more (defining access) expressions, which might not have a type (if for instance of the variable doesn't have a type)?
- There are some discrepancies in the
cs/unused-collectionandcs/useless-assignment-to-localthat might not be due to wobble; It appears that the precision of these queries have increased for tuple assignable definitions?
Yes, that would explain the increase.
For For |
#23183 follow-up; add defining accesses for all local declarations.
DCA has some result changes, but I think much of it is wobble.