Cfg: Fold getTryInit into indexed getBody.#21955
Open
aschackmull wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR generalizes the shared CFG AST signature for TryStmt by changing getBody() into an indexed accessor, enabling languages with multiple “try body elements” (for example, Java try-with-resources resources) to model them uniformly as part of the try body sequence.
Changes:
- Updated
AstSig::TryStmt.getBodyfrom a single result toStmt getBody(int index)and removed the separategetTryInitaccessor. - Adjusted shared CFG logic to use the indexed
getBody(_)/getBody(i)forms. - Updated Java and C# AST-signature implementations to match the new indexed
getBodycontract.
Show a summary per file
| File | Description |
|---|---|
| shared/controlflow/codeql/controlflow/ControlFlowGraph.qll | Changes the shared AST signature for TryStmt and updates shared CFG logic to use indexed try bodies. |
| java/ql/lib/semmle/code/java/ControlFlowGraph.qll | Implements the new indexed TryStmt.getBody(int) mapping for Java (including try-with-resources resources). |
| csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll | Updates the C# AST-signature implementation to the new indexed TryStmt.getBody(int) (single body at index 0). |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
Comment on lines
+188
to
+192
| /** | ||
| * Gets the body of this `try` statement at the specified (zero-based) | ||
| * position `index`. In some languages, there is only ever a single body | ||
| * (with `index` 0). | ||
| */ |
hvitved
approved these changes
Jun 8, 2026
Contributor
hvitved
left a comment
There was a problem hiding this comment.
LGTM, but should we perhaps apply dense ranking as for the other indexed predicates?
Contributor
Author
We're not doing that universally - we've stuck to an as-needed basis. And I think this one is somewhat reasonable to expect to be densely indexed. |
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.
This generalises
TryStmt.getBodyslightly to allow multiple indexed results. This was motivated by Ruby, but actually also allows us to handle Javas try-with-resources a bit nicer.