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.

- Move `examples/analyzer-plugin` to 
`analyzer/StaticAnalyzer/SampleAnalyzerPlugin`
- Create a new example plugin for handling checker dependencies

Since git will blame will be messed up anyways, I also clang-formatted the 
original plugin.


Repository:
  rC Clang

https://reviews.llvm.org/D59464

Files:
  examples/CMakeLists.txt
  examples/StaticAnalyzer/CMakeLists.txt
  examples/StaticAnalyzer/CheckerDependencyHandlingPlugin/CMakeLists.txt
  
examples/StaticAnalyzer/CheckerDependencyHandlingPlugin/CheckerDependencyHandling.cpp
  
examples/StaticAnalyzer/CheckerDependencyHandlingPlugin/CheckerDependencyHandlingAnalyzerPlugin.exports
  examples/StaticAnalyzer/SampleAnalyzerPlugin/CMakeLists.txt
  examples/StaticAnalyzer/SampleAnalyzerPlugin/MainCallChecker.cpp
  examples/StaticAnalyzer/SampleAnalyzerPlugin/SampleAnalyzerPlugin.exports
  examples/analyzer-plugin/CMakeLists.txt
  examples/analyzer-plugin/MainCallChecker.cpp
  examples/analyzer-plugin/SampleAnalyzerPlugin.exports
  test/Analysis/checker-plugins.c

Index: test/Analysis/checker-plugins.c
===================================================================
--- test/Analysis/checker-plugins.c
+++ test/Analysis/checker-plugins.c
@@ -1,4 +1,7 @@
-// RUN: %clang_analyze_cc1 -load %llvmshlibdir/SampleAnalyzerPlugin%pluginext -analyzer-checker='example.MainCallChecker' -verify %s
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -load %llvmshlibdir/SampleAnalyzerPlugin%pluginext \
+// RUN:   -analyzer-checker='example.MainCallChecker'
+
 // REQUIRES: plugins, examples
 
 // Test that the MainCallChecker example analyzer plugin loads and runs.
@@ -8,3 +11,22 @@
 void caller() {
   main(); // expected-warning {{call to main}}
 }
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -load %llvmshlibdir/CheckerDependencyHandlingAnalyzerPlugin%pluginext\
+// RUN:   -analyzer-checker=example.DependendentChecker \
+// RUN:   -analyzer-list-enabled-checkers \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-IMPLICITLY-ENABLED
+
+// CHECK-IMPLICITLY-ENABLED: example.Dependency
+// CHECK-IMPLICITLY-ENABLED: example.DependendentChecker
+
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -load %llvmshlibdir/CheckerDependencyHandlingAnalyzerPlugin%pluginext\
+// RUN:   -analyzer-checker=example.DependendentChecker \
+// RUN:   -analyzer-disable-checker=example.Dependency \
+// RUN:   -analyzer-list-enabled-checkers \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-IMPLICITLY-DISABLED
+
+// CHECK-IMPLICITLY-DISABLED-NOT: example.Dependency
+// CHECK-IMPLICITLY-DISABLED-NOT: example.DependendentChecker
Index: examples/StaticAnalyzer/SampleAnalyzerPlugin/SampleAnalyzerPlugin.exports
===================================================================
--- /dev/null
+++ examples/StaticAnalyzer/SampleAnalyzerPlugin/SampleAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Index: examples/StaticAnalyzer/SampleAnalyzerPlugin/MainCallChecker.cpp
===================================================================
--- examples/StaticAnalyzer/SampleAnalyzerPlugin/MainCallChecker.cpp
+++ examples/StaticAnalyzer/SampleAnalyzerPlugin/MainCallChecker.cpp
@@ -1,13 +1,13 @@
-#include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
-#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.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> > {
+class MainCallChecker : public Checker<check::PreStmt<CallExpr>> {
   mutable std::unique_ptr<BugType> BT;
 
 public:
@@ -15,7 +15,8 @@
 };
 } // end anonymous namespace
 
-void MainCallChecker::checkPreStmt(const CallExpr *CE, CheckerContext &C) const {
+void MainCallChecker::checkPreStmt(const CallExpr *CE,
+                                   CheckerContext &C) const {
   const Expr *Callee = CE->getCallee();
   const FunctionDecl *FD = C.getSVal(Callee).getAsFunctionDecl();
 
@@ -24,7 +25,7 @@
 
   // Get the name of the callee.
   IdentifierInfo *II = FD->getIdentifier();
-  if (!II)   // if no identifier, not a simple C function
+  if (!II) // if no identifier, not a simple C function
     return;
 
   if (II->isStr("main")) {
@@ -43,12 +44,11 @@
 }
 
 // Register plugin!
-extern "C"
-void clang_registerCheckers (CheckerRegistry &registry) {
+extern "C" void clang_registerCheckers(CheckerRegistry &registry) {
   registry.addChecker<MainCallChecker>(
       "example.MainCallChecker", "Disallows calls to functions called main",
       "");
 }
 
-extern "C"
-const char clang_analyzerAPIVersionString[] = CLANG_ANALYZER_API_VERSION_STRING;
+extern "C" const char clang_analyzerAPIVersionString[] =
+    CLANG_ANALYZER_API_VERSION_STRING;
Index: examples/StaticAnalyzer/CheckerDependencyHandlingPlugin/CheckerDependencyHandling.cpp
===================================================================
--- /dev/null
+++ examples/StaticAnalyzer/CheckerDependencyHandlingPlugin/CheckerDependencyHandling.cpp
@@ -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 &registry) {
+  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;
Index: examples/StaticAnalyzer/CheckerDependencyHandlingPlugin/CMakeLists.txt
===================================================================
--- /dev/null
+++ examples/StaticAnalyzer/CheckerDependencyHandlingPlugin/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/CheckerDependencyHandlingAnalyzerPlugin.exports)
+add_llvm_library(CheckerDependencyHandlingAnalyzerPlugin MODULE CheckerDependencyHandling.cpp PLUGIN_TOOL clang)
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+  target_link_libraries(CheckerDependencyHandlingAnalyzerPlugin PRIVATE
+    clangAnalysis
+    clangAST
+    clangStaticAnalyzerCore
+    LLVMSupport
+    )
+endif()
Index: examples/StaticAnalyzer/CMakeLists.txt
===================================================================
--- /dev/null
+++ examples/StaticAnalyzer/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(SampleAnalyzerPlugin)
+add_subdirectory(CheckerDependencyHandlingPlugin)
Index: examples/CMakeLists.txt
===================================================================
--- examples/CMakeLists.txt
+++ examples/CMakeLists.txt
@@ -4,7 +4,7 @@
 endif()
 
 if(CLANG_ENABLE_STATIC_ANALYZER)
-add_subdirectory(analyzer-plugin)
+  add_subdirectory(StaticAnalyzer)
 endif()
 add_subdirectory(clang-interpreter)
 add_subdirectory(PrintFunctionNames)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to