Skip to content

C++: Mark initializers of compiler-generated variables as compiler-generated - #22406

Merged
MathiasVP merged 5 commits into
github:mainfrom
MathiasVP:compiler-generated-initializers
Aug 21, 2026
Merged

C++: Mark initializers of compiler-generated variables as compiler-generated#22406
MathiasVP merged 5 commits into
github:mainfrom
MathiasVP:compiler-generated-initializers

Conversation

@MathiasVP

Copy link
Copy Markdown
Contributor

Pretty simple stuff. If a variable is compiler-generated surely the initializer is also compiler generated. So this PR marks it as such.

@MathiasVP
MathiasVP requested a review from a team as a code owner August 21, 2026 14:02
Copilot AI balanced review requested due to automatic review settings August 21, 2026 14:02
Comment thread cpp/ql/test/library-tests/compiler_generated/cpp.cpp

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

Marks initializers of compiler-generated C++ variables, and their expressions, as compiler-generated.

Changes:

  • Adds Initializer.isCompilerGenerated().
  • Propagates compiler-generated status to initializer expressions.
  • Adds coverage using __PRETTY_FUNCTION__.
Show a summary per file
File Description
cpp/ql/lib/semmle/code/cpp/Initializer.qll Adds initializer classification.
cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll Propagates classification to expressions.
cpp/ql/test/library-tests/compiler_generated/cpp.cpp Adds test input.
cpp/ql/test/library-tests/compiler_generated/compilerGenerated.ql Queries generated initializers.
cpp/ql/test/library-tests/compiler_generated/compilerGenerated.expected Updates expected results.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll
Comment on lines +59 to +66
predicate isCompilerGenerated() {
exists(Variable v |
v = this.getDeclaration() and
// We require the variable to be an orphan to not mark the initializer
// from a desugared ranged for loop as compiler generated.
orphaned_variables(unresolveElement(v), _) and
v.isCompilerGenerated()
)

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.

This is really an edge case, but I wonder whether there are some initializers related to coroutines that should be marked as compiler generated? However, we can always deal with those when the need arises (no immediate need here).

@jketema jketema 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.

LGTM if DCA is happy.

@MathiasVP

Copy link
Copy Markdown
Contributor Author

DCA was uneventful (as expected). Merging!

@MathiasVP
MathiasVP merged commit 20f36e0 into github:main Aug 21, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants