diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2016-08-20 09:57:21 +0000 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2016-08-20 09:57:21 +0000 |
commit | 5a3db3cf93d33f4082f33f8d90eefdc63d37446a (patch) | |
tree | 6aef3f857e8430acd4a62a0bac2c5d6a0d529cb6 /lib/Analysis/CloneDetection.cpp | |
parent | 41d8a468bd07b9d2f72347f28eb3a4bc2e222a5e (diff) |
[analyzer] Make CloneDetector consider template arguments.
For example, code samples `isa<Stmt>(S)' and `isa<Expr>(S)'
are no longer considered to be clones.
Patch by Raphael Isemann!
Differential Revision: https://reviews.llvm.org/D23555
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279366 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CloneDetection.cpp')
-rw-r--r-- | lib/Analysis/CloneDetection.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/Analysis/CloneDetection.cpp b/lib/Analysis/CloneDetection.cpp index a26409f950..ee1c6943f2 100644 --- a/lib/Analysis/CloneDetection.cpp +++ b/lib/Analysis/CloneDetection.cpp @@ -315,8 +315,26 @@ public: //--- Calls --------------------------------------------------------------// DEF_ADD_DATA(CallExpr, { // Function pointers don't have a callee and we just skip hashing it. - if (S->getDirectCallee()) - addData(S->getDirectCallee()->getQualifiedNameAsString()); + 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(); + std::string ArgString; + + // Print all template arguments into ArgString + llvm::raw_string_ostream OS(ArgString); + for (unsigned i = 0; i < Args->size(); ++i) { + Args->get(i).print(Context.getLangOpts(), OS); + // Add a padding character so that 'foo<X, XX>()' != 'foo<XX, X>()'. + OS << '\n'; + } + OS.flush(); + + addData(ArgString); + } + addData(D->getQualifiedNameAsString()); + } }) //--- Exceptions ---------------------------------------------------------// |