Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, rnkovacs, baloghadamsoftware.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, Charusso, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, szepet, whisperity, mgorny.

Repository:
  rC Clang

https://reviews.llvm.org/D59465

Files:
  examples/StaticAnalyzer/CMakeLists.txt
  examples/StaticAnalyzer/OptionHandlingPlugin/CMakeLists.txt
  examples/StaticAnalyzer/OptionHandlingPlugin/CheckerOptionHandling.cpp
  
examples/StaticAnalyzer/OptionHandlingPlugin/OptionHandlingAnalyzerPlugin.exports
  test/Analysis/checker-plugins.c

Index: test/Analysis/checker-plugins.c
===================================================================
--- test/Analysis/checker-plugins.c
+++ test/Analysis/checker-plugins.c
@@ -30,3 +30,18 @@
 
 // CHECK-IMPLICITLY-DISABLED-NOT: example.Dependency
 // CHECK-IMPLICITLY-DISABLED-NOT: example.DependendentChecker
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -load %llvmshlibdir/OptionHandlingAnalyzerPlugin%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/OptionHandlingAnalyzerPlugin%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
Index: examples/StaticAnalyzer/OptionHandlingPlugin/OptionHandlingAnalyzerPlugin.exports
===================================================================
--- /dev/null
+++ examples/StaticAnalyzer/OptionHandlingPlugin/OptionHandlingAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Index: examples/StaticAnalyzer/OptionHandlingPlugin/CheckerOptionHandling.cpp
===================================================================
--- /dev/null
+++ examples/StaticAnalyzer/OptionHandlingPlugin/CheckerOptionHandling.cpp
@@ -0,0 +1,42 @@
+#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 &registry) {
+  registry.addChecker(registerMyChecker, shouldRegisterMyChecker,
+                      "example.MyChecker", "Example Description",
+                      "example.mychecker.documentation.nonexistent.html");
+
+  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;
Index: examples/StaticAnalyzer/OptionHandlingPlugin/CMakeLists.txt
===================================================================
--- /dev/null
+++ examples/StaticAnalyzer/OptionHandlingPlugin/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/OptionHandlingAnalyzerPlugin.exports)
+add_llvm_library(OptionHandlingAnalyzerPlugin MODULE CheckerOptionHandling.cpp PLUGIN_TOOL clang)
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+  target_link_libraries(OptionHandlingAnalyzerPlugin PRIVATE
+    clangAnalysis
+    clangAST
+    clangStaticAnalyzerCore
+    LLVMSupport
+    )
+endif()
Index: examples/StaticAnalyzer/CMakeLists.txt
===================================================================
--- examples/StaticAnalyzer/CMakeLists.txt
+++ examples/StaticAnalyzer/CMakeLists.txt
@@ -1,2 +1,3 @@
 add_subdirectory(SampleAnalyzerPlugin)
 add_subdirectory(CheckerDependencyHandlingPlugin)
+add_subdirectory(OptionHandlingPlugin)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D59465: [analyzer] ... Kristóf Umann via Phabricator via cfe-commits

Reply via email to