r279529 - [analyzer] Fix CloneDetector crash on calling methods of class templates.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 23 09:42:00 PDT 2016
Author: dergachev
Date: Tue Aug 23 11:42:00 2016
New Revision: 279529
URL: http://llvm.org/viewvc/llvm-project?rev=279529&view=rev
Log:
[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
Modified:
cfe/trunk/lib/Analysis/CloneDetection.cpp
cfe/trunk/test/Analysis/copypaste/call.cpp
Modified: cfe/trunk/lib/Analysis/CloneDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CloneDetection.cpp?rev=279529&r1=279528&r2=279529&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CloneDetection.cpp (original)
+++ cfe/trunk/lib/Analysis/CloneDetection.cpp Tue Aug 23 11:42:00 2016
@@ -345,10 +345,9 @@ public:
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
Modified: cfe/trunk/test/Analysis/copypaste/call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/copypaste/call.cpp?rev=279529&r1=279528&r2=279529&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/copypaste/call.cpp (original)
+++ cfe/trunk/test/Analysis/copypaste/call.cpp Tue Aug 23 11:42:00 2016
@@ -88,3 +88,15 @@ bool fooTemplatePadding2(int x) {
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);
+}
More information about the cfe-commits
mailing list