Skip to content

C#: Simplify the ConstantCondition query.#21599

Draft
aschackmull wants to merge 2 commits intogithub:mainfrom
aschackmull:csharp/constantcondition-simplify
Draft

C#: Simplify the ConstantCondition query.#21599
aschackmull wants to merge 2 commits intogithub:mainfrom
aschackmull:csharp/constantcondition-simplify

Conversation

@aschackmull
Copy link
Copy Markdown
Contributor

@aschackmull aschackmull commented Mar 27, 2026

Several simplifications are made (motivated by the upcoming CFG switch):

  • Constant boolean conditions are restricted to comparisons - literal true/false are seldom interesting alerts and the special-casing for isNullOrEmpty called on constants that happens inside the CFG construction seems a bit too narrow to warrant attention, and it's not something that'll be preserved in the new CFG. This allows us to get rid of all the allow-listing that was due to the the CFG round-trip.
  • The constant nullness implementation is short-circuited instead of relying on the CFG round-trip.
  • Constant matching seemed to silly to keep - switching on constants or obviously disjoint types is the kind of thing that only really happens in silly synthetic test cases. And any real occurrences are better handled by an LLM anyway.

The ConstantCondition query was partially implemented inside the CFG (in Completion.qll). In particular, this included all of isConstantComparison from Constants.qll, which was the main implementation for the ConstantComparison query. But due to the CFG round-trip the ConstantCondition query only kept those results that were manifested as missing conditional CFG edges. Short-circuiting this round-trip means that the ConstantComparison query is made redundant.

@github-actions github-actions bot added the C# label Mar 27, 2026
@aschackmull aschackmull force-pushed the csharp/constantcondition-simplify branch from e30a08f to 2d39a2b Compare March 30, 2026 06:57
@aschackmull
Copy link
Copy Markdown
Contributor Author

I've tested the constant-type-check part of the query on MRVA - there were very few results, and those that I checked were FPs, so dropping that seems perfectly fine.

@aschackmull aschackmull force-pushed the csharp/constantcondition-simplify branch 2 times, most recently from 92225e6 to 371b9b8 Compare March 30, 2026 11:51
@github-actions
Copy link
Copy Markdown
Contributor

QHelp previews:

@aschackmull aschackmull force-pushed the csharp/constantcondition-simplify branch from 371b9b8 to 86cc188 Compare March 30, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant