From 5619fb6d828a33054fabfcc9f848cf5d80c716c7 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Sun, 2 May 2021 16:43:55 -0400 Subject: [PATCH 01/10] Port clang-tidy-plugin to LLVM 12 --- .../clang-tidy-plugin/AlmostNeverAutoCheck.h | 1 + tools/clang-tidy-plugin/AssertCheck.cpp | 8 +- tools/clang-tidy-plugin/AssertCheck.h | 3 +- tools/clang-tidy-plugin/CMakeLists.txt | 4 +- .../CombineLocalsIntoPointCheck.cpp | 78 ++++++++++++++----- .../CombineLocalsIntoPointCheck.h | 18 ++++- tools/clang-tidy-plugin/DeterminismCheck.h | 1 + tools/clang-tidy-plugin/HeaderGuardCheck.cpp | 14 ++-- tools/clang-tidy-plugin/HeaderGuardCheck.h | 5 +- .../JsonTranslationInputCheck.h | 1 + tools/clang-tidy-plugin/NoLongCheck.cpp | 5 +- tools/clang-tidy-plugin/NoLongCheck.h | 3 +- .../clang-tidy-plugin/NoStaticGettextCheck.h | 1 + .../PointInitializationCheck.h | 1 + .../SimplifyPointConstructorsCheck.cpp | 3 + .../SimplifyPointConstructorsCheck.h | 1 + .../StaticDeclarationsCheck.h | 1 + .../StaticIntIdConstantsCheck.h | 1 + .../StaticStringIdConstantsCheck.h | 1 + tools/clang-tidy-plugin/TestFilenameCheck.cpp | 15 ++-- tools/clang-tidy-plugin/TestFilenameCheck.h | 3 +- .../TestsMustRestoreGlobalStateCheck.cpp | 6 +- .../TestsMustRestoreGlobalStateCheck.h | 3 +- tools/clang-tidy-plugin/TextStyleCheck.h | 1 + .../TranslatorCommentsCheck.cpp | 12 +-- .../TranslatorCommentsCheck.h | 4 +- .../UnsequencedCallsCheck.cpp | 4 +- .../clang-tidy-plugin/UnsequencedCallsCheck.h | 2 + tools/clang-tidy-plugin/UnusedStaticsCheck.h | 1 + .../UseLocalizedSortingCheck.h | 1 + .../UseNamedPointConstantsCheck.cpp | 2 +- .../UseNamedPointConstantsCheck.h | 1 + tools/clang-tidy-plugin/UsePointApisCheck.h | 1 + .../UsePointArithmeticCheck.cpp | 24 ++++-- .../UsePointArithmeticCheck.h | 1 + tools/clang-tidy-plugin/Utils.cpp | 8 +- tools/clang-tidy-plugin/Utils.h | 4 +- tools/clang-tidy-plugin/XYCheck.h | 1 + .../test/combine-locals-into-point.cpp | 11 ++- tools/clang-tidy-plugin/test/lit.cfg | 2 + .../test/use-localized-sorting.cpp | 8 +- 41 files changed, 182 insertions(+), 83 deletions(-) diff --git a/tools/clang-tidy-plugin/AlmostNeverAutoCheck.h b/tools/clang-tidy-plugin/AlmostNeverAutoCheck.h index 8d1500eb9a4c3..9917d55e71fdd 100644 --- a/tools/clang-tidy-plugin/AlmostNeverAutoCheck.h +++ b/tools/clang-tidy-plugin/AlmostNeverAutoCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/AssertCheck.cpp b/tools/clang-tidy-plugin/AssertCheck.cpp index d09d2bf926384..8f7e89d3013a6 100644 --- a/tools/clang-tidy-plugin/AssertCheck.cpp +++ b/tools/clang-tidy-plugin/AssertCheck.cpp @@ -3,6 +3,9 @@ #include #include "clang/Frontend/CompilerInstance.h" +#include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Lex/Token.h" using namespace clang::ast_matchers; @@ -46,10 +49,9 @@ class AssertMacroCallbacks : public PPCallbacks llvm::SmallPtrSet CataAssertLocations; }; -void AssertCheck::registerPPCallbacks( CompilerInstance &Compiler ) +void AssertCheck::registerPPCallbacks( const SourceManager &, Preprocessor *PP, Preprocessor * ) { - Compiler.getPreprocessor().addPPCallbacks( - llvm::make_unique( &Compiler.getPreprocessor(), this ) ); + PP->addPPCallbacks( std::make_unique( PP, this ) ); } void AssertCheck::registerMatchers( MatchFinder * /*Finder*/ ) diff --git a/tools/clang-tidy-plugin/AssertCheck.h b/tools/clang-tidy-plugin/AssertCheck.h index 4e0d1d253c156..82206016831a0 100644 --- a/tools/clang-tidy-plugin/AssertCheck.h +++ b/tools/clang-tidy-plugin/AssertCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { @@ -21,7 +22,7 @@ class AssertCheck : public ClangTidyCheck public: AssertCheck( StringRef Name, ClangTidyContext *Context ) : ClangTidyCheck( Name, Context ) {} - void registerPPCallbacks( CompilerInstance &Compiler ) override; + void registerPPCallbacks( const SourceManager &, Preprocessor *, Preprocessor * ) override; void registerMatchers( ast_matchers::MatchFinder *Finder ) override; void check( const ast_matchers::MatchFinder::MatchResult &Result ) override; }; diff --git a/tools/clang-tidy-plugin/CMakeLists.txt b/tools/clang-tidy-plugin/CMakeLists.txt index cf0c237645db7..47aa6df658153 100644 --- a/tools/clang-tidy-plugin/CMakeLists.txt +++ b/tools/clang-tidy-plugin/CMakeLists.txt @@ -38,12 +38,12 @@ target_include_directories(CataAnalyzerPlugin SYSTEM PRIVATE if ("${CATA_CLANG_TIDY_INCLUDE_DIR}" STREQUAL "") set(CTPS_RELEASES https://github.com/jbytheway/clang-tidy-plugin-support/releases/download) - set(CTPS_VERSION llvm-8.0.1-r12) + set(CTPS_VERSION llvm11.1.0-r4) set(CTPS_SRC ${CMAKE_CURRENT_BINARY_DIR}/clang-tidy-plugin-support) ExternalProject_Add(clang-tidy-plugin-support URL ${CTPS_RELEASES}/${CTPS_VERSION}/clang-tidy-plugin-support-${CTPS_VERSION}.tar.xz - URL_HASH SHA256=00ffab0df11250f394830735514c62ae787bd2eb6eb9d5e97471206d270c54e2 + URL_HASH SHA256=718c7a5bed9694ed3aa8e0cf629bdcfa304e12a995de56b9204bc8ab2af6a4aa SOURCE_DIR ${CTPS_SRC} CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/tools/clang-tidy-plugin/CombineLocalsIntoPointCheck.cpp b/tools/clang-tidy-plugin/CombineLocalsIntoPointCheck.cpp index 73c9e77614b72..481db826ea6cf 100644 --- a/tools/clang-tidy-plugin/CombineLocalsIntoPointCheck.cpp +++ b/tools/clang-tidy-plugin/CombineLocalsIntoPointCheck.cpp @@ -52,7 +52,7 @@ static bool nameExistsInContext( const DeclContext *Context, const std::string & { for( const Decl *D : Context->decls() ) { if( const NamedDecl *ND = dyn_cast( D ) ) { - if( ND->getName() == Name ) { + if( ND->getIdentifier() && ND->getName() == Name ) { return true; } } @@ -86,11 +86,6 @@ static void CheckDecl( CombineLocalsIntoPointCheck &Check, const MatchFinder::Ma return; } - // Only one modification per function - if( !Check.alteredFunctions.insert( getContainingFunction( Result, XDecl ) ).second ) { - return; - } - const Decl *NextDecl = XDecl->getNextDeclInContext(); const VarDecl *YDecl = dyn_cast_or_null( NextDecl ); if( !YDecl ) { @@ -135,6 +130,20 @@ static void CheckDecl( CombineLocalsIntoPointCheck &Check, const MatchFinder::Ma return; } + // Only one modification per function + const FunctionDecl *Func = getContainingFunction( Result, XDecl ); + + if( !Func ) { + return; + } + + auto FuncInsert = Check.alteredFunctions.emplace( + Func, FunctionReplacementData{ XDecl, YDecl, ZDecl, {}, {} } ); + if( !FuncInsert.second ) { + return; + } + FunctionReplacementData &FuncReplacement = FuncInsert.first->second; + if( ZDecl ) { const Stmt *ZGrandparentStmt = GetGrandparent( ZDecl ); @@ -213,16 +222,7 @@ static void CheckDecl( CombineLocalsIntoPointCheck &Check, const MatchFinder::Ma SourceLocation EndLoc = ZDecl ? ZDecl->getEndLoc() : YDecl->getEndLoc(); SourceRange RangeToReplace( XDecl->getBeginLoc(), EndLoc ); - std::string Message = ZDecl ? - "Variables %0, %1, and %2 could be combined into a single 'tripoint' variable." : - "Variables %0 and %1 could be combined into a single 'point' variable."; - Check.diag( XDecl->getBeginLoc(), Message ) - << XDecl << YDecl << ZDecl - << FixItHint::CreateReplacement( RangeToReplace, Replacement ); - Check.diag( YDecl->getLocation(), "%0 variable", DiagnosticIDs::Note ) << YDecl; - if( ZDecl ) { - Check.diag( ZDecl->getLocation(), "%0 variable", DiagnosticIDs::Note ) << ZDecl; - } + FuncReplacement.Fixits.push_back( FixItHint::CreateReplacement( RangeToReplace, Replacement ) ); } static void CheckDeclRef( CombineLocalsIntoPointCheck &Check, @@ -234,8 +234,8 @@ static void CheckDeclRef( CombineLocalsIntoPointCheck &Check, return; } - auto Replacement = Check.usageReplacements.find( Decl ); - if( Replacement == Check.usageReplacements.end() ) { + auto NewName = Check.usageReplacements.find( Decl ); + if( NewName == Check.usageReplacements.end() ) { return; } @@ -243,9 +243,17 @@ static void CheckDeclRef( CombineLocalsIntoPointCheck &Check, return; } - Check.diag( DeclRef->getBeginLoc(), "Update %0 to '%1'.", DiagnosticIDs::Note ) - << Decl << Replacement->second - << FixItHint::CreateReplacement( DeclRef->getSourceRange(), Replacement->second ); + auto Func = Check.alteredFunctions.find( getContainingFunction( Result, Decl ) ); + if( Func == Check.alteredFunctions.end() ) { + Check.diag( DeclRef->getBeginLoc(), "Internal check error finding replacement data for ref", + DiagnosticIDs::Error ); + return; + } + FunctionReplacementData &Replacement = Func->second; + Replacement.RefReplacements.push_back( + DeclRefReplacementData{ DeclRef, Decl, NewName->second } ); + Replacement.Fixits.push_back( + FixItHint::CreateReplacement( DeclRef->getSourceRange(), NewName->second ) ); } void CombineLocalsIntoPointCheck::check( const MatchFinder::MatchResult &Result ) @@ -254,6 +262,34 @@ void CombineLocalsIntoPointCheck::check( const MatchFinder::MatchResult &Result CheckDeclRef( *this, Result ); } +void CombineLocalsIntoPointCheck::onEndOfTranslationUnit() +{ + for( const std::pair &p : + alteredFunctions ) { + const FunctionReplacementData &data = p.second; + std::string Message = data.ZDecl ? + "Variables %0, %1, and %2 could be combined into a single 'tripoint' variable." : + "Variables %0 and %1 could be combined into a single 'point' variable."; + { + DiagnosticBuilder Diag = diag( data.XDecl->getBeginLoc(), Message ) + << data.XDecl << data.YDecl << data.ZDecl; + for( const FixItHint &FixIt : data.Fixits ) { + Diag << FixIt; + } + } + diag( data.YDecl->getLocation(), "%0 variable", DiagnosticIDs::Note ) << data.YDecl; + if( data.ZDecl ) { + diag( data.ZDecl->getLocation(), "%0 variable", DiagnosticIDs::Note ) + << data.ZDecl; + } + for( const DeclRefReplacementData &RefReplacment : data.RefReplacements ) { + diag( RefReplacment.DeclRef->getBeginLoc(), "Update %0 to '%1'.", + DiagnosticIDs::Note ) + << RefReplacment.Decl << RefReplacment.NewName; + } + } +} + } // namespace cata } // namespace tidy } // namespace clang diff --git a/tools/clang-tidy-plugin/CombineLocalsIntoPointCheck.h b/tools/clang-tidy-plugin/CombineLocalsIntoPointCheck.h index 7d489e54f4f49..ca0bd13134fc3 100644 --- a/tools/clang-tidy-plugin/CombineLocalsIntoPointCheck.h +++ b/tools/clang-tidy-plugin/CombineLocalsIntoPointCheck.h @@ -7,6 +7,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { @@ -18,6 +19,20 @@ class ClangTidyContext; namespace cata { +struct DeclRefReplacementData { + const DeclRefExpr *DeclRef; + const VarDecl *Decl; + std::string NewName; +}; + +struct FunctionReplacementData { + const VarDecl *XDecl; + const VarDecl *YDecl; + const VarDecl *ZDecl; + std::vector RefReplacements; + std::vector Fixits; +}; + class CombineLocalsIntoPointCheck : public ClangTidyCheck { public: @@ -25,10 +40,11 @@ class CombineLocalsIntoPointCheck : public ClangTidyCheck : ClangTidyCheck( Name, Context ) {} void registerMatchers( ast_matchers::MatchFinder *Finder ) override; void check( const ast_matchers::MatchFinder::MatchResult &Result ) override; + void onEndOfTranslationUnit() override; using ClangTidyCheck::getLangOpts; std::unordered_map usageReplacements; - std::unordered_set alteredFunctions; + std::unordered_map alteredFunctions; }; } // namespace cata diff --git a/tools/clang-tidy-plugin/DeterminismCheck.h b/tools/clang-tidy-plugin/DeterminismCheck.h index d848042ea0c14..baa5c014380b8 100644 --- a/tools/clang-tidy-plugin/DeterminismCheck.h +++ b/tools/clang-tidy-plugin/DeterminismCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/HeaderGuardCheck.cpp b/tools/clang-tidy-plugin/HeaderGuardCheck.cpp index 16894eaddd4fd..a733fa25e3441 100644 --- a/tools/clang-tidy-plugin/HeaderGuardCheck.cpp +++ b/tools/clang-tidy-plugin/HeaderGuardCheck.cpp @@ -3,6 +3,7 @@ #include #include +#include #if !defined(_MSC_VER) #include @@ -27,7 +28,7 @@ static std::string cleanPath( StringRef Path ) { SmallString<256> Result = Path; llvm::sys::path::remove_dots( Result, true ); - return Result.str(); + return Result.str().str(); } static bool pathExists( const std::string &path ) @@ -267,7 +268,7 @@ class HeaderGuardPPCallbacks : public PPCallbacks std::string CPPVar = getHeaderGuard( FileName ); if( CPPVar.empty() ) { - return CurHeaderGuard; + return CurHeaderGuard.str(); } if( Ifndef.isValid() && CurHeaderGuard != CPPVar ) { @@ -281,7 +282,7 @@ class HeaderGuardPPCallbacks : public PPCallbacks CPPVar ) ); return CPPVar; } - return CurHeaderGuard; + return CurHeaderGuard.str(); } /// \brief Checks the comment after the #endif of a header guard and fixes it @@ -379,11 +380,10 @@ class HeaderGuardPPCallbacks : public PPCallbacks CataHeaderGuardCheck *Check; }; -void CataHeaderGuardCheck::registerPPCallbacks( CompilerInstance &Compiler ) +void CataHeaderGuardCheck::registerPPCallbacks( + const SourceManager &, Preprocessor *PP, Preprocessor * ) { - Compiler.getPreprocessor().addPPCallbacks( - llvm::make_unique( &Compiler.getPreprocessor(), - this ) ); + PP->addPPCallbacks( std::make_unique( PP, this ) ); } } // namespace cata diff --git a/tools/clang-tidy-plugin/HeaderGuardCheck.h b/tools/clang-tidy-plugin/HeaderGuardCheck.h index d131504f578cd..5092472dfc6ee 100644 --- a/tools/clang-tidy-plugin/HeaderGuardCheck.h +++ b/tools/clang-tidy-plugin/HeaderGuardCheck.h @@ -1,7 +1,8 @@ #ifndef CATA_TOOLS_CLANG_TIDY_PLUGIN_HEADERGUARDCHECK_H #define CATA_TOOLS_CLANG_TIDY_PLUGIN_HEADERGUARDCHECK_H -#include +#include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { @@ -16,7 +17,7 @@ class CataHeaderGuardCheck : public ClangTidyCheck { public: CataHeaderGuardCheck( StringRef Name, ClangTidyContext *Context ); - void registerPPCallbacks( CompilerInstance &Compiler ) override; + void registerPPCallbacks( const SourceManager &, Preprocessor *, Preprocessor * ) override; }; } // namespace cata diff --git a/tools/clang-tidy-plugin/JsonTranslationInputCheck.h b/tools/clang-tidy-plugin/JsonTranslationInputCheck.h index 5a8147556444d..9459d027ab728 100644 --- a/tools/clang-tidy-plugin/JsonTranslationInputCheck.h +++ b/tools/clang-tidy-plugin/JsonTranslationInputCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/NoLongCheck.cpp b/tools/clang-tidy-plugin/NoLongCheck.cpp index 866a236dc1553..4fd84011d924a 100644 --- a/tools/clang-tidy-plugin/NoLongCheck.cpp +++ b/tools/clang-tidy-plugin/NoLongCheck.cpp @@ -55,10 +55,9 @@ class NoLongMacrosCallbacks : public PPCallbacks NoLongCheck *Check; }; -void NoLongCheck::registerPPCallbacks( CompilerInstance &Compiler ) +void NoLongCheck::registerPPCallbacks( const SourceManager &, Preprocessor *PP, Preprocessor * ) { - Compiler.getPreprocessor().addPPCallbacks( - llvm::make_unique( this ) ); + PP->addPPCallbacks( std::make_unique( this ) ); } void NoLongCheck::registerMatchers( MatchFinder *Finder ) diff --git a/tools/clang-tidy-plugin/NoLongCheck.h b/tools/clang-tidy-plugin/NoLongCheck.h index 58b259abec9ab..6c90eff5e6966 100644 --- a/tools/clang-tidy-plugin/NoLongCheck.h +++ b/tools/clang-tidy-plugin/NoLongCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { @@ -22,7 +23,7 @@ class NoLongCheck : public ClangTidyCheck public: NoLongCheck( StringRef Name, ClangTidyContext *Context ) : ClangTidyCheck( Name, Context ) {} - void registerPPCallbacks( CompilerInstance &Compiler ) override; + void registerPPCallbacks( const SourceManager &, Preprocessor *, Preprocessor * ) override; void registerMatchers( ast_matchers::MatchFinder *Finder ) override; void check( const ast_matchers::MatchFinder::MatchResult &Result ) override; }; diff --git a/tools/clang-tidy-plugin/NoStaticGettextCheck.h b/tools/clang-tidy-plugin/NoStaticGettextCheck.h index 5f4242a2fea44..a37712d3e357c 100644 --- a/tools/clang-tidy-plugin/NoStaticGettextCheck.h +++ b/tools/clang-tidy-plugin/NoStaticGettextCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/PointInitializationCheck.h b/tools/clang-tidy-plugin/PointInitializationCheck.h index a5b899c7c846a..71065f1212cfa 100644 --- a/tools/clang-tidy-plugin/PointInitializationCheck.h +++ b/tools/clang-tidy-plugin/PointInitializationCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/SimplifyPointConstructorsCheck.cpp b/tools/clang-tidy-plugin/SimplifyPointConstructorsCheck.cpp index 3793781215654..79d4c112fa415 100644 --- a/tools/clang-tidy-plugin/SimplifyPointConstructorsCheck.cpp +++ b/tools/clang-tidy-plugin/SimplifyPointConstructorsCheck.cpp @@ -58,6 +58,9 @@ struct ExpressionCategory { ExpressionCategory( const MatchFinder::MatchResult &Result, const Expr *E ) : Replacement( getText( Result, E ) ) { + if( StringRef( Replacement ).endswith( "->" ) ) { + Replacement.erase( Replacement.end() - 2, Replacement.end() ); + } QualType EType = E->getType(); if( EType->isPointerType() ) { IsArrowRef = true; diff --git a/tools/clang-tidy-plugin/SimplifyPointConstructorsCheck.h b/tools/clang-tidy-plugin/SimplifyPointConstructorsCheck.h index 7e16c3ae133f5..bc32972a7e349 100644 --- a/tools/clang-tidy-plugin/SimplifyPointConstructorsCheck.h +++ b/tools/clang-tidy-plugin/SimplifyPointConstructorsCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/StaticDeclarationsCheck.h b/tools/clang-tidy-plugin/StaticDeclarationsCheck.h index 11265013085fa..60d2541d0e2c5 100644 --- a/tools/clang-tidy-plugin/StaticDeclarationsCheck.h +++ b/tools/clang-tidy-plugin/StaticDeclarationsCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/StaticIntIdConstantsCheck.h b/tools/clang-tidy-plugin/StaticIntIdConstantsCheck.h index 0a9ec7ad42ac4..a8493f3ba2037 100644 --- a/tools/clang-tidy-plugin/StaticIntIdConstantsCheck.h +++ b/tools/clang-tidy-plugin/StaticIntIdConstantsCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/StaticStringIdConstantsCheck.h b/tools/clang-tidy-plugin/StaticStringIdConstantsCheck.h index 7a56037f0ace3..a84de5b7495e2 100644 --- a/tools/clang-tidy-plugin/StaticStringIdConstantsCheck.h +++ b/tools/clang-tidy-plugin/StaticStringIdConstantsCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/TestFilenameCheck.cpp b/tools/clang-tidy-plugin/TestFilenameCheck.cpp index 9f739c43732e4..d7b6f9e08dc3f 100644 --- a/tools/clang-tidy-plugin/TestFilenameCheck.cpp +++ b/tools/clang-tidy-plugin/TestFilenameCheck.cpp @@ -29,8 +29,8 @@ namespace cata class TestFilenameCallbacks : public PPCallbacks { public: - TestFilenameCallbacks( TestFilenameCheck *Check, CompilerInstance *Compiler ) : - Check( Check ), Compiler( Compiler ) {} + TestFilenameCallbacks( TestFilenameCheck *Check, const SourceManager *SrcM ) : + Check( Check ), SM( SrcM ) {} void MacroExpands( const Token &MacroNameTok, const MacroDefinition &, @@ -39,8 +39,7 @@ class TestFilenameCallbacks : public PPCallbacks StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName(); if( MacroName == "TEST_CASE" ) { - SourceManager &SM = Compiler->getSourceManager(); - StringRef Filename = SM.getBufferName( Range.getBegin() ); + StringRef Filename = SM->getBufferName( Range.getBegin() ); bool IsTestFilename = Filename.endswith( "_test.cpp" ); if( !IsTestFilename ) { @@ -52,13 +51,13 @@ class TestFilenameCallbacks : public PPCallbacks } private: TestFilenameCheck *Check; - CompilerInstance *Compiler; + const SourceManager *SM; }; -void TestFilenameCheck::registerPPCallbacks( CompilerInstance &Compiler ) +void TestFilenameCheck::registerPPCallbacks( const SourceManager &SM, Preprocessor *PP, + Preprocessor * ) { - Compiler.getPreprocessor().addPPCallbacks( - llvm::make_unique( this, &Compiler ) ); + PP->addPPCallbacks( std::make_unique( this, &SM ) ); } } // namespace cata diff --git a/tools/clang-tidy-plugin/TestFilenameCheck.h b/tools/clang-tidy-plugin/TestFilenameCheck.h index 74ebb865e5f5d..9464480e37115 100644 --- a/tools/clang-tidy-plugin/TestFilenameCheck.h +++ b/tools/clang-tidy-plugin/TestFilenameCheck.h @@ -4,6 +4,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { @@ -22,7 +23,7 @@ class TestFilenameCheck : public ClangTidyCheck TestFilenameCheck( StringRef Name, ClangTidyContext *Context ) : ClangTidyCheck( Name, Context ) {} - void registerPPCallbacks( CompilerInstance &Compiler ) override; + void registerPPCallbacks( const SourceManager &, Preprocessor *, Preprocessor * ) override; }; } // namespace cata diff --git a/tools/clang-tidy-plugin/TestsMustRestoreGlobalStateCheck.cpp b/tools/clang-tidy-plugin/TestsMustRestoreGlobalStateCheck.cpp index 1c73c216c90bc..87b9f218056cc 100644 --- a/tools/clang-tidy-plugin/TestsMustRestoreGlobalStateCheck.cpp +++ b/tools/clang-tidy-plugin/TestsMustRestoreGlobalStateCheck.cpp @@ -49,10 +49,10 @@ class TestsMustRestoreGlobalStateCallbacks : public PPCallbacks TestsMustRestoreGlobalStateCheck *Check; }; -void TestsMustRestoreGlobalStateCheck::registerPPCallbacks( CompilerInstance &Compiler ) +void TestsMustRestoreGlobalStateCheck::registerPPCallbacks( + const SourceManager &, Preprocessor *PP, Preprocessor * ) { - Compiler.getPreprocessor().addPPCallbacks( - llvm::make_unique( this ) ); + PP->addPPCallbacks( std::make_unique( this ) ); } void TestsMustRestoreGlobalStateCheck::registerMatchers( MatchFinder *Finder ) diff --git a/tools/clang-tidy-plugin/TestsMustRestoreGlobalStateCheck.h b/tools/clang-tidy-plugin/TestsMustRestoreGlobalStateCheck.h index 0b80f96e8a378..1093ae78e11d1 100644 --- a/tools/clang-tidy-plugin/TestsMustRestoreGlobalStateCheck.h +++ b/tools/clang-tidy-plugin/TestsMustRestoreGlobalStateCheck.h @@ -6,6 +6,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" #include "Utils.h" namespace clang @@ -54,7 +55,7 @@ class TestsMustRestoreGlobalStateCheck : public ClangTidyCheck public: TestsMustRestoreGlobalStateCheck( StringRef Name, ClangTidyContext *Context ); - void registerPPCallbacks( CompilerInstance &Compiler ) override; + void registerPPCallbacks( const SourceManager &, Preprocessor *, Preprocessor * ) override; void registerMatchers( ast_matchers::MatchFinder *Finder ) override; void check( const ast_matchers::MatchFinder::MatchResult &Result ) override; void onEndOfTranslationUnit() override; diff --git a/tools/clang-tidy-plugin/TextStyleCheck.h b/tools/clang-tidy-plugin/TextStyleCheck.h index 5d4101e006cec..951b3ee534463 100644 --- a/tools/clang-tidy-plugin/TextStyleCheck.h +++ b/tools/clang-tidy-plugin/TextStyleCheck.h @@ -6,6 +6,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/TranslatorCommentsCheck.cpp b/tools/clang-tidy-plugin/TranslatorCommentsCheck.cpp index ea658656902da..9ee4947f5cdac 100644 --- a/tools/clang-tidy-plugin/TranslatorCommentsCheck.cpp +++ b/tools/clang-tidy-plugin/TranslatorCommentsCheck.cpp @@ -199,13 +199,15 @@ class TranslatorCommentsCheck::TranslationMacroCallback : public PPCallbacks TranslatorCommentsCheck::TranslatorCommentsCheck( StringRef Name, ClangTidyContext *Context ) : ClangTidyCheck( Name, Context ), MatchingStarted( false ), - Handler( llvm::make_unique( *this ) ) {} + Handler( std::make_unique( *this ) ) {} -void TranslatorCommentsCheck::registerPPCallbacks( CompilerInstance &Compiler ) +TranslatorCommentsCheck::~TranslatorCommentsCheck() = default; + +void TranslatorCommentsCheck::registerPPCallbacks( + const SourceManager &SM, Preprocessor *PP, Preprocessor * ) { - Compiler.getPreprocessor().addCommentHandler( Handler.get() ); - Compiler.getPreprocessor().addPPCallbacks( - llvm::make_unique( *this, Compiler.getSourceManager() ) ); + PP->addCommentHandler( Handler.get() ); + PP->addPPCallbacks( std::make_unique( *this, SM ) ); } void TranslatorCommentsCheck::registerMatchers( MatchFinder *Finder ) diff --git a/tools/clang-tidy-plugin/TranslatorCommentsCheck.h b/tools/clang-tidy-plugin/TranslatorCommentsCheck.h index c0da879456af9..1d4f716c3f1bb 100644 --- a/tools/clang-tidy-plugin/TranslatorCommentsCheck.h +++ b/tools/clang-tidy-plugin/TranslatorCommentsCheck.h @@ -2,6 +2,7 @@ #define CATA_TOOLS_CLANG_TIDY_PLUGIN_TRANSLATORCOMMENTSCHECK_H #include +#include #include #include #include @@ -23,8 +24,9 @@ class TranslatorCommentsCheck : public ClangTidyCheck { public: TranslatorCommentsCheck( StringRef Name, ClangTidyContext *Context ); + ~TranslatorCommentsCheck(); - void registerPPCallbacks( CompilerInstance &Compiler ) override; + void registerPPCallbacks( const SourceManager &, Preprocessor *, Preprocessor * ) override; void registerMatchers( ast_matchers::MatchFinder *Finder ) override; void check( const ast_matchers::MatchFinder::MatchResult &Result ) override; void onEndOfTranslationUnit() override; diff --git a/tools/clang-tidy-plugin/UnsequencedCallsCheck.cpp b/tools/clang-tidy-plugin/UnsequencedCallsCheck.cpp index 2182b38aa73a8..26fe17f41ec41 100644 --- a/tools/clang-tidy-plugin/UnsequencedCallsCheck.cpp +++ b/tools/clang-tidy-plugin/UnsequencedCallsCheck.cpp @@ -43,7 +43,7 @@ void UnsequencedCallsCheck::registerMatchers( MatchFinder *Finder ) // everything between two sequence points. static const Expr *GetContainingSequenceStatement( ASTContext *Context, const Expr *Node ) { - for( const ast_type_traits::DynTypedNode &parent : Context->getParents( *Node ) ) { + for( const DynTypedNode &parent : Context->getParents( *Node ) ) { if( parent.get() ) { return Node; } @@ -79,7 +79,7 @@ static std::vector GetAncestorExpressions( ASTContext *Context, co const Expr *next; do { next = nullptr; - for( const ast_type_traits::DynTypedNode &parent : Context->getParents( *Node ) ) { + for( const DynTypedNode &parent : Context->getParents( *Node ) ) { if( const Expr *candidate = parent.get() ) { next = candidate; break; diff --git a/tools/clang-tidy-plugin/UnsequencedCallsCheck.h b/tools/clang-tidy-plugin/UnsequencedCallsCheck.h index 9d4dec47b85f0..6baeb6e9484a7 100644 --- a/tools/clang-tidy-plugin/UnsequencedCallsCheck.h +++ b/tools/clang-tidy-plugin/UnsequencedCallsCheck.h @@ -3,8 +3,10 @@ #include #include +#include #include "ClangTidy.h" +#include "ClangTidyCheck.h" #include "Utils.h" namespace clang diff --git a/tools/clang-tidy-plugin/UnusedStaticsCheck.h b/tools/clang-tidy-plugin/UnusedStaticsCheck.h index 0711759ca9bea..85ddcede4cb82 100644 --- a/tools/clang-tidy-plugin/UnusedStaticsCheck.h +++ b/tools/clang-tidy-plugin/UnusedStaticsCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/UseLocalizedSortingCheck.h b/tools/clang-tidy-plugin/UseLocalizedSortingCheck.h index 29586eba5e37e..b9e2a08829b7a 100644 --- a/tools/clang-tidy-plugin/UseLocalizedSortingCheck.h +++ b/tools/clang-tidy-plugin/UseLocalizedSortingCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/UseNamedPointConstantsCheck.cpp b/tools/clang-tidy-plugin/UseNamedPointConstantsCheck.cpp index 3423458d63677..4e9d08f3a6168 100644 --- a/tools/clang-tidy-plugin/UseNamedPointConstantsCheck.cpp +++ b/tools/clang-tidy-plugin/UseNamedPointConstantsCheck.cpp @@ -169,7 +169,7 @@ static void CheckConstructor( UseNamedPointConstantsCheck &Check, if( TempParent ) { SourceRangeToReplace = ConstructorCall->getSourceRange(); // Work around buggy source range for default parameters - const std::string ReplacedText = getText( Result, ConstructorCall ); + const StringRef ReplacedText = getText( Result, ConstructorCall ); if( ReplacedText.size() >= 2 && ReplacedText.substr( 0, 2 ) == "= " ) { Replacement = "= " + Replacement; } diff --git a/tools/clang-tidy-plugin/UseNamedPointConstantsCheck.h b/tools/clang-tidy-plugin/UseNamedPointConstantsCheck.h index 2e8bcf9861dd6..08dc965f4d998 100644 --- a/tools/clang-tidy-plugin/UseNamedPointConstantsCheck.h +++ b/tools/clang-tidy-plugin/UseNamedPointConstantsCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/UsePointApisCheck.h b/tools/clang-tidy-plugin/UsePointApisCheck.h index 5d14331872fd7..6cf6b0c6e09e4 100644 --- a/tools/clang-tidy-plugin/UsePointApisCheck.h +++ b/tools/clang-tidy-plugin/UsePointApisCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/UsePointArithmeticCheck.cpp b/tools/clang-tidy-plugin/UsePointArithmeticCheck.cpp index b28c7e4c4177c..2e92aa27bbce1 100644 --- a/tools/clang-tidy-plugin/UsePointArithmeticCheck.cpp +++ b/tools/clang-tidy-plugin/UsePointArithmeticCheck.cpp @@ -94,8 +94,9 @@ struct ExpressionComponent { coefficient( 1 ), isMember( false ), isArrowRef( false ), - isTripoint( false ) - {} + isTripoint( false ) { + complete_init(); + } ExpressionComponent( const MatchFinder::MatchResult &Result, const Expr *E, const CXXRecordDecl *MemberOf, bool IsArrowRef ) : @@ -103,8 +104,15 @@ struct ExpressionComponent { coefficient( 1 ), isMember( true ), isArrowRef( IsArrowRef ), - isTripoint( MemberOf->getName() == "tripoint" ) - {} + isTripoint( MemberOf->getName() == "tripoint" ) { + complete_init(); + } + + void complete_init() { + if( StringRef( objectRef ).endswith( "->" ) ) { + objectRef.erase( objectRef.end() - 2, objectRef.end() ); + } + } std::string objectRef; int coefficient; @@ -265,7 +273,7 @@ static std::vector decomposeExpr( const Expr *E, const std: } case Stmt::MaterializeTemporaryExprClass: { const MaterializeTemporaryExpr *Temp = cast( E ); - return decomposeExpr( Temp->GetTemporaryExpr(), Member, Result ); + return decomposeExpr( Temp->getSubExpr(), Member, Result ); } case Stmt::MemberExprClass: { const MemberExpr *MemEx = cast( E ); @@ -369,11 +377,11 @@ static void appendCoefficient( std::string &Result, int coefficient ) } } -static std::string writeConstructor( const std::string &TypeName, +static std::string writeConstructor( const StringRef TypeName, const std::set &Keys, std::map Args ) { - std::string Result = TypeName + "( "; + std::string Result = TypeName.str() + "( "; bool AnyLeftovers = false; for( const auto &Key : Keys ) { std::string &Leftover = Args[Key]; @@ -611,7 +619,7 @@ static void CheckConstructor( UsePointArithmeticCheck &Check, Keys.insert( Component.first ); } - std::string TargetTypeName; + StringRef TargetTypeName; if( Leftovers["z"].empty() ) { TargetTypeName = "point"; Keys.erase( "z" ); diff --git a/tools/clang-tidy-plugin/UsePointArithmeticCheck.h b/tools/clang-tidy-plugin/UsePointArithmeticCheck.h index f6010ea86bbbf..ca9c1dc08291c 100644 --- a/tools/clang-tidy-plugin/UsePointArithmeticCheck.h +++ b/tools/clang-tidy-plugin/UsePointArithmeticCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/Utils.cpp b/tools/clang-tidy-plugin/Utils.cpp index 00907ff7356f8..7bcc1196827a1 100644 --- a/tools/clang-tidy-plugin/Utils.cpp +++ b/tools/clang-tidy-plugin/Utils.cpp @@ -10,19 +10,19 @@ namespace cata NameConvention::NameConvention( StringRef xName ) { if( xName.endswith( "x" ) ) { - root = xName.drop_back(); + root = xName.drop_back().str(); capital = false; atEnd = true; } else if( xName.endswith( "X" ) ) { - root = xName.drop_back(); + root = xName.drop_back().str(); capital = true; atEnd = true; } else if( xName.startswith( "x" ) ) { - root = xName.drop_front(); + root = xName.drop_front().str(); capital = false; atEnd = false; } else if( xName.startswith( "X" ) ) { - root = xName.drop_front(); + root = xName.drop_front().str(); capital = true; atEnd = false; } else { diff --git a/tools/clang-tidy-plugin/Utils.h b/tools/clang-tidy-plugin/Utils.h index c84f1c0ddb9d4..cb132ebfc7a86 100644 --- a/tools/clang-tidy-plugin/Utils.h +++ b/tools/clang-tidy-plugin/Utils.h @@ -46,7 +46,7 @@ inline StringRef getText( const ast_matchers::MatchFinder::MatchResult &Result, template static const T *getParent( const ast_matchers::MatchFinder::MatchResult &Result, const U *Node ) { - for( const ast_type_traits::DynTypedNode &parent : Result.Context->getParents( *Node ) ) { + for( const DynTypedNode &parent : Result.Context->getParents( *Node ) ) { if( const T *Candidate = parent.get() ) { return Candidate; } @@ -59,7 +59,7 @@ template static const FunctionDecl *getContainingFunction( const ast_matchers::MatchFinder::MatchResult &Result, const T *Node ) { - for( const ast_type_traits::DynTypedNode &parent : Result.Context->getParents( *Node ) ) { + for( const DynTypedNode &parent : Result.Context->getParents( *Node ) ) { if( const Decl *Candidate = parent.get() ) { if( const FunctionDecl *ContainingFunction = dyn_cast( Candidate ) ) { return ContainingFunction; diff --git a/tools/clang-tidy-plugin/XYCheck.h b/tools/clang-tidy-plugin/XYCheck.h index 4493cc25b2e94..64555fdcd2095 100644 --- a/tools/clang-tidy-plugin/XYCheck.h +++ b/tools/clang-tidy-plugin/XYCheck.h @@ -5,6 +5,7 @@ #include #include "ClangTidy.h" +#include "ClangTidyCheck.h" namespace clang { diff --git a/tools/clang-tidy-plugin/test/combine-locals-into-point.cpp b/tools/clang-tidy-plugin/test/combine-locals-into-point.cpp index 75355e52fa809..a33a398f3f1aa 100644 --- a/tools/clang-tidy-plugin/test/combine-locals-into-point.cpp +++ b/tools/clang-tidy-plugin/test/combine-locals-into-point.cpp @@ -143,8 +143,6 @@ void g10() void g11() { - // When multiple changes to be done in one function, only perform one (to - // avoid overlapping replacements) static constexpr int x = 0; // CHECK-MESSAGES: warning: Variables 'x' and 'y' could be combined into a single 'point' variable. [cata-combine-locals-into-point] // CHECK-FIXES: static constexpr point p( 0, 1 ); @@ -159,3 +157,12 @@ void g12() const unsigned x1 = false; const unsigned y1 = true; } + +void g13() +{ + // Check that suppressing the first warning suppresses the rest. + // NOLINTNEXTLINE(cata-combine-locals-into-point) + int rx = 7; + int ry = 14; + f0( point( rx, ry ) ); +} diff --git a/tools/clang-tidy-plugin/test/lit.cfg b/tools/clang-tidy-plugin/test/lit.cfg index 496804316adfa..7bacf442b3d47 100644 --- a/tools/clang-tidy-plugin/test/lit.cfg +++ b/tools/clang-tidy-plugin/test/lit.cfg @@ -17,6 +17,8 @@ else: config.plugin_build_root, 'clang-tidy-plugin-support', 'bin', 'check_clang_tidy.py') +check_clang_tidy += ' -std=c++14' + cata_include = os.path.join( config.cata_source_dir, "src" ) cata_plugin = os.path.join( diff --git a/tools/clang-tidy-plugin/test/use-localized-sorting.cpp b/tools/clang-tidy-plugin/test/use-localized-sorting.cpp index 5914548437b96..d3b6c31bad7b5 100644 --- a/tools/clang-tidy-plugin/test/use-localized-sorting.cpp +++ b/tools/clang-tidy-plugin/test/use-localized-sorting.cpp @@ -63,7 +63,7 @@ bool f1( const NonString &l, const NonString &r ) bool f2( const std::pair &l, const std::pair &r ) { return l < r; - // CHECK-MESSAGES: warning: Raw comparison of 'const std::pair' (aka 'const pair >'). For UI purposes please use localized_compare from translations.h. [cata-use-localized-sorting] + // CHECK-MESSAGES: warning: Raw comparison of 'const std::pair' (aka 'const pair>'). For UI purposes please use localized_compare from translations.h. [cata-use-localized-sorting] } bool f3( const std::pair &l, const std::pair &r ) @@ -74,7 +74,7 @@ bool f3( const std::pair &l, const std::pair &r bool f4( const std::tuple &l, const std::tuple &r ) { return l < r; - // CHECK-MESSAGES: warning: Raw comparison of 'const std::tuple' (aka 'const tuple >'). For UI purposes please use localized_compare from translations.h. [cata-use-localized-sorting] + // CHECK-MESSAGES: warning: Raw comparison of 'const std::tuple' (aka 'const tuple>'). For UI purposes please use localized_compare from translations.h. [cata-use-localized-sorting] } bool f5( const std::tuple &l, const std::tuple &r ) @@ -86,7 +86,7 @@ bool f4( const std::tuple> &l, const std::tuple> &r ) { return l < r; - // CHECK-MESSAGES: warning: Raw comparison of 'const std::tuple >' (aka 'const tuple > >'). For UI purposes please use localized_compare from translations.h. [cata-use-localized-sorting] + // CHECK-MESSAGES: warning: Raw comparison of 'const std::tuple>' (aka 'const tuple>>'). For UI purposes please use localized_compare from translations.h. [cata-use-localized-sorting] } bool sort0( const std::string *start, const std::string *end ) @@ -103,7 +103,7 @@ bool sort1( const NonString *start, const NonString *end ) bool sortit0( iterator start, iterator end ) { std::sort( start, end ); - // CHECK-MESSAGES: warning: Raw sort of 'std::basic_string, std::allocator >'. For UI purposes please use localized_compare from translations.h. [cata-use-localized-sorting] + // CHECK-MESSAGES: warning: Raw sort of 'std::basic_string'. For UI purposes please use localized_compare from translations.h. [cata-use-localized-sorting] } bool sortit1( iterator start, iterator end ) From 22b1bd37474eaec5e879d4ea28debac8bd708117 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Sun, 2 May 2021 17:11:13 -0400 Subject: [PATCH 02/10] Update build script and workflow for LLVM 12 --- .github/workflows/clang-tidy.yml | 13 +++++++------ build-scripts/build.sh | 8 ++++---- tools/clang-tidy-plugin/CMakeLists.txt | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 6d888a7be574c..2a0bdb2527434 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -1,4 +1,4 @@ -name: Clang-tidy (clang-8, tiles) +name: Clang-tidy (clang-12, tiles) on: push: @@ -28,11 +28,11 @@ on: jobs: build: - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 env: CMAKE: 1 - CLANG: clang++-8 - COMPILER: clang++-8 + CLANG: clang++-12 + COMPILER: clang++-12 CATA_CLANG_TIDY: plugin TILES: 1 SOUND: 1 @@ -43,9 +43,10 @@ jobs: fetch-depth: 1 - name: install dependencies run: | - #sudo apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main" + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main" sudo apt-get update - sudo apt-get install libncursesw5-dev clang-8 libclang-8-dev llvm-8-dev llvm-8-tools \ + sudo apt-get install libncursesw5-dev clang-12 libclang-12-dev llvm-12-dev llvm-12-tools \ libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libpulse-dev ccache \ gettext - name: prepare diff --git a/build-scripts/build.sh b/build-scripts/build.sh index 8e1dbdebdd9a1..4afe678a11484 100755 --- a/build-scripts/build.sh +++ b/build-scripts/build.sh @@ -71,16 +71,16 @@ then cmake_extra_opts+=("-DCATA_CLANG_TIDY_PLUGIN=ON") # Need to specify the particular LLVM / Clang versions to use, lest it # use the llvm-7 that comes by default on the Travis Xenial image. - cmake_extra_opts+=("-DLLVM_DIR=/usr/lib/llvm-8/lib/cmake/llvm") - cmake_extra_opts+=("-DClang_DIR=/usr/lib/llvm-8/lib/cmake/clang") + cmake_extra_opts+=("-DLLVM_DIR=/usr/lib/llvm-12/lib/cmake/llvm") + cmake_extra_opts+=("-DClang_DIR=/usr/lib/llvm-12/lib/cmake/clang") fi - if [ "$COMPILER" = "clang++-8" -a -n "$GITHUB_WORKFLOW" -a -n "$CATA_CLANG_TIDY" ] + if [ "$COMPILER" = "clang++-12" -a -n "$GITHUB_WORKFLOW" -a -n "$CATA_CLANG_TIDY" ] then # This is a hacky workaround for the fact that the custom clang-tidy we are # using is built for Travis CI, so it's not using the correct include directories # for GitHub workflows. - cmake_extra_opts+=("-DCMAKE_CXX_FLAGS=-isystem /usr/include/clang/8.0.0/include") + cmake_extra_opts+=("-DCMAKE_CXX_FLAGS=-isystem /usr/include/clang/12.0.0/include") fi mkdir build diff --git a/tools/clang-tidy-plugin/CMakeLists.txt b/tools/clang-tidy-plugin/CMakeLists.txt index 47aa6df658153..b070c60f744aa 100644 --- a/tools/clang-tidy-plugin/CMakeLists.txt +++ b/tools/clang-tidy-plugin/CMakeLists.txt @@ -38,12 +38,12 @@ target_include_directories(CataAnalyzerPlugin SYSTEM PRIVATE if ("${CATA_CLANG_TIDY_INCLUDE_DIR}" STREQUAL "") set(CTPS_RELEASES https://github.com/jbytheway/clang-tidy-plugin-support/releases/download) - set(CTPS_VERSION llvm11.1.0-r4) + set(CTPS_VERSION llvm-12.0.0-r1) set(CTPS_SRC ${CMAKE_CURRENT_BINARY_DIR}/clang-tidy-plugin-support) ExternalProject_Add(clang-tidy-plugin-support URL ${CTPS_RELEASES}/${CTPS_VERSION}/clang-tidy-plugin-support-${CTPS_VERSION}.tar.xz - URL_HASH SHA256=718c7a5bed9694ed3aa8e0cf629bdcfa304e12a995de56b9204bc8ab2af6a4aa + URL_HASH SHA256=40626a0cb132b6eb137c4c7b5b1a04a0c96623c076790b848cc577b95a8889c5 SOURCE_DIR ${CTPS_SRC} CONFIGURE_COMMAND "" BUILD_COMMAND "" From 0af763a8e0dc1671bec1a314ddef86949dd1c486 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Mon, 3 May 2021 06:40:45 -0400 Subject: [PATCH 03/10] Disable new warnings from LLVM 12 --- .clang-tidy | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index 1e041e5b16011..8cb0b5ce153dc 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -46,18 +46,47 @@ modernize-*,\ performance-*,\ readability-*,\ -readability-braces-around-statements,\ +-bugprone-branch-clone,\ +-bugprone-infinite-loop,\ -bugprone-misplaced-widening-cast,\ -bugprone-narrowing-conversions,\ +-bugprone-redundant-branch-condition,\ +-bugprone-reserved-identifier,\ +-bugprone-signed-char-misuse,\ +-bugprone-sizeof-expression,\ +-bugprone-unhandled-self-assignment,\ +-cata-combine-locals-into-point,\ +-cert-dcl37-c,\ +-cert-dcl51-cpp,\ +-cert-oop54-cpp,\ +-cert-str34-c,\ +-clang-analyzer-core.CallAndMessage,\ +-clang-analyzer-deadcode.DeadStores,\ +-misc-misplaced-const,\ +-misc-no-recursion,\ -misc-non-private-member-variables-in-classes,\ +-misc-redundant-expression,\ +-modernize-avoid-bind,\ -modernize-avoid-c-arrays,\ +-modernize-loop-convert,\ -modernize-pass-by-value,\ -modernize-return-braced-init-list,\ -modernize-use-default-member-init,\ +-modernize-use-override,\ +-performance-no-automatic-move,\ +-performance-trivially-destructible,\ -performance-unnecessary-value-param,\ +-readability-avoid-const-params-in-decls,\ +-readability-convert-member-functions-to-static,\ -readability-else-after-return,\ +-readability-function-cognitive-complexity,\ -readability-implicit-bool-conversion,\ -readability-magic-numbers,\ +-readability-make-member-function-const,\ -readability-named-parameter,\ +-readability-qualified-auto,\ +-readability-redundant-access-specifiers,\ +-readability-use-anyofallof,\ " WarningsAsErrors: '*' HeaderFilterRegex: '(src|test|tools).*' From 3714f994822a002914cb34412bc6159858469fe5 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Tue, 4 May 2021 07:06:29 -0400 Subject: [PATCH 04/10] Add version sanity check to module Strange errors can arise if the plugin is loaded into the wrong clang version. Add a check to verify that the versions match. --- tools/clang-tidy-plugin/CataTidyModule.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/clang-tidy-plugin/CataTidyModule.cpp b/tools/clang-tidy-plugin/CataTidyModule.cpp index b7cb4df22c32c..76e4a05efd101 100644 --- a/tools/clang-tidy-plugin/CataTidyModule.cpp +++ b/tools/clang-tidy-plugin/CataTidyModule.cpp @@ -1,3 +1,4 @@ +#include #include #include "AlmostNeverAutoCheck.h" @@ -38,6 +39,16 @@ class CataModule : public ClangTidyModule { public: void addCheckFactories( ClangTidyCheckFactories &CheckFactories ) override { + // Sanity check the clang version to verify that we're loaded into + // the same version we linked against + + std::string RuntimeVersion = getClangFullVersion(); + if( !StringRef( RuntimeVersion ).contains( "clang version " CLANG_VERSION_STRING ) ) { + llvm::report_fatal_error( + Twine( "clang version mismatch in CataTidyModule. Compiled against " + CLANG_VERSION_STRING " but loaded by ", RuntimeVersion ) ); + abort(); + } CheckFactories.registerCheck( "cata-almost-never-auto" ); CheckFactories.registerCheck( "cata-assert" ); CheckFactories.registerCheck( From c704ceb99af0219d1bda29adc6a0772abe3665b8 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Tue, 4 May 2021 13:28:35 -0400 Subject: [PATCH 05/10] Update DEVELOPER_TOOLING for LLVM 12 --- doc/DEVELOPER_TOOLING.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/DEVELOPER_TOOLING.md b/doc/DEVELOPER_TOOLING.md index 65d16f7860e3c..a31d9759a76f1 100644 --- a/doc/DEVELOPER_TOOLING.md +++ b/doc/DEVELOPER_TOOLING.md @@ -66,7 +66,7 @@ In addition to the usual means of creating a `tags` file via e.g. [`ctags`](http Cataclysm has a [clang-tidy configuration file](../.clang-tidy) and if you have `clang-tidy` available you can run it to perform static analysis of the -codebase. We test with `clang-tidy` from LLVM 8.0.1 on Travis, so for the most +codebase. We test with `clang-tidy` from LLVM 12.0.0 on CI, so for the most consistent results, you might want to use that version. To run it you have a few options. @@ -92,12 +92,12 @@ We have written our own clang-tidy checks in a custom plugin. Unfortunately, `clang-tidy` as distributed by LLVM doesn't support plugins, so making this work requires some extra steps. -#### Ubuntu Xenial +#### Ubuntu Focal -If you are on Ubuntu Xenial then you might be able to get it working the same -way Travis does. Add the LLVM 8 Xenial source [listed -here](https://apt.llvm.org/) to your `sources.list`, install the `clang-8 -libclang-8-dev llvm-8-dev llvm-8-tools` packages, and build Cataclysm with CMake, +If you are on Ubuntu Focal then you might be able to get it working the same +way CI does. Add the LLVM 12 Focal source [listed +here](https://apt.llvm.org/) to your `sources.list`, install the `clang-12 +libclang-12-dev llvm-12-dev llvm-12-tools` packages, and build Cataclysm with CMake, adding `-DCATA_CLANG_TIDY_PLUGIN=ON`. On other distributions you will probably need to build `clang-tidy` yourself. @@ -154,7 +154,7 @@ First, clone the llvm repo from for example [the official github repo](https://g Checkout the `release/8.x` branch, since that's where our patch was based on. On Windows, instead of applying the patch mentioned in the previous section, you -shoud apply `plugin-support.patch` from [this PR](https://github.com/jbytheway/clang-tidy-plugin-support/pull/1) +should apply `plugin-support.patch` from [this PR](https://github.com/jbytheway/clang-tidy-plugin-support/pull/1) instead, if it's not merged yet. This is because the `-rdynamic` option is not supported on Windows, so clang-tidy needs to be built as a static library instead. (If you cloned the repo from the official github repo, replace `tools/extra` with @@ -185,7 +185,7 @@ cmake \ The next step is to call `make` to actually build clang-tidy as a library. When using MinGW-w64 to build, you should call `mingw32-make` instead. Also, because `FileCheck` is not shipped with Windows, you'll also need to build -it youself using llvm sources by adding the `FileCheck` target to the make command. +it yourself using llvm sources by adding the `FileCheck` target to the make command. ```sh mkdir -p build From 7a336be5d1c43392efd4f8005905d940bbdde829 Mon Sep 17 00:00:00 2001 From: Qrox Date: Wed, 5 May 2021 22:41:00 +0800 Subject: [PATCH 06/10] Update clang-tidy plugin docs for Windows --- doc/DEVELOPER_TOOLING.md | 74 +++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/doc/DEVELOPER_TOOLING.md b/doc/DEVELOPER_TOOLING.md index a31d9759a76f1..7fbbb3bb768f7 100644 --- a/doc/DEVELOPER_TOOLING.md +++ b/doc/DEVELOPER_TOOLING.md @@ -141,8 +141,7 @@ lit -v build/tools/clang-tidy-plugin/test To build llvm on Windows, you'll first need to get some tools installed. - Cmake -- Python 3 (Python 2 may be still required to run the lit test, -which will be discussed in the next section.) +- Python 3 - MinGW-w64 (other compilers may or may not work. Clang itself does not seem to be building llvm on Windows correctly.) - A shell environment @@ -151,14 +150,10 @@ After the tools are installed, a patch still needs to be applied before building llvm, since `clang-tidy` as distributed by LLVM doesn't support plugins. First, clone the llvm repo from for example [the official github repo](https://github.com/llvm/llvm-project.git). -Checkout the `release/8.x` branch, since that's where our patch was based on. +Checkout the `release/12.x` branch, since that's where our patch was based on. -On Windows, instead of applying the patch mentioned in the previous section, you -should apply `plugin-support.patch` from [this PR](https://github.com/jbytheway/clang-tidy-plugin-support/pull/1) -instead, if it's not merged yet. This is because the `-rdynamic` option is not -supported on Windows, so clang-tidy needs to be built as a static library instead. -(If you cloned the repo from the official github repo, replace `tools/extra` with -`clang-tools-extra` in the patch before applying it.) +On Windows, in addition to applying `plugin-support.patch` mentioned in the previous section, you +should also apply `clang-tidy-scripts.patch` (from [this PR](https://github.com/jbytheway/clang-tidy-plugin-support/pull/3), if it is not merged yet) so you can run the lit test with the custom clang-tidy executable and let clang-tidy apply suggestions automatically. After the patch is applied, you can then build the llvm code. Unfortunately, it seems that clang itself cannot correctly compile the llvm code on Windows (gives @@ -202,7 +197,7 @@ After building clang-tidy as a library from the llvm source, the next step is to build clang-tidy as an executable, with the custom checks from the CDDA source. In this step, the following tools are required. -- Python 3 (Python 2 may still be required to run the lit test for the custom checks) +- Python 3 - CMake - MinGW-w64 - FileCheck (built from the llvm source) @@ -221,34 +216,53 @@ be applied before the custom checks can be built as an executable. ```patch diff --git a/tools/clang-tidy-plugin/CMakeLists.txt b/tools/clang-tidy-plugin/CMakeLists.txt -index 553ef0ebe0..f591bc80d1 100644 +index cf0c237645..540d3e29a5 100644 --- a/tools/clang-tidy-plugin/CMakeLists.txt +++ b/tools/clang-tidy-plugin/CMakeLists.txt -@@ -3,8 +3,8 @@ include(ExternalProject) +@@ -4,7 +4,7 @@ include(ExternalProject) find_package(LLVM REQUIRED CONFIG) find_package(Clang REQUIRED CONFIG) --add_library( -- CataAnalyzerPlugin MODULE -+add_executable( -+ CataAnalyzerPlugin - CataTidyModule.cpp - JsonTranslationInputCheck.cpp - NoLongCheck.cpp -@@ -51,6 +51,11 @@ else() - CataAnalyzerPlugin SYSTEM PRIVATE ${CATA_CLANG_TIDY_INCLUDE_DIR}) - endif() +-add_library(CataAnalyzerPlugin MODULE ++add_executable(CataAnalyzerPlugin + AlmostNeverAutoCheck.cpp + AssertCheck.cpp + CataTidyModule.cpp +@@ -56,6 +56,11 @@ else () + target_include_directories(CataAnalyzerPlugin SYSTEM PRIVATE ${CATA_CLANG_TIDY_INCLUDE_DIR}) + endif () +target_link_libraries( + CataAnalyzerPlugin + clangTidyMain + ) + - target_compile_definitions( - CataAnalyzerPlugin PRIVATE ${LLVM_DEFINITIONS}) + target_compile_definitions(CataAnalyzerPlugin PRIVATE ${LLVM_DEFINITIONS}) + + # We need to turn off exceptions and RTTI to match the LLVM build. +diff --git a/tools/clang-tidy-plugin/CataTidyModule.cpp b/tools/clang-tidy-plugin/CataTidyModule.cpp +index b7cb4df22c..a83db0c60e 100644 +--- a/tools/clang-tidy-plugin/CataTidyModule.cpp ++++ b/tools/clang-tidy-plugin/CataTidyModule.cpp +@@ -18,6 +18,7 @@ + #include "TestFilenameCheck.h" + #include "TestsMustRestoreGlobalStateCheck.h" + #include "TextStyleCheck.h" ++#include "tool/ClangTidyMain.h" + #include "TranslatorCommentsCheck.h" + #include "UnsequencedCallsCheck.h" + #include "UnusedStaticsCheck.h" +@@ -80,3 +81,8 @@ X( "cata-module", "Adds Cataclysm-DDA checks." ); + } // namespace tidy + } // namespace clang ++ ++int main( int argc, const char **argv ) ++{ ++ return clang::tidy::clangTidyMain( argc, argv ); ++} diff --git a/tools/clang-tidy-plugin/test/lit.cfg b/tools/clang-tidy-plugin/test/lit.cfg -index 4ab6e913a7..d1a4418ba6 100644 +index 496804316a..43beb49653 100644 --- a/tools/clang-tidy-plugin/test/lit.cfg +++ b/tools/clang-tidy-plugin/test/lit.cfg @@ -17,11 +17,13 @@ else: @@ -271,12 +285,10 @@ index 4ab6e913a7..d1a4418ba6 100644 The next step is to run CMake to generate the compilation database. The compilation database contains compiler flags that clang-tidy uses to check the source files. -Make sure Python 3 (and Python 2 if it's still required), CMake, MinGW-w64, and FileCheck are on the path. +Make sure Python 3, CMake, MinGW-w64, and FileCheck are on the path. Note that two `bin` directories of MinGW-w64 should be on the path: `/bin`, and `/x86_64-w64-mingw32/bin`. FileCheck's path is `/build/bin`, -if you built it with the instructions in the previous section. Python 2 should -precede Python 3 in the path, otherwise scripts that are intended to run with -Python 2 might not work. +if you built it with the instructions in the previous section. Then add the following CMake options to generate the compilation database (substitute values inside `<>` with the actual paths) and build the CDDA source @@ -299,10 +311,10 @@ with Python 3 to fix some errors in the compilation database. Then the compilati database should be usable by clang-tidy. If you want to check if the custom checks are working correctly, run the following -script. Note that `python` here is the executable from Python 2. +script. ```sh -python /llvm/utils/lit/lit.py -v build/tools/clang-tidy-plugin/test +python3 /llvm/utils/lit/lit.py -v build/tools/clang-tidy-plugin/test ``` Finally, use the following command to run clang-tidy with the custom checks. From f328b005bd88573052364695d10af315e9a196ee Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Tue, 18 May 2021 06:58:27 -0400 Subject: [PATCH 07/10] Bump CTPS version to llvm-12.0.0-r3 --- tools/clang-tidy-plugin/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/clang-tidy-plugin/CMakeLists.txt b/tools/clang-tidy-plugin/CMakeLists.txt index b070c60f744aa..900ee496b43f1 100644 --- a/tools/clang-tidy-plugin/CMakeLists.txt +++ b/tools/clang-tidy-plugin/CMakeLists.txt @@ -38,12 +38,12 @@ target_include_directories(CataAnalyzerPlugin SYSTEM PRIVATE if ("${CATA_CLANG_TIDY_INCLUDE_DIR}" STREQUAL "") set(CTPS_RELEASES https://github.com/jbytheway/clang-tidy-plugin-support/releases/download) - set(CTPS_VERSION llvm-12.0.0-r1) + set(CTPS_VERSION llvm-12.0.0-r3) set(CTPS_SRC ${CMAKE_CURRENT_BINARY_DIR}/clang-tidy-plugin-support) ExternalProject_Add(clang-tidy-plugin-support URL ${CTPS_RELEASES}/${CTPS_VERSION}/clang-tidy-plugin-support-${CTPS_VERSION}.tar.xz - URL_HASH SHA256=40626a0cb132b6eb137c4c7b5b1a04a0c96623c076790b848cc577b95a8889c5 + URL_HASH SHA256=c84aaf35b4d5bb9130b1cc309a92146ae5c62fd69db30a6254725beac9d60990 SOURCE_DIR ${CTPS_SRC} CONFIGURE_COMMAND "" BUILD_COMMAND "" From c7d76abf8f50116f08dd7c2af5793ee8de9d21d8 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Tue, 18 May 2021 11:38:35 -0400 Subject: [PATCH 08/10] Update clang-tidy-scripts.patch link Now that this patch is merged to master, we need no longer refer to a PR. --- doc/DEVELOPER_TOOLING.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/DEVELOPER_TOOLING.md b/doc/DEVELOPER_TOOLING.md index 7fbbb3bb768f7..b68ff30815e14 100644 --- a/doc/DEVELOPER_TOOLING.md +++ b/doc/DEVELOPER_TOOLING.md @@ -153,7 +153,10 @@ First, clone the llvm repo from for example [the official github repo](https://g Checkout the `release/12.x` branch, since that's where our patch was based on. On Windows, in addition to applying `plugin-support.patch` mentioned in the previous section, you -should also apply `clang-tidy-scripts.patch` (from [this PR](https://github.com/jbytheway/clang-tidy-plugin-support/pull/3), if it is not merged yet) so you can run the lit test with the custom clang-tidy executable and let clang-tidy apply suggestions automatically. +should also apply +[`clang-tidy-scripts.patch`](https://github.com/jbytheway/clang-tidy-plugin-support/blob/master/clang-tidy-scripts.patch) +so you can run the lit test with the custom clang-tidy executable and let +clang-tidy apply suggestions automatically. After the patch is applied, you can then build the llvm code. Unfortunately, it seems that clang itself cannot correctly compile the llvm code on Windows (gives From 3e400cbb2eafbaecc6576ec41731cf70ae373420 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Tue, 18 May 2021 12:36:44 -0400 Subject: [PATCH 09/10] Minor grammar/style fixes Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com> --- doc/DEVELOPER_TOOLING.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/DEVELOPER_TOOLING.md b/doc/DEVELOPER_TOOLING.md index b68ff30815e14..937a85b82a792 100644 --- a/doc/DEVELOPER_TOOLING.md +++ b/doc/DEVELOPER_TOOLING.md @@ -66,10 +66,10 @@ In addition to the usual means of creating a `tags` file via e.g. [`ctags`](http Cataclysm has a [clang-tidy configuration file](../.clang-tidy) and if you have `clang-tidy` available you can run it to perform static analysis of the -codebase. We test with `clang-tidy` from LLVM 12.0.0 on CI, so for the most +codebase. We test with `clang-tidy` from LLVM 12.0.0 with CI, so for the most consistent results, you might want to use that version. -To run it you have a few options. +To run it, you have a few options. * `clang-tidy` ships with a wrapper script `run-clang-tidy.py`. @@ -95,9 +95,9 @@ work requires some extra steps. #### Ubuntu Focal If you are on Ubuntu Focal then you might be able to get it working the same -way CI does. Add the LLVM 12 Focal source [listed -here](https://apt.llvm.org/) to your `sources.list`, install the `clang-12 -libclang-12-dev llvm-12-dev llvm-12-tools` packages, and build Cataclysm with CMake, +way our CI does. Add the LLVM 12 Focal source [listed +here](https://apt.llvm.org/) to your `sources.list`, install the needed packages (`clang-12 +libclang-12-dev llvm-12-dev llvm-12-tools`), and build Cataclysm with CMake, adding `-DCATA_CLANG_TIDY_PLUGIN=ON`. On other distributions you will probably need to build `clang-tidy` yourself. @@ -149,8 +149,8 @@ building llvm on Windows correctly.) After the tools are installed, a patch still needs to be applied before building llvm, since `clang-tidy` as distributed by LLVM doesn't support plugins. -First, clone the llvm repo from for example [the official github repo](https://github.com/llvm/llvm-project.git). -Checkout the `release/12.x` branch, since that's where our patch was based on. +First, clone the llvm repo from, for example, [the official github repo](https://github.com/llvm/llvm-project.git). +Checkout the `release/12.x` branch, since that's what our patch was based on. On Windows, in addition to applying `plugin-support.patch` mentioned in the previous section, you should also apply From 8216b65dc7df40124f0798ee73d8c80ded12f4e4 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Thu, 20 May 2021 09:15:47 -0400 Subject: [PATCH 10/10] Capitalize LLVM consistently --- doc/DEVELOPER_TOOLING.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/DEVELOPER_TOOLING.md b/doc/DEVELOPER_TOOLING.md index 937a85b82a792..5f31b77d0194a 100644 --- a/doc/DEVELOPER_TOOLING.md +++ b/doc/DEVELOPER_TOOLING.md @@ -126,7 +126,7 @@ To run `clang-tidy` with this plugin enabled add the to your `clang-tidy` command line. If you wish to run the tests for the custom clang-tidy plugin you will also -need `lit`. This will be built as part of `llvm`, or you can install it via +need `lit`. This will be built as part of LLVM, or you can install it via `pip` or your local package manager if you prefer. Then, assuming `build` is your Cataclysm build directory, you can run the tests @@ -139,17 +139,17 @@ lit -v build/tools/clang-tidy-plugin/test ##### Build LLVM -To build llvm on Windows, you'll first need to get some tools installed. +To build LLVM on Windows, you'll first need to get some tools installed. - Cmake - Python 3 - MinGW-w64 (other compilers may or may not work. Clang itself does not seem to be -building llvm on Windows correctly.) +building LLVM on Windows correctly.) - A shell environment After the tools are installed, a patch still needs to be applied before building -llvm, since `clang-tidy` as distributed by LLVM doesn't support plugins. +LLVM, since `clang-tidy` as distributed by LLVM doesn't support plugins. -First, clone the llvm repo from, for example, [the official github repo](https://github.com/llvm/llvm-project.git). +First, clone the LLVM repo from, for example, [the official github repo](https://github.com/llvm/llvm-project.git). Checkout the `release/12.x` branch, since that's what our patch was based on. On Windows, in addition to applying `plugin-support.patch` mentioned in the previous section, you @@ -158,13 +158,13 @@ should also apply so you can run the lit test with the custom clang-tidy executable and let clang-tidy apply suggestions automatically. -After the patch is applied, you can then build the llvm code. Unfortunately, it -seems that clang itself cannot correctly compile the llvm code on Windows (gives +After the patch is applied, you can then build the LLVM code. Unfortunately, it +seems that clang itself cannot correctly compile the LLVM code on Windows (gives some sort of relocation error). Luckily, MinGW-w64 can be used instead to compile the code. The first step to build the code is to run CMake to generate the makefile. On -the root dir of llvm, run the following script (substitute values inside `<>` +the root dir of LLVM, run the following script (substitute values inside `<>` with the actual paths). Make sure CMake, python, and MinGW-w64 are on the path. ```sh @@ -183,7 +183,7 @@ cmake \ The next step is to call `make` to actually build clang-tidy as a library. When using MinGW-w64 to build, you should call `mingw32-make` instead. Also, because `FileCheck` is not shipped with Windows, you'll also need to build -it yourself using llvm sources by adding the `FileCheck` target to the make command. +it yourself using LLVM sources by adding the `FileCheck` target to the make command. ```sh mkdir -p build @@ -196,14 +196,14 @@ are needed to build our custom clang-tidy executable later. ##### Build clang-tidy with custom checks -After building clang-tidy as a library from the llvm source, the next step is to +After building clang-tidy as a library from the LLVM source, the next step is to build clang-tidy as an executable, with the custom checks from the CDDA source. In this step, the following tools are required. - Python 3 - CMake - MinGW-w64 -- FileCheck (built from the llvm source) +- FileCheck (built from the LLVM source) - A shell environment You also need to install yaml for python 3 to work. Download the `.whl` installer