Index: include/clang/Analysis/CloneDetection.h =================================================================== --- include/clang/Analysis/CloneDetection.h +++ include/clang/Analysis/CloneDetection.h @@ -318,6 +318,10 @@ void constrain(std::vector &Result); }; +struct AutoGeneratedCloneConstraint { + void constrain(std::vector &Result); +}; + /// Analyzes the pattern of the referenced variables in a statement. class VariablePattern { Index: lib/Analysis/CloneDetection.cpp =================================================================== --- lib/Analysis/CloneDetection.cpp +++ lib/Analysis/CloneDetection.cpp @@ -366,6 +366,38 @@ } } +void AutoGeneratedCloneConstraint::constrain( + std::vector &Result) { + std::vector IndexesToRemove; + unsigned i = 0; + + for (CloneDetector::CloneGroup &Group : Result) { + if (Group.empty()) + continue; + + for (const StmtSequence &S : Group) { + const Decl *D = S.getContainingDecl(); + if (D && D->isInvalidDecl()) { + SourceLocation sLoc = D->getLocation(); + const SourceManager &SM = D->getASTContext().getSourceManager(); + FileID fileID = SM.getFileID(sLoc); + const FileEntry *fileEntry = SM.getFileEntryForID(fileID); + if (fileEntry && fileEntry->isValid()) { + if (std::string(fileEntry->getName()).find("moc_") == 0) { + IndexesToRemove.push_back(i); + } + } + } + } + + i++; + } + + for (auto I = IndexesToRemove.rbegin(); I != IndexesToRemove.rend(); ++I) { + Result.erase(Result.begin() + *I); + } +} + static size_t createHash(llvm::MD5 &Hash) { size_t HashCode; Index: lib/StaticAnalyzer/Checkers/CloneChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/CloneChecker.cpp +++ lib/StaticAnalyzer/Checkers/CloneChecker.cpp @@ -80,7 +80,8 @@ Detector.findClones(AllCloneGroups, RecursiveCloneTypeIIConstraint(), MinComplexityConstraint(MinComplexity), - MinGroupSizeConstraint(2), OnlyLargestCloneConstraint()); + MinGroupSizeConstraint(2), OnlyLargestCloneConstraint(), + AutoGeneratedCloneConstraint()); if (ReportSuspiciousClones) reportSuspiciousClones(BR, Mgr, AllCloneGroups);