Index: clang-tools-extra/CMakeLists.txt =================================================================== --- clang-tools-extra/CMakeLists.txt +++ clang-tools-extra/CMakeLists.txt @@ -1,5 +1,8 @@ include(CMakeDependentOption) +option(CLANG_TIDY_ENABLE_STATIC_ANALYZER + "Include static analyzer checks in clang-tidy" ON) + add_subdirectory(clang-apply-replacements) add_subdirectory(clang-reorder-fields) add_subdirectory(modularize) Index: clang-tools-extra/clang-tidy/CMakeLists.txt =================================================================== --- clang-tools-extra/clang-tidy/CMakeLists.txt +++ clang-tools-extra/clang-tidy/CMakeLists.txt @@ -3,6 +3,11 @@ Support ) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clang-tidy-config.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/clang-tidy-config.h) +include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) + add_clang_library(clangTidy ClangTidy.cpp ClangTidyCheck.cpp @@ -34,7 +39,7 @@ clangToolingCore ) -if(CLANG_ENABLE_STATIC_ANALYZER) +if(CLANG_TIDY_ENABLE_STATIC_ANALYZER) clang_target_link_libraries(clangTidy PRIVATE clangStaticAnalyzerCore @@ -59,7 +64,7 @@ add_subdirectory(llvmlibc) add_subdirectory(misc) add_subdirectory(modernize) -if(CLANG_ENABLE_STATIC_ANALYZER) +if(CLANG_TIDY_ENABLE_STATIC_ANALYZER) add_subdirectory(mpi) endif() add_subdirectory(objc) @@ -91,7 +96,7 @@ clangTidyReadabilityModule clangTidyZirconModule ) -if(CLANG_ENABLE_STATIC_ANALYZER) +if(CLANG_TIDY_ENABLE_STATIC_ANALYZER) list(APPEND ALL_CLANG_TIDY_CHECKS clangTidyMPIModule) endif() set(ALL_CLANG_TIDY_CHECKS ${ALL_CLANG_TIDY_CHECKS} PARENT_SCOPE) Index: clang-tools-extra/clang-tidy/ClangTidy.cpp =================================================================== --- clang-tools-extra/clang-tidy/ClangTidy.cpp +++ clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -20,11 +20,11 @@ #include "ClangTidyModuleRegistry.h" #include "ClangTidyProfiling.h" #include "ExpandModularHeadersPPCallbacks.h" +#include "clang-tidy-config.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" #include "clang/ASTMatchers/ASTMatchFinder.h" -#include "clang/Config/config.h" #include "clang/Format/Format.h" #include "clang/Frontend/ASTConsumers.h" #include "clang/Frontend/CompilerInstance.h" @@ -47,10 +47,10 @@ #include #include -#if CLANG_ENABLE_STATIC_ANALYZER +#if CLANG_TIDY_ENABLE_STATIC_ANALYZER #include "clang/Analysis/PathDiagnostic.h" #include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h" -#endif // CLANG_ENABLE_STATIC_ANALYZER +#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER using namespace clang::ast_matchers; using namespace clang::driver; @@ -63,7 +63,7 @@ namespace tidy { namespace { -#if CLANG_ENABLE_STATIC_ANALYZER +#if CLANG_TIDY_ENABLE_STATIC_ANALYZER static const char *AnalyzerCheckNamePrefix = "clang-analyzer-"; class AnalyzerDiagnosticConsumer : public ento::PathDiagnosticConsumer { @@ -95,7 +95,7 @@ private: ClangTidyContext &Context; }; -#endif // CLANG_ENABLE_STATIC_ANALYZER +#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER class ErrorReporter { public: @@ -324,7 +324,7 @@ } } -#if CLANG_ENABLE_STATIC_ANALYZER +#if CLANG_TIDY_ENABLE_STATIC_ANALYZER static void setStaticAnalyzerCheckerOpts(const ClangTidyOptions &Opts, AnalyzerOptionsRef AnalyzerOptions) { StringRef AnalyzerPrefix(AnalyzerCheckNamePrefix); @@ -369,7 +369,7 @@ } return List; } -#endif // CLANG_ENABLE_STATIC_ANALYZER +#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER std::unique_ptr ClangTidyASTConsumerFactory::CreateASTConsumer( @@ -424,7 +424,7 @@ if (!Checks.empty()) Consumers.push_back(Finder->newASTConsumer()); -#if CLANG_ENABLE_STATIC_ANALYZER +#if CLANG_TIDY_ENABLE_STATIC_ANALYZER AnalyzerOptionsRef AnalyzerOptions = Compiler.getAnalyzerOpts(); AnalyzerOptions->CheckersAndPackages = getAnalyzerCheckersAndPackages( Context, Context.canEnableAnalyzerAlphaCheckers()); @@ -440,7 +440,7 @@ new AnalyzerDiagnosticConsumer(Context)); Consumers.push_back(std::move(AnalysisConsumer)); } -#endif // CLANG_ENABLE_STATIC_ANALYZER +#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER return std::make_unique( std::move(Consumers), std::move(Profiling), std::move(Finder), std::move(Checks)); @@ -453,11 +453,11 @@ CheckNames.emplace_back(CheckFactory.getKey()); } -#if CLANG_ENABLE_STATIC_ANALYZER +#if CLANG_TIDY_ENABLE_STATIC_ANALYZER for (const auto &AnalyzerCheck : getAnalyzerCheckersAndPackages( Context, Context.canEnableAnalyzerAlphaCheckers())) CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first); -#endif // CLANG_ENABLE_STATIC_ANALYZER +#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER llvm::sort(CheckNames); return CheckNames; Index: clang-tools-extra/clang-tidy/ClangTidyForceLinker.h =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyForceLinker.h +++ clang-tools-extra/clang-tidy/ClangTidyForceLinker.h @@ -9,7 +9,7 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYFORCELINKER_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYFORCELINKER_H -#include "clang/Config/config.h" +#include "clang-tidy-config.h" #include "llvm/Support/Compiler.h" namespace clang { @@ -90,7 +90,7 @@ static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination = ModernizeModuleAnchorSource; -#if CLANG_ENABLE_STATIC_ANALYZER && \ +#if CLANG_TIDY_ENABLE_STATIC_ANALYZER && \ !defined(CLANG_TIDY_DISABLE_STATIC_ANALYZER_CHECKS) // This anchor is used to force the linker to link the MPIModule. extern volatile int MPIModuleAnchorSource; Index: clang-tools-extra/clang-tidy/clang-tidy-config.h.cmake =================================================================== --- /dev/null +++ clang-tools-extra/clang-tidy/clang-tidy-config.h.cmake @@ -0,0 +1,10 @@ +/* This generated file is for internal use. Do not include it from headers. */ + +#ifdef CLANG_TIDY_CONFIG_H +#error clang-tidy-config.h can only be included once +#else +#define CLANG_TIDY_CONFIG_H + +#cmakedefine01 CLANG_TIDY_ENABLE_STATIC_ANALYZER + +#endif Index: clang-tools-extra/docs/clang-tidy/Contributing.rst =================================================================== --- clang-tools-extra/docs/clang-tidy/Contributing.rst +++ clang-tools-extra/docs/clang-tidy/Contributing.rst @@ -27,7 +27,7 @@ * `clang-check`_ with the ``-ast-dump`` (and optionally ``-ast-dump-filter``) provides a convenient way to dump AST of a C++ program. -If CMake is configured with ``CLANG_ENABLE_STATIC_ANALYZER``, +If CMake is configured with ``CLANG_TIDY_ENABLE_STATIC_ANALYZER=NO``, :program:`clang-tidy` will not be built with support for the ``clang-analyzer-*`` checks or the ``mpi-*`` checks. Index: clang-tools-extra/test/CMakeLists.txt =================================================================== --- clang-tools-extra/test/CMakeLists.txt +++ clang-tools-extra/test/CMakeLists.txt @@ -16,7 +16,7 @@ string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) llvm_canonicalize_cmake_booleans( - CLANG_ENABLE_STATIC_ANALYZER + CLANG_TIDY_ENABLE_STATIC_ANALYZER LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA ) Index: clang-tools-extra/test/lit.cfg.py =================================================================== --- clang-tools-extra/test/lit.cfg.py +++ clang-tools-extra/test/lit.cfg.py @@ -115,7 +115,7 @@ if platform.system() not in ['Windows']: config.available_features.add('ansi-escape-sequences') -if config.clang_staticanalyzer: +if config.clang_tidy_staticanalyzer: config.available_features.add('static-analyzer') # Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if Index: clang-tools-extra/test/lit.site.cfg.py.in =================================================================== --- clang-tools-extra/test/lit.site.cfg.py.in +++ clang-tools-extra/test/lit.site.cfg.py.in @@ -10,7 +10,7 @@ config.clang_libs_dir = "@SHLIBDIR@" config.python_executable = "@Python3_EXECUTABLE@" config.target_triple = "@TARGET_TRIPLE@" -config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@ +config.clang_tidy_staticanalyzer = @CLANG_TIDY_ENABLE_STATIC_ANALYZER@ config.libclang_include_clang_tools_extra = @LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA@ # Support substitution of the tools and libs dirs with user parameters. This is Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -492,7 +492,8 @@ "Build the Clang tools. If OFF, just generate build targets." ON) option(CLANG_ENABLE_ARCMT "Build ARCMT." ON) -option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON) +option(CLANG_ENABLE_STATIC_ANALYZER + "Include static analyzer in clang binary." ON) option(CLANG_ENABLE_PROTO_FUZZER "Build Clang protobuf fuzzer." OFF) Index: clang/cmake/caches/Android.cmake =================================================================== --- clang/cmake/caches/Android.cmake +++ clang/cmake/caches/Android.cmake @@ -4,6 +4,7 @@ set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "") set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "") +set(CLANG_TIDY_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "") set(CLANG_VENDOR Android CACHE STRING "") set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "") Index: clang/lib/CMakeLists.txt =================================================================== --- clang/lib/CMakeLists.txt +++ clang/lib/CMakeLists.txt @@ -21,8 +21,6 @@ add_subdirectory(DirectoryWatcher) add_subdirectory(Index) add_subdirectory(IndexSerialization) -if(CLANG_ENABLE_STATIC_ANALYZER) - add_subdirectory(StaticAnalyzer) -endif() +add_subdirectory(StaticAnalyzer) add_subdirectory(Format) add_subdirectory(Testing) Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/BUILD.gn +++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/BUILD.gn @@ -1,9 +1,32 @@ import("//clang/lib/StaticAnalyzer/Frontend/enable.gni") +import("//llvm/utils/gn/build/write_cmake_config.gni") +import("enable.gni") + +config("clang-tidy-config_Config") { + visibility = [ ":clang-tidy-config" ] + include_dirs = [ "$target_gen_dir" ] +} + +write_cmake_config("clang-tidy-config") { + input = "clang-tidy-config.h.cmake" + output = "$target_gen_dir/clang-tidy-config.h" + values = [] + + if (clang_tidy_enable_static_analyzer) { + values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=1" ] + } else { + values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=" ] + } + + # Let targets depending on this find the generated file. + public_configs = [ ":clang-tidy-config_Config" ] +} static_library("clang-tidy") { output_name = "clangTidy" configs += [ "//llvm/utils/gn/build:clang_code" ] deps = [ + ":clang-tidy-config", "//clang/include/clang/StaticAnalyzer/Checkers", "//clang/lib/AST", "//clang/lib/ASTMatchers", @@ -19,7 +42,7 @@ "//llvm/lib/Support", ] - if (clang_enable_static_analyzer) { + if (clang_tidy_enable_static_analyzer) { deps += [ "//clang/lib/StaticAnalyzer/Core", "//clang/lib/StaticAnalyzer/Frontend", @@ -63,7 +86,7 @@ "//clang-tools-extra/clang-tidy/readability", "//clang-tools-extra/clang-tidy/zircon", ] - if (clang_enable_static_analyzer) { + if (clang_tidy_enable_static_analyzer) { deps += [ "//clang-tools-extra/clang-tidy/mpi" ] } } Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/enable.gni =================================================================== --- /dev/null +++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/enable.gni @@ -0,0 +1,4 @@ +declare_args() { + # Whether to include the static analyzer in the clang-tidy binary. + clang_tidy_enable_static_analyzer = true +} Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/tool/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/tool/BUILD.gn +++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/tool/BUILD.gn @@ -3,6 +3,7 @@ deps = [ "//clang-tools-extra/clang-tidy", "//clang-tools-extra/clang-tidy:all-checks", + "//clang-tools-extra/clang-tidy:clang-tidy-config", "//clang/lib/AST", "//clang/lib/ASTMatchers", "//clang/lib/Basic", Index: llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn +++ llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn @@ -1,3 +1,4 @@ +import("//clang-tools-extra/clang-tidy/enable.gni") import("//clang/lib/StaticAnalyzer/Frontend/enable.gni") import("//clang/tools/libclang/include_clang_tools_extra.gni") import("//llvm/triples.gni") @@ -38,10 +39,10 @@ "Python3_EXECUTABLE=$python_path", ] - if (clang_enable_static_analyzer) { - extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=1" ] + if (clang_tidy_enable_static_analyzer) { + extra_values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=1" ] } else { - extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=0" ] + extra_values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=0" ] } if (libclang_include_clang_tools_extra) {