Skip to content

C++: Use the new prototype-related extensionals in MaD#21899

Open
MathiasVP wants to merge 5 commits into
github:mainfrom
MathiasVP:use-new-prototype-extensionals
Open

C++: Use the new prototype-related extensionals in MaD#21899
MathiasVP wants to merge 5 commits into
github:mainfrom
MathiasVP:use-new-prototype-extensionals

Conversation

@MathiasVP
Copy link
Copy Markdown
Contributor

@MathiasVP MathiasVP commented May 27, 2026

This PR makes use of the new extensionals that were added in #21870 to fix a couple of bugs in MaD.

I discussed the best way to handle "backwards compatibility" with @jketema, and we agreed to keep the old code in production for a couple of versions to allow new databases with populated class_template_generated_from and function_template_generated_from extensionals to be produced.

The DCA run is up-to-date (and boring as expected). The force-push was just me fixing up QLDoc.

@github-actions github-actions Bot added the C++ label May 27, 2026
@MathiasVP MathiasVP force-pushed the use-new-prototype-extensionals branch from 357fd96 to 3002476 Compare May 28, 2026 09:16
@MathiasVP MathiasVP marked this pull request as ready for review May 28, 2026 10:03
@MathiasVP MathiasVP requested a review from a team as a code owner May 28, 2026 10:03
Copilot AI review requested due to automatic review settings May 28, 2026 10:03
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label May 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the C++ MaD (Models as Data) support to leverage the newer template “prototype/origin” extensionals introduced in #21870, while retaining a fallback path for older databases whose upgrade leaves those extensionals empty.

Changes:

  • Add “new vs old” implementations for resolving fully-templated class/function entities, selecting based on whether the new extensionals are populated.
  • Adjust signature/type-name expansion to use the fully-templated declaring class resolution.
  • Update the MaD signatures test expectations to reflect the new resolution behavior.
Show a summary per file
File Description
cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll Switches MaD template-resolution logic to prefer new getOriginalTemplate-based extensionals with a compatibility fallback; minor QLDoc touch-ups.
cpp/ql/test/library-tests/dataflow/taint-tests/test_mad-signatures.expected Updates expected signature/type-name output to match the new template-resolution behavior.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll Outdated
Comment thread cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll Outdated
@MathiasVP MathiasVP force-pushed the use-new-prototype-extensionals branch from 67d7281 to 2d58150 Compare May 28, 2026 11:34
Copy link
Copy Markdown
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

Some comments and questions.

/** Gets the fully templated version of `f`. */
Function getFullyTemplatedFunction(Function f) {
// The `Function::getOriginalTemplate` predicate was introduced in CodeQL
// version 2.25.6 and the upgrade script leaves the
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.

Suggested change
// version 2.25.6 and the upgrade script leaves the
// version 2.25.7 and the upgrade script leaves the

/** Gets the fully templated version of `c`. */
private Class getFullyTemplatedClass(Class c) {
// The `Class::getOriginalTemplate` predicate was introduced in CodeQL
// version 2.25.6 and the upgrade script leaves the
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.

Suggested change
// version 2.25.6 and the upgrade script leaves the
// version 2.25.7 and the upgrade script leaves the

Comment on lines +356 to +367
private Function getFullyTemplatedFunctionNew(Function f) {
not f.isFromUninstantiatedTemplate(_) and
exists(Function mid |
f.isConstructedFrom(mid)
or
not f.isConstructedFrom(_) and f = mid
|
result = getOriginalFunctionTemplate(mid)
or
not mid instanceof TemplateFunction and mid = result
)
}
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.

Does this properly handle the case where the template we are instantiating has multiple template parameters and we instantiate those not all at once but in multiple steps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seems to work fine: e18448d

Comment on lines +293 to +304
private Class getFullyTemplatedClassNew(Class c) {
not c.isFromUninstantiatedTemplate(_) and
exists(Class mid |
c.isConstructedFrom(mid)
or
not c.isConstructedFrom(_) and c = mid
|
result = getOriginalClassTemplate(mid)
or
not mid instanceof TemplateClass and mid = result
)
}
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.

Same question as for functions.

Copy link
Copy Markdown
Contributor Author

@MathiasVP MathiasVP May 29, 2026

Choose a reason for hiding this comment

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

Hmmm... I don't think I can construct an example for functions similar to what was added in e18448d. AFAIK, it's not possible to have an alias template for a function template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ 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.

3 participants