-
Notifications
You must be signed in to change notification settings - Fork 2k
C++: Use the new prototype-related extensionals in MaD
#21899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5f54a86
8393b40
9f211ce
2d58150
e18448d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -276,6 +276,45 @@ private predicate isClassConstructedFrom(Class c, Class templateClass) { | |||||
| not c.isConstructedFrom(_) and c = templateClass | ||||||
| } | ||||||
|
|
||||||
| /** Gets the fully templated version of `c`. */ | ||||||
| private Class getFullyTemplatedClassOld(Class c) { | ||||||
| not c.isFromUninstantiatedTemplate(_) and | ||||||
| isClassConstructedFrom(c, result) | ||||||
| } | ||||||
|
|
||||||
| private TemplateClass getOriginalClassTemplate(TemplateClass tc) { | ||||||
| result = tc.getOriginalTemplate() | ||||||
| or | ||||||
| not exists(tc.getOriginalTemplate()) and | ||||||
| result = tc | ||||||
| } | ||||||
|
|
||||||
| /** Gets the fully templated version of `c`. */ | ||||||
| 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 | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| /** 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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm. I think the change did make it into 2.25.6, no? See https://github.com/github/codeql/commits/codeql-cli-2.25.6/cpp/ql/lib |
||||||
| // `class_template_generated_from` extensionals empty if the database | ||||||
| // was generated with an older extractor. So we use the old implementation | ||||||
| // if the `class_template_generated_from` extensional is empty. | ||||||
| if class_template_generated_from(_, _) | ||||||
| then result = getFullyTemplatedClassNew(c) | ||||||
| else result = getFullyTemplatedClassOld(c) | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Holds if `f` is an instantiation of a function template `templateFunc`, or | ||||||
| * holds with `f = templateFunc` if `f` is not an instantiation of any function | ||||||
|
|
@@ -292,7 +331,7 @@ private predicate isFunctionConstructedFrom(Function f, Function templateFunc) { | |||||
| } | ||||||
|
|
||||||
| /** Gets the fully templated version of `f`. */ | ||||||
| Function getFullyTemplatedFunction(Function f) { | ||||||
| private Function getFullyTemplatedFunctionOld(Function f) { | ||||||
| not f.isFromUninstantiatedTemplate(_) and | ||||||
| ( | ||||||
| exists(Class c, Class templateClass, int i | | ||||||
|
|
@@ -306,13 +345,46 @@ Function getFullyTemplatedFunction(Function f) { | |||||
| ) | ||||||
| } | ||||||
|
|
||||||
| private TemplateFunction getOriginalFunctionTemplate(TemplateFunction tf) { | ||||||
| result = tf.getOriginalTemplate() | ||||||
| or | ||||||
| not exists(tf.getOriginalTemplate()) and | ||||||
| result = tf | ||||||
| } | ||||||
|
|
||||||
| /** Gets the fully templated version of `f`. */ | ||||||
| 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 | ||||||
| ) | ||||||
| } | ||||||
|
Comment on lines
+356
to
+367
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to work fine: e18448d |
||||||
|
|
||||||
| /** 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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| // `function_template_generated_from` extensionals empty if the database | ||||||
| // was generated with an older extractor. So we use the old implementation | ||||||
| // if the `function_template_generated_from` extensional is empty. | ||||||
| if function_template_generated_from(_, _) | ||||||
| then result = getFullyTemplatedFunctionNew(f) | ||||||
| else result = getFullyTemplatedFunctionOld(f) | ||||||
| } | ||||||
|
|
||||||
| /** Prefixes `const` to `s` if `t` is const, or returns `s` otherwise. */ | ||||||
| bindingset[s, t] | ||||||
| private string withConst(string s, Type t) { | ||||||
| if t.isConst() then result = "const " + s else result = s | ||||||
| } | ||||||
|
|
||||||
| /** Prefixes `volatile` to `s` if `t` is const, or returns `s` otherwise. */ | ||||||
| /** Prefixes `volatile` to `s` if `t` is volatile, or returns `s` otherwise. */ | ||||||
| bindingset[s, t] | ||||||
| private string withVolatile(string s, Type t) { | ||||||
| if t.isVolatile() then result = "volatile " + s else result = s | ||||||
|
|
@@ -490,7 +562,7 @@ pragma[nomagic] | |||||
| private string getTypeNameWithoutClassTemplates(Function f, int n, int remaining) { | ||||||
| // If there is a declaring type then we start by expanding the function templates | ||||||
| exists(Class template | | ||||||
| isClassConstructedFrom(f.getDeclaringType(), template) and | ||||||
| template = getFullyTemplatedClass(f.getDeclaringType()) and | ||||||
| remaining = getNumberOfSupportedClassTemplateArguments(template) and | ||||||
| result = getTypeNameWithoutFunctionTemplates(f, n, 0) | ||||||
| ) | ||||||
|
|
@@ -502,7 +574,7 @@ private string getTypeNameWithoutClassTemplates(Function f, int n, int remaining | |||||
| or | ||||||
| exists(string mid, TypeTemplateParameter tp, Class template | | ||||||
| mid = getTypeNameWithoutClassTemplates(f, n, remaining + 1) and | ||||||
| isClassConstructedFrom(f.getDeclaringType(), template) and | ||||||
| template = getFullyTemplatedClass(f.getDeclaringType()) and | ||||||
| tp = getSupportedClassTemplateArgument(template, remaining) | ||||||
| | | ||||||
| result = mid.replaceAll(tp.getName(), "class:" + remaining.toString()) | ||||||
|
|
||||||
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.