Index: include/clang/Analysis/CloneDetection.h =================================================================== --- include/clang/Analysis/CloneDetection.h +++ include/clang/Analysis/CloneDetection.h @@ -318,6 +318,17 @@ void constrain(std::vector &Result); }; +struct AutoGeneratedCloneConstraint { + bool isAutoGenerated(const CloneDetector::CloneGroup &Group); + + void constrain(std::vector &CloneGroups) { + CloneConstraint::filterGroups( + CloneGroups, [this](const CloneDetector::CloneGroup &Group) { + return isAutoGenerated(Group); + }); + } +}; + /// 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,25 @@ } } +bool AutoGeneratedCloneConstraint::isAutoGenerated(const CloneDetector::CloneGroup &Group) { + if (Group.empty()) + return false; + + for (const StmtSequence &S : Group) { + const Decl *D = S.getContainingDecl(); + 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) + return true; + } + } + + return false; +} + 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 @@ -78,7 +78,8 @@ // because reportSuspiciousClones() wants to search them for errors. std::vector AllCloneGroups; - Detector.findClones(AllCloneGroups, RecursiveCloneTypeIIConstraint(), + Detector.findClones(AllCloneGroups, AutoGeneratedCloneConstraint(), + RecursiveCloneTypeIIConstraint(), MinComplexityConstraint(MinComplexity), MinGroupSizeConstraint(2), OnlyLargestCloneConstraint());