Conversation
…e next version of our C/C++ frontend.
MathiasVP
marked this pull request as ready for review
October 5, 2026 20:20
Contributor
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Updates the C++ IR translation logic to ignore implicit destructor calls for temporaries created within conditional evaluation contexts, and adds a regression test covering conditional-operator temporaries with non-trivial destructors.
Changes:
- Add
temp_test13demonstrating temporaries with destructors inside a ternary that returns an lvalue subobject. - Filter implicit destructor calls in IR translation to exclude “conditional temporary destructor calls”.
- Update IR/AST expected outputs to match the new filtering behavior.
| File | Description |
|---|---|
| cpp/ql/test/library-tests/ir/ir/destructors_for_temps.cpp | Adds a new test case and a struct with array + destructor to exercise conditional temporary destructor handling. |
| cpp/ql/test/library-tests/ir/ir/raw_ir.expected | Updates the raw IR snapshot to include temp_test13 and its new control-flow/aliasing behavior. |
| cpp/ql/test/library-tests/ir/ir/aliased_ir.expected | Updates aliased IR snapshot consistent with the new implicit-dtor filtering. |
| cpp/ql/test/library-tests/ir/ir/PrintAST.expected | Updates AST snapshot showing the implicit destructor calls attached to the conditional expression. |
| cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll | Introduces filtered indexing for implicit destructor calls and uses it across statement child traversal. |
| cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll | Applies the same filtered indexing for expression-attached implicit destructor calls. |
| cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll | Changes visibility of isConditionalTemporaryDestructorCall to support reuse in other internal modules. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.


Consider this snippet (which I also added as a test in this PR):
Currently, the extractor incorrectly places each temporary's destructor call inside the conditional branches. However, an upcoming extractor fix will move those destructor calls to the
returnstatement. This revealed a bug in the IR's placement of destructors.IR construction only generates destructors for non-conditional destruction. We do this by filtering out those expressions here. However, we forgot to filter out the calls to conditional destructors inside the translation classes. For example here where we just return any destructor without checking if that destructor is conditional.
Unfortunately, I was unable to craft a testcase that fails on the current version of the extractor. So it's a bit hard to judge the impact of this PR. I did, however, check that this fixes the issue when running on a database extracted with CodeQL running the fixed version of the extractor.