teemperor created this revision. teemperor added reviewers: v.g.vassilev, NoQ. teemperor added a subscriber: cfe-commits.
The current check with `isTemplateInstantiation()` is also returning true when calling a member method of a template class. In this case getTemplateSpecializationArgs() returns a null pointer and we crash. It seems the intended way to check for template specialization args is to make a nullptr check on getTemplateSpecializationArgs() which we start doing with this patch. We don't need to add any code for the member methods of template classes as the qualified type of the calling object already contains the template arguments of the class. https://reviews.llvm.org/D23780 Files: lib/Analysis/CloneDetection.cpp test/Analysis/copypaste/call.cpp Index: test/Analysis/copypaste/call.cpp =================================================================== --- test/Analysis/copypaste/call.cpp +++ test/Analysis/copypaste/call.cpp @@ -88,3 +88,15 @@ return templatePaddingFunc<XX, X>(); 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); +} Index: lib/Analysis/CloneDetection.cpp =================================================================== --- lib/Analysis/CloneDetection.cpp +++ lib/Analysis/CloneDetection.cpp @@ -185,10 +185,9 @@ DEF_ADD_DATA(CallExpr, { // Function pointers don't have a callee and we just skip hashing it. if (const FunctionDecl *D = S->getDirectCallee()) { - // If the function is a template instantiation, we also need to handle - // the template arguments as they are no included in the qualified name. - if (D->isTemplateInstantiation()) { - auto Args = D->getTemplateSpecializationArgs(); + // If the function is a template specialization, we also need to handle + // the template arguments as they are not included in the qualified name. + if (auto Args = D->getTemplateSpecializationArgs()) { std::string ArgString; // Print all template arguments into ArgString
Index: test/Analysis/copypaste/call.cpp =================================================================== --- test/Analysis/copypaste/call.cpp +++ test/Analysis/copypaste/call.cpp @@ -88,3 +88,15 @@ return templatePaddingFunc<XX, X>(); 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); +} Index: lib/Analysis/CloneDetection.cpp =================================================================== --- lib/Analysis/CloneDetection.cpp +++ lib/Analysis/CloneDetection.cpp @@ -185,10 +185,9 @@ DEF_ADD_DATA(CallExpr, { // Function pointers don't have a callee and we just skip hashing it. if (const FunctionDecl *D = S->getDirectCallee()) { - // If the function is a template instantiation, we also need to handle - // the template arguments as they are no included in the qualified name. - if (D->isTemplateInstantiation()) { - auto Args = D->getTemplateSpecializationArgs(); + // If the function is a template specialization, we also need to handle + // the template arguments as they are not included in the qualified name. + if (auto Args = D->getTemplateSpecializationArgs()) { std::string ArgString; // Print all template arguments into ArgString
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits