Skip to content

C#: Remove expanded assignments.#21452

Draft
michaelnebel wants to merge 9 commits intogithub:mainfrom
michaelnebel:csharp/expandedassignment
Draft

C#: Remove expanded assignments.#21452
michaelnebel wants to merge 9 commits intogithub:mainfrom
michaelnebel:csharp/expandedassignment

Conversation

@michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Mar 11, 2026

This PR has two goals, primarily to avoid making multiple upgrade/downgrade scripts:

  • Remove expanded assignments. This aligns our implementation with Java and should make adoption of the shared CFG library easier. It also simplifies expression handling and avoids caching a large predicate. Previously, when the extractor encountered a += b, it would synthesize a = a + b.
  • Swap the left- and right-hand-side child indices for assignments. This lets us remove several hacks/rotations currently used in the code.

Review on a commit-by-commit basis is encouraged.

Implementation notes

  • The implementation now “correctly” classifies a += b (e.g., when a and b are int) as an operator call, since it implicitly invokes the user-defined static operator on Int32.
  • The only compound assignment that does not call an operator is ??= as the null-coalescing operator is a built-in short-circuit like operation.
  • Added a new set of classes to represent expressions involving a specific operation (e.g., AddOperation, which can represent either a + b or a += b).

DCA notes

  • Performance appears unchanged.
  • The missing result for cs/unsynchronized-getter is due to removal of a false positive: the query did not properly account for expanded assignments.
  • The missing result for cs/web/xss looks acceptable: one alert is removed, but it is essentially a shorter path to the same underlying alert (which is here)
  • The new results for cs/useless-upcast look acceptable.
  • Remaining differences appear consistent with normal DCA background noise.

@github-actions github-actions bot added the C# label Mar 11, 2026
@michaelnebel michaelnebel force-pushed the csharp/expandedassignment branch from c94de85 to 1d8d712 Compare March 11, 2026 12:47
)
else expr_parent(child, i, parent)
}
deprecated predicate expr_parent_adjusted(Expr child, int i, ControlFlowElement parent) { none() }
@michaelnebel michaelnebel force-pushed the csharp/expandedassignment branch 9 times, most recently from abb75be to 5021ea9 Compare March 16, 2026 10:00
@michaelnebel michaelnebel changed the title C#: Cleanup expanded assignments. C#: Remove expanded assignments. Mar 16, 2026
@michaelnebel michaelnebel force-pushed the csharp/expandedassignment branch 12 times, most recently from adc3882 to 41fef59 Compare March 20, 2026 11:13
@michaelnebel michaelnebel force-pushed the csharp/expandedassignment branch from 41fef59 to 07144c2 Compare March 20, 2026 12:09
@michaelnebel
Copy link
Contributor Author

@hvitved : I would really appreciate a review of this PR even though it is still in draft mode. The PR still needs upgrade/downgrade scripts and more DCA runs.

@michaelnebel michaelnebel requested a review from hvitved March 20, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant