C#: Improve dataflow for mutation definition and mutation operator calls.#21839
Closed
michaelnebel wants to merge 6 commits into
Closed
C#: Improve dataflow for mutation definition and mutation operator calls.#21839michaelnebel wants to merge 6 commits into
michaelnebel wants to merge 6 commits into
Conversation
78ff6ae to
cb29538
Compare
…ount for implicit assignment of built and user-definied static operator calls.
…d decrement (only use the specialized code, which is already present).
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the C# dataflow/SSA modeling around mutation operations (++, --) and mutator operator calls, and refreshes the affected library-test baselines accordingly.
Changes:
- Extend assignable/mutation definition handling to cover additional mutation-operator call cases.
- Adjust sign-analysis SSA assignment extraction to avoid treating mutator operations as simple assignments.
- Add/extend operator dataflow library tests and update corresponding
.expectedoutputs.
Show a summary per file
| File | Description |
|---|---|
| csharp/ql/test/library-tests/fields/Fields11.expected | Updated baseline for field-flow expectations impacted by mutation handling. |
| csharp/ql/test/library-tests/dataflow/operators/operatorFlow.expected | Updated operator-flow graph baseline with new mutator operator edges/nodes. |
| csharp/ql/test/library-tests/dataflow/operators/Operator.cs | Adds user-defined decrement operator + new flow assertions for -- scenarios. |
| csharp/ql/test/library-tests/dataflow/local/TaintTrackingStep.expected | Updated baseline to include SSA steps for decrement operations. |
| csharp/ql/test/library-tests/dataflow/local/DataFlowStep.expected | Updated baseline to include dataflow steps for decrement operations. |
| csharp/ql/test/library-tests/csharp7/LocalTaintFlow.expected | Updated baseline for taint steps involving increment operations. |
| csharp/ql/test/library-tests/assignables/GetAnAssignedValue.expected | Updated baseline to treat mutation operations as assigned-value sources. |
| csharp/ql/test/library-tests/assignables/AssignableDefinition.expected | Updated baseline for mutation definitions to record the mutation op as the source. |
| csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll | Tweaks SSA-to-expression extraction to exclude mutator-operation defining expressions. |
| csharp/ql/lib/semmle/code/csharp/Assignable.qll | Introduces mutation-operation assignment abstraction and updates mutation-definition plumbing. |
| csharp/ql/lib/change-notes/2026-05-19-mutation-operator-dataflow.md | Adds a change note entry (currently duplicates an existing one). |
Copilot's findings
- Files reviewed: 11/11 changed files
- Comments generated: 3
| var x = new C1(); | ||
| var y = x--; | ||
| Sink(x.Field); // $ hasValueFlow=2 | ||
| Sink(y.Field); // $ hasValueFlow=2 |
| } | ||
|
|
||
| /** | ||
| * A mutation operation that implicitly assigns the result to its operand. For example, `a++` in |
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * C# 14: Added support for user-defined instance increment/decrement operators. |
cb29538 to
be7f7a4
Compare
Contributor
Author
|
@hvitved : No need to review this as it shouldn't be merged. |
be7f7a4 to
dec76af
Compare
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.
In this PR, we improve data-flow for mutation operations and mutator operator calls.
Note, that
c++implicitly (if this is not an instance operator) the resulting value toc.Comments on DCA
cs/invalid-dynamic-call, which is a removal of a false positive (related to a dynamic call of--). However, I believe this is somewhat due to wobliness as there is another PR, which "introduces" a similar result in themonoproject (which is a false positive). I am not able to reproduce with a local example.