Skip to content

Cfg: Change AST/CFG for CatchClauses to use a pattern.#22017

Draft
aschackmull wants to merge 1 commit into
github:mainfrom
aschackmull:cfg/catchclause-pattern
Draft

Cfg: Change AST/CFG for CatchClauses to use a pattern.#22017
aschackmull wants to merge 1 commit into
github:mainfrom
aschackmull:cfg/catchclause-pattern

Conversation

@aschackmull

Copy link
Copy Markdown
Contributor

This PR updates the AstSig and corresponding CFG for CatchClauses to use a pattern with a match-completion. This increases alignment with both Ruby, Python, and in particular the upcoming unified AST. Support for missing catch clause bodies is also added.
For Java and C#, the variable declaration is simply seen as the pattern that may match or not as that's the part containing the type test. This is expected to also be the general pattern in the unified AST while the CFG lib retains the getVariable member in order to more easily support Ruby and Python (in which the type test and the variable binding are independent child nodes of the catch).

@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Jun 19, 2026
@aschackmull aschackmull requested review from a team as code owners June 19, 2026 13:42
Copilot AI review requested due to automatic review settings June 19, 2026 13:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates the shared control-flow graph (CFG) construction to treat CatchClause exception handling as a pattern match with match-completion, aligning the shared AstSig with other languages (Ruby/Python) and the upcoming unified AST model, and adding support for catch clauses with missing bodies.

Changes:

  • Extend AstSig.CatchClause with getPattern() and update catch-all semantics to be based on the absence of a pattern.
  • Update shared CFG construction to route evaluation through catch patterns (and to handle catch clauses that have no body via an additional node/tag).
  • Adapt Java and C# language-specific CatchClause mappings so the variable declaration is modeled as the catch pattern.
Show a summary per file
File Description
shared/controlflow/codeql/controlflow/ControlFlowGraph.qll Updates CatchClause AstSig and shared CFG building to use a pattern/match-completion model and handle missing catch bodies.
java/ql/lib/semmle/code/java/ControlFlowGraph.qll Maps Java catch variable declaration to CatchClause.getPattern() and disables a separate getVariable() node.
csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll Maps C# catch variable declaration expression to CatchClause.getPattern() and disables a separate getVariable() node.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment on lines +237 to 241
* Gets the variable declared by this catch clause, if any.
*
* Some languages include the variable binding as part of the pattern.
*/
AstNode getVariable();
@aschackmull aschackmull marked this pull request as draft June 19, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# Java no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants