r360910 - [analyzer] Add a test plugin for checker option handling
Kristof Umann via cfe-commits
cfe-commits at lists.llvm.org
Thu May 16 08:55:07 PDT 2019
Author: szelethus
Date: Thu May 16 08:55:07 2019
New Revision: 360910
URL: http://llvm.org/viewvc/llvm-project?rev=360910&view=rev
Log:
[analyzer] Add a test plugin for checker option handling
Differential Revision: https://reviews.llvm.org/D59465
Added:
cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/
cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt
cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp
cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports
Modified:
cfe/trunk/test/Analysis/checker-plugins.c
cfe/trunk/test/Analysis/plugins/CMakeLists.txt
Modified: cfe/trunk/test/Analysis/checker-plugins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/checker-plugins.c?rev=360910&r1=360909&r2=360910&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/checker-plugins.c (original)
+++ cfe/trunk/test/Analysis/checker-plugins.c Thu May 16 08:55:07 2019
@@ -30,3 +30,18 @@ void caller() {
// CHECK-IMPLICITLY-DISABLED-NOT: example.Dependency
// CHECK-IMPLICITLY-DISABLED-NOT: example.DependendentChecker
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN: -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
+// RUN: -analyzer-checker=example.MyChecker \
+// RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-CHECKER-OPTION-OUTPUT
+
+// CHECK-CHECKER-OPTION-OUTPUT: Example option is set to false
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN: -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
+// RUN: -analyzer-checker=example.MyChecker \
+// RUN: -analyzer-config example.MyChecker:ExampleOption=true \
+// RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-CHECKER-OPTION-OUTPUT-TRUE
+
+// CHECK-CHECKER-OPTION-OUTPUT-TRUE: Example option is set to true
Modified: cfe/trunk/test/Analysis/plugins/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/CMakeLists.txt?rev=360910&r1=360909&r2=360910&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CMakeLists.txt (original)
+++ cfe/trunk/test/Analysis/plugins/CMakeLists.txt Thu May 16 08:55:07 2019
@@ -1,9 +1,11 @@
add_subdirectory(SampleAnalyzer)
add_subdirectory(CheckerDependencyHandling)
+add_subdirectory(CheckerOptionHandling)
set(CLANG_ANALYZER_PLUGIN_DEPS
SampleAnalyzerPlugin
CheckerDependencyHandlingAnalyzerPlugin
+ CheckerOptionHandlingAnalyzerPlugin
)
add_custom_target(clang-analyzer-plugin
Added: cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt?rev=360910&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt (added)
+++ cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt Thu May 16 08:55:07 2019
@@ -0,0 +1,11 @@
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/CheckerOptionHandlingAnalyzerPlugin.exports)
+add_llvm_library(CheckerOptionHandlingAnalyzerPlugin MODULE CheckerOptionHandling.cpp PLUGIN_TOOL clang)
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+ target_link_libraries(CheckerOptionHandlingAnalyzerPlugin PRIVATE
+ clangAnalysis
+ clangAST
+ clangStaticAnalyzerCore
+ LLVMSupport
+ )
+endif()
Added: cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp?rev=360910&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp (added)
+++ cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp Thu May 16 08:55:07 2019
@@ -0,0 +1,43 @@
+#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", false)
+ ? "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.");
+}
+
+extern "C" const char clang_analyzerAPIVersionString[] =
+ CLANG_ANALYZER_API_VERSION_STRING;
Added: cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports?rev=360910&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports (added)
+++ cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports Thu May 16 08:55:07 2019
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
More information about the cfe-commits
mailing list