C++: Since isConstructedFrom only holds for templates we need to explicitly handle the case where the function (or class) is not a template.

This commit is contained in:
Mathias Vorreiter Pedersen
2024-11-26 17:53:24 +00:00
parent bf36f00bb0
commit f688470324
2 changed files with 18 additions and 6 deletions

View File

@@ -434,18 +434,30 @@ private predicate elementSpec(
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _, _, _)
}
private predicate isClassConstructedFrom(Class c, Class templateClass) {
c.isConstructedFrom(templateClass)
or
not any(Class c_).isConstructedFrom(templateClass) and c = templateClass
}
private predicate isFunctionConstructedFrom(Function f, Function templateFunc) {
f.isConstructedFrom(templateFunc)
or
not any(Function f_).isConstructedFrom(templateFunc) and f = templateFunc
}
/** Gets the fully templated version of `f`. */
private Function getFullyTemplatedFunction(Function f) {
not f.isFromUninstantiatedTemplate(_) and
(
exists(Class c, Class templateClass, int i |
c.isConstructedFrom(templateClass) and
isClassConstructedFrom(c, templateClass) and
f = c.getAMember(i) and
result = templateClass.getCanonicalMember(i)
)
or
not exists(f.getDeclaringType()) and
f.isConstructedFrom(result)
isFunctionConstructedFrom(f, result)
)
}
@@ -489,7 +501,7 @@ private string getTypeNameWithoutFunctionTemplates(Function f, int n, int remain
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 |
f.getDeclaringType().isConstructedFrom(template) and
isClassConstructedFrom(f.getDeclaringType(), template) and
remaining = template.getNumberOfTemplateArguments() and
result = getTypeNameWithoutFunctionTemplates(f, n, 0)
)
@@ -501,7 +513,7 @@ private string getTypeNameWithoutClassTemplates(Function f, int n, int remaining
or
exists(string mid, TemplateParameter tp, Class template |
mid = getTypeNameWithoutClassTemplates(f, n, remaining + 1) and
f.getDeclaringType().isConstructedFrom(template) and
isClassConstructedFrom(f.getDeclaringType(), template) and
tp = template.getTemplateArgument(remaining) and
result = mid.replaceAll(tp.getName(), "class:" + remaining.toString())
)

View File

@@ -75,12 +75,12 @@ void test__U_STRINGorID() {
{
UINT x = source<UINT>();
_U_STRINGorID u(x);
sink(u.m_lpstr); // $ MISSING: ir
sink(u.m_lpstr); // $ ir
}
{
LPCTSTR y = indirect_source<const char>();
_U_STRINGorID u(y);
sink(u.m_lpstr); // $ MISSING: ir
sink(u.m_lpstr); // $ ir
}
}