Skip to content
Snippets Groups Projects
Commit d0e69cf6 authored by Artem Dergachev's avatar Artem Dergachev
Browse files

[analyzer] Fix CloneDetector crash on calling methods of class templates.

If a call expression represents a method call of a class template,
and the method itself isn't templated, then the method may be considered
to be a template instantiation without template specialization arguments.

No longer crash when we could not find template specialization arguments.

Patch by Raphael Isemann!

Differential Revision: https://reviews.llvm.org/D23780


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279529 91177308-0d34-0410-b5e6-96231b3b80d8
parent 36fa4bbf
No related branches found
No related tags found
No related merge requests found
...@@ -345,10 +345,9 @@ public: ...@@ -345,10 +345,9 @@ public:
DEF_ADD_DATA(CallExpr, { DEF_ADD_DATA(CallExpr, {
// Function pointers don't have a callee and we just skip hashing it. // Function pointers don't have a callee and we just skip hashing it.
if (const FunctionDecl *D = S->getDirectCallee()) { if (const FunctionDecl *D = S->getDirectCallee()) {
// If the function is a template instantiation, we also need to handle // If the function is a template specialization, we also need to handle
// the template arguments as they are no included in the qualified name. // the template arguments as they are not included in the qualified name.
if (D->isTemplateInstantiation()) { if (auto Args = D->getTemplateSpecializationArgs()) {
auto Args = D->getTemplateSpecializationArgs();
std::string ArgString; std::string ArgString;
// Print all template arguments into ArgString // Print all template arguments into ArgString
......
...@@ -88,3 +88,15 @@ bool fooTemplatePadding2(int x) { ...@@ -88,3 +88,15 @@ bool fooTemplatePadding2(int x) {
return templatePaddingFunc<XX, X>(); return templatePaddingFunc<XX, X>();
return true; return true;
} }
// Test that we don't crash on member functions of template instantiations.
template<typename T>
struct A {
void foo(T t) {}
};
void fooTestInstantiation() {
A<int> a;
a.foo(1);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment