summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2018-10-01 20:24:22 +0000
committerStephen Kelly <steveire@gmail.com>2018-10-01 20:24:22 +0000
commitfd693e6beb62fa7c398b0fcfdacf227293a733da (patch)
tree51a4bd06fc5c24f2d00845d7c6e6a38fb8d87793
parentd2fe65dcc3e7dd3a56038d9706f03c2a7489fd6c (diff)
[clang-tidy] Build it even without static analyzer
Conditionally compile the parts of clang-tidy which depend on the static analyzer. Funnily enough, I made the patch to exclude this from the build in 2013, and it was committed with the comment that the tool should not be fully excluded, but only the parts of it which depend on the analyzer should be excluded. http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20130617/081797.html This commit implements that idea. Reviewed By: aaron.ballman Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D52334
-rw-r--r--clang-tools-extra/CMakeLists.txt2
-rw-r--r--clang-tools-extra/clang-tidy/CMakeLists.txt13
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidy.cpp11
-rw-r--r--clang-tools-extra/clang-tidy/plugin/CMakeLists.txt7
-rw-r--r--clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/tool/CMakeLists.txt7
-rw-r--r--clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp3
-rw-r--r--clang-tools-extra/docs/clang-tidy/index.rst4
-rw-r--r--clang-tools-extra/test/CMakeLists.txt16
-rw-r--r--clang-tools-extra/test/clang-tidy/enable-alpha-checks.cpp2
-rw-r--r--clang-tools-extra/test/clang-tidy/mpi-buffer-deref.cpp1
-rw-r--r--clang-tools-extra/test/clang-tidy/mpi-type-mismatch.cpp1
-rw-r--r--clang-tools-extra/test/clang-tidy/nolint.cpp1
-rw-r--r--clang-tools-extra/test/clang-tidy/read_file_config.cpp1
-rw-r--r--clang-tools-extra/test/clang-tidy/static-analyzer-config.cpp1
-rw-r--r--clang-tools-extra/test/clang-tidy/static-analyzer.cpp1
-rw-r--r--clang-tools-extra/test/clang-tidy/temporaries.cpp1
-rw-r--r--clang-tools-extra/test/lit.cfg34
-rw-r--r--clang-tools-extra/unittests/CMakeLists.txt4
19 files changed, 75 insertions, 38 deletions
diff --git a/clang-tools-extra/CMakeLists.txt b/clang-tools-extra/CMakeLists.txt
index c434682cf67..c3137adef9f 100644
--- a/clang-tools-extra/CMakeLists.txt
+++ b/clang-tools-extra/CMakeLists.txt
@@ -1,10 +1,8 @@
add_subdirectory(clang-apply-replacements)
add_subdirectory(clang-reorder-fields)
add_subdirectory(modularize)
-if(CLANG_ENABLE_STATIC_ANALYZER)
add_subdirectory(clang-tidy)
add_subdirectory(clang-tidy-vs)
-endif()
add_subdirectory(change-namespace)
add_subdirectory(clang-doc)
diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt b/clang-tools-extra/clang-tidy/CMakeLists.txt
index a872469429c..0037268a15b 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -21,12 +21,17 @@ add_clang_library(clangTidy
clangLex
clangRewrite
clangSema
- clangStaticAnalyzerCore
- clangStaticAnalyzerFrontend
clangTooling
clangToolingCore
)
+if(CLANG_ENABLE_STATIC_ANALYZER)
+ target_link_libraries(clangTidy PRIVATE
+ clangStaticAnalyzerCore
+ clangStaticAnalyzerFrontend
+ )
+endif()
+
add_subdirectory(android)
add_subdirectory(abseil)
add_subdirectory(boost)
@@ -39,7 +44,9 @@ add_subdirectory(hicpp)
add_subdirectory(llvm)
add_subdirectory(misc)
add_subdirectory(modernize)
-add_subdirectory(mpi)
+if(CLANG_ENABLE_STATIC_ANALYZER)
+ add_subdirectory(mpi)
+endif()
add_subdirectory(objc)
add_subdirectory(performance)
add_subdirectory(plugin)
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index d9eb1a51165..729371fb861 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -23,6 +23,7 @@
#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"
@@ -34,8 +35,10 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Rewrite/Frontend/FixItRewriter.h"
#include "clang/Rewrite/Frontend/FrontendActions.h"
+#if CLANG_ENABLE_STATIC_ANALYZER
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
+#endif // CLANG_ENABLE_STATIC_ANALYZER
#include "clang/Tooling/DiagnosticsYaml.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/ReplacementsYaml.h"
@@ -56,6 +59,7 @@ namespace clang {
namespace tidy {
namespace {
+#if CLANG_ENABLE_STATIC_ANALYZER
static const char *AnalyzerCheckNamePrefix = "clang-analyzer-";
class AnalyzerDiagnosticConsumer : public ento::PathDiagnosticConsumer {
@@ -87,6 +91,7 @@ public:
private:
ClangTidyContext &Context;
};
+#endif // CLANG_ENABLE_STATIC_ANALYZER
class ErrorReporter {
public:
@@ -296,6 +301,7 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
}
}
+#if CLANG_ENABLE_STATIC_ANALYZER
static void setStaticAnalyzerCheckerOpts(const ClangTidyOptions &Opts,
AnalyzerOptionsRef AnalyzerOptions) {
StringRef AnalyzerPrefix(AnalyzerCheckNamePrefix);
@@ -339,6 +345,7 @@ static CheckersList getCheckersControlList(ClangTidyContext &Context,
}
return List;
}
+#endif // CLANG_ENABLE_STATIC_ANALYZER
std::unique_ptr<clang::ASTConsumer>
ClangTidyASTConsumerFactory::CreateASTConsumer(
@@ -380,6 +387,7 @@ ClangTidyASTConsumerFactory::CreateASTConsumer(
if (!Checks.empty())
Consumers.push_back(Finder->newASTConsumer());
+#if CLANG_ENABLE_STATIC_ANALYZER
AnalyzerOptionsRef AnalyzerOptions = Compiler.getAnalyzerOpts();
AnalyzerOptions->CheckersControlList =
getCheckersControlList(Context, Context.canEnableAnalyzerAlphaCheckers());
@@ -395,6 +403,7 @@ ClangTidyASTConsumerFactory::CreateASTConsumer(
new AnalyzerDiagnosticConsumer(Context));
Consumers.push_back(std::move(AnalysisConsumer));
}
+#endif // CLANG_ENABLE_STATIC_ANALYZER
return llvm::make_unique<ClangTidyASTConsumer>(
std::move(Consumers), std::move(Profiling), std::move(Finder),
std::move(Checks));
@@ -407,9 +416,11 @@ std::vector<std::string> ClangTidyASTConsumerFactory::getCheckNames() {
CheckNames.push_back(CheckFactory.first);
}
+#if CLANG_ENABLE_STATIC_ANALYZER
for (const auto &AnalyzerCheck : getCheckersControlList(
Context, Context.canEnableAnalyzerAlphaCheckers()))
CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
+#endif // CLANG_ENABLE_STATIC_ANALYZER
std::sort(CheckNames.begin(), CheckNames.end());
return CheckNames;
diff --git a/clang-tools-extra/clang-tidy/plugin/CMakeLists.txt b/clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
index 3540b2be712..7a12d7fd599 100644
--- a/clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
@@ -20,7 +20,6 @@ add_clang_library(clangTidyPlugin
clangTidyLLVMModule
clangTidyMiscModule
clangTidyModernizeModule
- clangTidyMPIModule
clangTidyObjCModule
clangTidyPerformanceModule
clangTidyPortabilityModule
@@ -28,3 +27,9 @@ add_clang_library(clangTidyPlugin
clangTidyZirconModule
clangTooling
)
+
+if(CLANG_ENABLE_STATIC_ANALYZER)
+ target_link_libraries(clangTidyPlugin PRIVATE
+ clangTidyMPIModule
+ )
+endif()
diff --git a/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp b/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
index 34556120553..22448939e83 100644
--- a/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
+++ b/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
@@ -9,6 +9,7 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
+#include "clang/Config/config.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/Frontend/MultiplexConsumer.h"
@@ -133,10 +134,12 @@ extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
ModernizeModuleAnchorSource;
+#if CLANG_ENABLE_STATIC_ANALYZER
// This anchor is used to force the linker to link the MPIModule.
extern volatile int MPIModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
MPIModuleAnchorSource;
+#endif
// This anchor is used to force the linker to link the ObjCModule.
extern volatile int ObjCModuleAnchorSource;
diff --git a/clang-tools-extra/clang-tidy/tool/CMakeLists.txt b/clang-tools-extra/clang-tidy/tool/CMakeLists.txt
index a3ec4ae755c..f58cfea5518 100644
--- a/clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -29,7 +29,6 @@ target_link_libraries(clang-tidy
clangTidyLLVMModule
clangTidyMiscModule
clangTidyModernizeModule
- clangTidyMPIModule
clangTidyObjCModule
clangTidyPerformanceModule
clangTidyPortabilityModule
@@ -39,6 +38,12 @@ target_link_libraries(clang-tidy
clangToolingCore
)
+if(CLANG_ENABLE_STATIC_ANALYZER)
+ target_link_libraries(clang-tidy PRIVATE
+ clangTidyMPIModule
+ )
+endif()
+
install(PROGRAMS clang-tidy-diff.py
DESTINATION share/clang
COMPONENT clang-tidy)
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index b458b293157..d272a482ad7 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -16,6 +16,7 @@
//===----------------------------------------------------------------------===//
#include "../ClangTidy.h"
+#include "clang/Config/config.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/TargetSelect.h"
@@ -534,10 +535,12 @@ extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
ModernizeModuleAnchorSource;
+#if CLANG_ENABLE_STATIC_ANALYZER
// This anchor is used to force the linker to link the MPIModule.
extern volatile int MPIModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
MPIModuleAnchorSource;
+#endif
// This anchor is used to force the linker to link the PerformanceModule.
extern volatile int PerformanceModuleAnchorSource;
diff --git a/clang-tools-extra/docs/clang-tidy/index.rst b/clang-tools-extra/docs/clang-tidy/index.rst
index 3b7443c2da1..ab165d8c5a7 100644
--- a/clang-tools-extra/docs/clang-tidy/index.rst
+++ b/clang-tools-extra/docs/clang-tidy/index.rst
@@ -337,6 +337,10 @@ There are a few tools particularly useful when developing clang-tidy checks:
* `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``,
+:program:`clang-tidy` will not be built with support for the
+``clang-analyzer-*`` checks or the ``mpi-*`` checks.
+
.. _AST Matchers: http://clang.llvm.org/docs/LibASTMatchers.html
.. _PPCallbacks: http://clang.llvm.org/doxygen/classclang_1_1PPCallbacks.html
diff --git a/clang-tools-extra/test/CMakeLists.txt b/clang-tools-extra/test/CMakeLists.txt
index a1bda509089..e2d7e12ef19 100644
--- a/clang-tools-extra/test/CMakeLists.txt
+++ b/clang-tools-extra/test/CMakeLists.txt
@@ -56,18 +56,14 @@ set(CLANG_TOOLS_TEST_DEPS
# Unit tests
ExtraToolsUnitTests
- )
-if(CLANG_ENABLE_STATIC_ANALYZER)
- list(APPEND CLANG_TOOLS_TEST_DEPS
- # For the clang-tidy libclang integration test.
- c-index-test
- # clang-tidy tests require it.
- clang-headers
+ # For the clang-tidy libclang integration test.
+ c-index-test
+ # clang-tidy tests require it.
+ clang-headers
- clang-tidy
- )
-endif()
+ clang-tidy
+ )
add_lit_testsuite(check-clang-tools "Running the Clang extra tools' regression tests"
${CMAKE_CURRENT_BINARY_DIR}
diff --git a/clang-tools-extra/test/clang-tidy/enable-alpha-checks.cpp b/clang-tools-extra/test/clang-tidy/enable-alpha-checks.cpp
index b1e51303498..74bdfdb5dd0 100644
--- a/clang-tools-extra/test/clang-tidy/enable-alpha-checks.cpp
+++ b/clang-tools-extra/test/clang-tidy/enable-alpha-checks.cpp
@@ -1,3 +1,5 @@
+// REQUIRES: static-analyzer
+
// Check if '-allow-enabling-analyzer-alpha-checkers' is visible for users.
// RUN: clang-tidy -help | not grep 'allow-enabling-analyzer-alpha-checkers'
diff --git a/clang-tools-extra/test/clang-tidy/mpi-buffer-deref.cpp b/clang-tools-extra/test/clang-tidy/mpi-buffer-deref.cpp
index 67304d23010..47d58a5a6c4 100644
--- a/clang-tools-extra/test/clang-tidy/mpi-buffer-deref.cpp
+++ b/clang-tools-extra/test/clang-tidy/mpi-buffer-deref.cpp
@@ -1,3 +1,4 @@
+// REQUIRES: static-analyzer
// RUN: %check_clang_tidy %s mpi-buffer-deref %t -- -- -I %S/Inputs/mpi-type-mismatch
#include "mpimock.h"
diff --git a/clang-tools-extra/test/clang-tidy/mpi-type-mismatch.cpp b/clang-tools-extra/test/clang-tidy/mpi-type-mismatch.cpp
index 5e230b89ba1..bf978dcc188 100644
--- a/clang-tools-extra/test/clang-tidy/mpi-type-mismatch.cpp
+++ b/clang-tools-extra/test/clang-tidy/mpi-type-mismatch.cpp
@@ -1,3 +1,4 @@
+// REQUIRES: static-analyzer
// RUN: %check_clang_tidy %s mpi-type-mismatch %t -- -- -I %S/Inputs/mpi-type-mismatch
#include "mpimock.h"
diff --git a/clang-tools-extra/test/clang-tidy/nolint.cpp b/clang-tools-extra/test/clang-tidy/nolint.cpp
index 893e81929c8..24c37228d3c 100644
--- a/clang-tools-extra/test/clang-tidy/nolint.cpp
+++ b/clang-tools-extra/test/clang-tidy/nolint.cpp
@@ -1,3 +1,4 @@
+// REQUIRES: static-analyzer
// RUN: %check_clang_tidy %s google-explicit-constructor,clang-diagnostic-unused-variable,clang-analyzer-core.UndefinedBinaryOperatorResult %t -- -extra-arg=-Wunused-variable -- -I%S/Inputs/nolint
#include "trigger_warning.h"
diff --git a/clang-tools-extra/test/clang-tidy/read_file_config.cpp b/clang-tools-extra/test/clang-tidy/read_file_config.cpp
index 3635c214fcd..3e39b4d630e 100644
--- a/clang-tools-extra/test/clang-tidy/read_file_config.cpp
+++ b/clang-tools-extra/test/clang-tidy/read_file_config.cpp
@@ -1,3 +1,4 @@
+// REQUIRES: static-analyzer
// RUN: mkdir -p %T/read-file-config/
// RUN: cp %s %T/read-file-config/test.cpp
// RUN: echo 'Checks: "-*,modernize-use-nullptr"' > %T/read-file-config/.clang-tidy
diff --git a/clang-tools-extra/test/clang-tidy/static-analyzer-config.cpp b/clang-tools-extra/test/clang-tidy/static-analyzer-config.cpp
index cee0a4c413c..9ca87cf8dce 100644
--- a/clang-tools-extra/test/clang-tidy/static-analyzer-config.cpp
+++ b/clang-tools-extra/test/clang-tidy/static-analyzer-config.cpp
@@ -1,3 +1,4 @@
+// REQUIRES: static-analyzer
// RUN: clang-tidy %s -checks='-*,clang-analyzer-unix.Malloc' -config='{CheckOptions: [{ key: "clang-analyzer-unix.Malloc:Optimistic", value: true}]}' -- | FileCheck %s
typedef __typeof(sizeof(int)) size_t;
void *malloc(size_t);
diff --git a/clang-tools-extra/test/clang-tidy/static-analyzer.cpp b/clang-tools-extra/test/clang-tidy/static-analyzer.cpp
index b0015aa47cc..af9693ad099 100644
--- a/clang-tools-extra/test/clang-tidy/static-analyzer.cpp
+++ b/clang-tools-extra/test/clang-tidy/static-analyzer.cpp
@@ -1,3 +1,4 @@
+// REQUIRES: static-analyzer
// RUN: clang-tidy %s -checks='-*,clang-analyzer-*' -- | FileCheck %s
extern void *malloc(unsigned long);
extern void free(void *);
diff --git a/clang-tools-extra/test/clang-tidy/temporaries.cpp b/clang-tools-extra/test/clang-tidy/temporaries.cpp
index 3df4c60d463..0aa60ed3f62 100644
--- a/clang-tools-extra/test/clang-tidy/temporaries.cpp
+++ b/clang-tools-extra/test/clang-tidy/temporaries.cpp
@@ -1,3 +1,4 @@
+// REQUIRES: static-analyzer
// RUN: clang-tidy -checks='-*,clang-analyzer-core.NullDereference' %s -- | FileCheck %s
struct NoReturnDtor {
diff --git a/clang-tools-extra/test/lit.cfg b/clang-tools-extra/test/lit.cfg
index 8e755c879fe..8f8ebaf9898 100644
--- a/clang-tools-extra/test/lit.cfg
+++ b/clang-tools-extra/test/lit.cfg
@@ -119,24 +119,22 @@ if platform.system() not in ['Windows']:
if config.clang_staticanalyzer:
config.available_features.add('static-analyzer')
- check_clang_tidy = os.path.join(
- config.test_source_root, "clang-tidy", "check_clang_tidy.py")
- config.substitutions.append(
- ('%check_clang_tidy',
- '%s %s' % (config.python_executable, check_clang_tidy)) )
- clang_tidy_diff = os.path.join(
- config.test_source_root, "..", "clang-tidy", "tool", "clang-tidy-diff.py")
- config.substitutions.append(
- ('%clang_tidy_diff',
- '%s %s' % (config.python_executable, clang_tidy_diff)) )
- run_clang_tidy = os.path.join(
- config.test_source_root, "..", "clang-tidy", "tool", "run-clang-tidy.py")
- config.substitutions.append(
- ('%run_clang_tidy',
- '%s %s' % (config.python_executable, run_clang_tidy)) )
-else:
- # exclude the clang-tidy test directory
- config.excludes.append('clang-tidy')
+
+check_clang_tidy = os.path.join(
+ config.test_source_root, "clang-tidy", "check_clang_tidy.py")
+config.substitutions.append(
+ ('%check_clang_tidy',
+ '%s %s' % (config.python_executable, check_clang_tidy)) )
+clang_tidy_diff = os.path.join(
+ config.test_source_root, "..", "clang-tidy", "tool", "clang-tidy-diff.py")
+config.substitutions.append(
+ ('%clang_tidy_diff',
+ '%s %s' % (config.python_executable, clang_tidy_diff)) )
+run_clang_tidy = os.path.join(
+ config.test_source_root, "..", "clang-tidy", "tool", "run-clang-tidy.py")
+config.substitutions.append(
+ ('%run_clang_tidy',
+ '%s %s' % (config.python_executable, run_clang_tidy)) )
clangd_benchmarks_dir = os.path.join(os.path.dirname(config.clang_tools_dir),
"tools", "clang", "tools", "extra",
diff --git a/clang-tools-extra/unittests/CMakeLists.txt b/clang-tools-extra/unittests/CMakeLists.txt
index 82f54d5cdf4..d123700bab2 100644
--- a/clang-tools-extra/unittests/CMakeLists.txt
+++ b/clang-tools-extra/unittests/CMakeLists.txt
@@ -18,8 +18,6 @@ add_subdirectory(change-namespace)
add_subdirectory(clang-apply-replacements)
add_subdirectory(clang-move)
add_subdirectory(clang-query)
-if(CLANG_ENABLE_STATIC_ANALYZER)
- add_subdirectory(clang-tidy)
-endif()
+add_subdirectory(clang-tidy)
add_subdirectory(clangd)
add_subdirectory(include-fixer)