r361790 - [test] Fix plugin tests
Don Hinton via cfe-commits
cfe-commits at lists.llvm.org
Mon May 27 23:26:58 PDT 2019
Author: dhinton
Date: Mon May 27 23:26:58 2019
New Revision: 361790
URL: http://llvm.org/viewvc/llvm-project?rev=361790&view=rev
Log:
[test] Fix plugin tests
Summary:
The following changes were required to fix these tests:
1) Change LLVM_ENABLE_PLUGINS to an option and move it to
llvm/CMakeLists.txt with an appropriate default -- which matches
the original default behavior.
2) Move the plugins directory from clang/test/Analysis
clang/lib/Analysis. It's not enough to add an exclude to the
lit.local.cfg file because add_lit_testsuites recurses the tree and
automatically adds the appropriate `check-` targets, which don't
make sense for the plugins because they aren't tests and don't
have `RUN` statements.
Here's a list of the `clang-check-anlysis*` targets with this
change:
```
$ ninja -t targets all| sed -n "s/.*\/\(check[^:]*\):.*/\1/p" | sort -u | grep clang-analysis
check-clang-analysis
check-clang-analysis-checkers
check-clang-analysis-copypaste
check-clang-analysis-diagnostics
check-clang-analysis-engine
check-clang-analysis-exploration_order
check-clang-analysis-html_diagnostics
check-clang-analysis-html_diagnostics-relevant_lines
check-clang-analysis-inlining
check-clang-analysis-objc
check-clang-analysis-unified-sources
check-clang-analysis-z3
```
3) Simplify the logic and only include the subdirectories under
clang/lib/Analysis/plugins if LLVM_ENABLE_PLUGINS is set.
Reviewed By: NoQ
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D62445
Added:
cfe/trunk/lib/Analysis/plugins/
cfe/trunk/lib/Analysis/plugins/CMakeLists.txt
cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/
cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt
cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/
cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt
cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp
cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports
cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/
cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
Removed:
cfe/trunk/test/Analysis/plugins/
Modified:
cfe/trunk/lib/Analysis/CMakeLists.txt
cfe/trunk/test/Analysis/lit.local.cfg
cfe/trunk/test/CMakeLists.txt
Modified: cfe/trunk/lib/Analysis/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CMakeLists.txt?rev=361790&r1=361789&r2=361790&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CMakeLists.txt (original)
+++ cfe/trunk/lib/Analysis/CMakeLists.txt Mon May 27 23:26:58 2019
@@ -34,3 +34,5 @@ add_clang_library(clangAnalysis
clangBasic
clangLex
)
+
+add_subdirectory(plugins)
Added: cfe/trunk/lib/Analysis/plugins/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/plugins/CMakeLists.txt?rev=361790&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/plugins/CMakeLists.txt (added)
+++ cfe/trunk/lib/Analysis/plugins/CMakeLists.txt Mon May 27 23:26:58 2019
@@ -0,0 +1,5 @@
+if(LLVM_ENABLE_PLUGINS)
+ add_subdirectory(SampleAnalyzer)
+ add_subdirectory(CheckerDependencyHandling)
+ add_subdirectory(CheckerOptionHandling)
+endif()
Added: cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt?rev=361790&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt (added)
+++ cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt Mon May 27 23:26:58 2019
@@ -0,0 +1,10 @@
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/CheckerDependencyHandlingAnalyzerPlugin.exports)
+add_llvm_library(CheckerDependencyHandlingAnalyzerPlugin MODULE CheckerDependencyHandling.cpp PLUGIN_TOOL clang)
+
+target_link_libraries(CheckerDependencyHandlingAnalyzerPlugin PRIVATE
+ clangAnalysis
+ clangAST
+ clangStaticAnalyzerCore
+ clangStaticAnalyzerFrontend
+ LLVMSupport
+ )
Added: cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp?rev=361790&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp (added)
+++ cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp Mon May 27 23:26:58 2019
@@ -0,0 +1,28 @@
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+struct Dependency : public Checker<check::BeginFunction> {
+ void checkBeginFunction(CheckerContext &Ctx) const {}
+};
+struct DependendentChecker : public Checker<check::BeginFunction> {
+ void checkBeginFunction(CheckerContext &Ctx) const {}
+};
+} // end anonymous namespace
+
+// Register plugin!
+extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
+ registry.addChecker<Dependency>("example.Dependency", "", "");
+ registry.addChecker<DependendentChecker>("example.DependendentChecker", "",
+ "");
+
+ registry.addDependency("example.DependendentChecker", "example.Dependency");
+}
+
+extern "C" const char clang_analyzerAPIVersionString[] =
+ CLANG_ANALYZER_API_VERSION_STRING;
Added: cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports?rev=361790&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports (added)
+++ cfe/trunk/lib/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports Mon May 27 23:26:58 2019
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Added: cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt?rev=361790&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt (added)
+++ cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt Mon May 27 23:26:58 2019
@@ -0,0 +1,10 @@
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/CheckerOptionHandlingAnalyzerPlugin.exports)
+add_llvm_library(CheckerOptionHandlingAnalyzerPlugin MODULE CheckerOptionHandling.cpp PLUGIN_TOOL clang)
+
+target_link_libraries(CheckerOptionHandlingAnalyzerPlugin PRIVATE
+ clangAnalysis
+ clangAST
+ clangStaticAnalyzerCore
+ clangStaticAnalyzerFrontend
+ LLVMSupport
+ )
Added: cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp?rev=361790&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp (added)
+++ cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp Mon May 27 23:26:58 2019
@@ -0,0 +1,44 @@
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+struct MyChecker : public Checker<check::BeginFunction> {
+ void checkBeginFunction(CheckerContext &Ctx) const {}
+};
+
+void registerMyChecker(CheckerManager &Mgr) {
+ MyChecker *Checker = Mgr.registerChecker<MyChecker>();
+ llvm::outs() << "Example option is set to "
+ << (Mgr.getAnalyzerOptions().getCheckerBooleanOption(
+ Checker, "ExampleOption")
+ ? "true"
+ : "false")
+ << '\n';
+}
+
+bool shouldRegisterMyChecker(const LangOptions &LO) { return true; }
+
+} // end anonymous namespace
+
+// Register plugin!
+extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
+ registry.addChecker(registerMyChecker, shouldRegisterMyChecker,
+ "example.MyChecker", "Example Description",
+ "example.mychecker.documentation.nonexistent.html",
+ /*isHidden*/false);
+
+ registry.addCheckerOption(/*OptionType*/ "bool",
+ /*CheckerFullName*/ "example.MyChecker",
+ /*OptionName*/ "ExampleOption",
+ /*DefaultValStr*/ "false",
+ /*Description*/ "This is an example checker opt.",
+ /*DevelopmentStage*/ "released");
+}
+
+extern "C" const char clang_analyzerAPIVersionString[] =
+ CLANG_ANALYZER_API_VERSION_STRING;
Added: cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports?rev=361790&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports (added)
+++ cfe/trunk/lib/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports Mon May 27 23:26:58 2019
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Added: cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt?rev=361790&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt (added)
+++ cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt Mon May 27 23:26:58 2019
@@ -0,0 +1,10 @@
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/SampleAnalyzerPlugin.exports)
+add_llvm_library(SampleAnalyzerPlugin MODULE MainCallChecker.cpp PLUGIN_TOOL clang)
+
+target_link_libraries(SampleAnalyzerPlugin PRIVATE
+ clangAnalysis
+ clangAST
+ clangStaticAnalyzerCore
+ clangStaticAnalyzerFrontend
+ LLVMSupport
+ )
Added: cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp?rev=361790&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp (added)
+++ cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp Mon May 27 23:26:58 2019
@@ -0,0 +1,54 @@
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class MainCallChecker : public Checker<check::PreStmt<CallExpr>> {
+ mutable std::unique_ptr<BugType> BT;
+
+public:
+ void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
+};
+} // end anonymous namespace
+
+void MainCallChecker::checkPreStmt(const CallExpr *CE,
+ CheckerContext &C) const {
+ const Expr *Callee = CE->getCallee();
+ const FunctionDecl *FD = C.getSVal(Callee).getAsFunctionDecl();
+
+ if (!FD)
+ return;
+
+ // Get the name of the callee.
+ IdentifierInfo *II = FD->getIdentifier();
+ if (!II) // if no identifier, not a simple C function
+ return;
+
+ if (II->isStr("main")) {
+ ExplodedNode *N = C.generateErrorNode();
+ if (!N)
+ return;
+
+ if (!BT)
+ BT.reset(new BugType(this, "call to main", "example analyzer plugin"));
+
+ std::unique_ptr<BugReport> report =
+ llvm::make_unique<BugReport>(*BT, BT->getName(), N);
+ report->addRange(Callee->getSourceRange());
+ C.emitReport(std::move(report));
+ }
+}
+
+// Register plugin!
+extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
+ registry.addChecker<MainCallChecker>(
+ "example.MainCallChecker", "Disallows calls to functions called main",
+ "");
+}
+
+extern "C" const char clang_analyzerAPIVersionString[] =
+ CLANG_ANALYZER_API_VERSION_STRING;
Added: cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports?rev=361790&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports (added)
+++ cfe/trunk/lib/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports Mon May 27 23:26:58 2019
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Modified: cfe/trunk/test/Analysis/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/lit.local.cfg?rev=361790&r1=361789&r2=361790&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/lit.local.cfg (original)
+++ cfe/trunk/test/Analysis/lit.local.cfg Mon May 27 23:26:58 2019
@@ -18,7 +18,5 @@ config.substitutions.append(('%diff_plis
config.substitutions.append(('%diff_sarif',
'''diff -U1 -w -I ".*file:.*%basename_t" -I '"version":' -I "2\.0\.0\-csd\.[0-9]*\.beta\."'''))
-config.excludes.add('plugins')
-
if not config.root.clang_staticanalyzer:
config.unsupported = True
Modified: cfe/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=361790&r1=361789&r2=361790&view=diff
==============================================================================
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Mon May 27 23:26:58 2019
@@ -126,27 +126,13 @@ if( NOT CLANG_BUILT_STANDALONE )
endif()
if (CLANG_ENABLE_STATIC_ANALYZER)
- add_subdirectory(Analysis/plugins)
- list(APPEND CLANG_TEST_DEPS clang-analyzer-plugin)
-
- # check-all would launch those tests via check-clang.
- set(EXCLUDE_FROM_ALL ON)
-
- add_lit_testsuite(check-clang-analyzer "Running the Clang analyzer tests"
- ${CMAKE_CURRENT_BINARY_DIR}/Analysis
- PARAMS ${ANALYZER_TEST_PARAMS}
- DEPENDS ${CLANG_TEST_DEPS})
- set_target_properties(check-clang-analyzer PROPERTIES FOLDER "Clang tests")
-
- if (LLVM_WITH_Z3)
- add_lit_testsuite(check-clang-analyzer-z3 "Running the Clang analyzer tests, using Z3 as a solver"
- ${CMAKE_CURRENT_BINARY_DIR}/Analysis
- PARAMS ${ANALYZER_TEST_PARAMS_Z3}
- DEPENDS ${CLANG_TEST_DEPS})
- set_target_properties(check-clang-analyzer-z3 PROPERTIES FOLDER "Clang tests")
+ if (LLVM_ENABLE_PLUGINS)
+ set(CLANG_ANALYZER_PLUGIN_DEPS
+ SampleAnalyzerPlugin
+ CheckerDependencyHandlingAnalyzerPlugin
+ CheckerOptionHandlingAnalyzerPlugin
+ )
endif()
-
- set(EXCLUDE_FROM_ALL OFF)
endif()
add_custom_target(clang-test-depends DEPENDS ${CLANG_TEST_DEPS})
More information about the cfe-commits
mailing list