r361793 - Revert [test] Fix plugin tests

Don Hinton via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 23:38:16 PDT 2019


Author: dhinton
Date: Mon May 27 23:38:16 2019
New Revision: 361793

URL: http://llvm.org/viewvc/llvm-project?rev=361793&view=rev
Log:
Revert [test] Fix plugin tests

This reverts r361790 (git commit fe5eaab2b5b4523886bd63aebcfea8cfce586fa1)

It's causing buildbot breakage, so reverting while I investigate.

Added:
    cfe/trunk/test/Analysis/plugins/
    cfe/trunk/test/Analysis/plugins/CMakeLists.txt
    cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/
    cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt
    cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
    cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
    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
    cfe/trunk/test/Analysis/plugins/SampleAnalyzer/
    cfe/trunk/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
    cfe/trunk/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
    cfe/trunk/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
Removed:
    cfe/trunk/lib/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=361793&r1=361792&r2=361793&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CMakeLists.txt (original)
+++ cfe/trunk/lib/Analysis/CMakeLists.txt Mon May 27 23:38:16 2019
@@ -34,5 +34,3 @@ add_clang_library(clangAnalysis
   clangBasic
   clangLex
   )
-
-add_subdirectory(plugins)

Modified: cfe/trunk/test/Analysis/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/lit.local.cfg?rev=361793&r1=361792&r2=361793&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/lit.local.cfg (original)
+++ cfe/trunk/test/Analysis/lit.local.cfg Mon May 27 23:38:16 2019
@@ -18,5 +18,7 @@ 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

Added: cfe/trunk/test/Analysis/plugins/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/CMakeLists.txt?rev=361793&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CMakeLists.txt (added)
+++ cfe/trunk/test/Analysis/plugins/CMakeLists.txt Mon May 27 23:38:16 2019
@@ -0,0 +1,12 @@
+add_subdirectory(SampleAnalyzer)
+add_subdirectory(CheckerDependencyHandling)
+add_subdirectory(CheckerOptionHandling)
+
+set(CLANG_ANALYZER_PLUGIN_DEPS
+  SampleAnalyzerPlugin
+  CheckerDependencyHandlingAnalyzerPlugin
+  CheckerOptionHandlingAnalyzerPlugin
+  )
+
+add_custom_target(clang-analyzer-plugin
+  DEPENDS ${CLANG_ANALYZER_PLUGIN_DEPS})

Added: cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt?rev=361793&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt (added)
+++ cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt Mon May 27 23:38:16 2019
@@ -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()

Added: cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp?rev=361793&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp (added)
+++ cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp Mon May 27 23:38:16 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 &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;

Added: cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports?rev=361793&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports (added)
+++ cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports Mon May 27 23:38:16 2019
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString

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=361793&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt (added)
+++ cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt Mon May 27 23:38:16 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=361793&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp (added)
+++ cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp Mon May 27 23:38:16 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 &registry) {
+  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/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports?rev=361793&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports (added)
+++ cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandlingAnalyzerPlugin.exports Mon May 27 23:38:16 2019
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString

Added: cfe/trunk/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt?rev=361793&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt (added)
+++ cfe/trunk/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt Mon May 27 23:38:16 2019
@@ -0,0 +1,11 @@
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/SampleAnalyzerPlugin.exports)
+add_llvm_library(SampleAnalyzerPlugin MODULE MainCallChecker.cpp PLUGIN_TOOL clang)
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+  target_link_libraries(SampleAnalyzerPlugin PRIVATE
+    clangAnalysis
+    clangAST
+    clangStaticAnalyzerCore
+    LLVMSupport
+    )
+endif()

Added: cfe/trunk/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp?rev=361793&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp (added)
+++ cfe/trunk/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp Mon May 27 23:38:16 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 &registry) {
+  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/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports?rev=361793&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports (added)
+++ cfe/trunk/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports Mon May 27 23:38:16 2019
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString

Modified: cfe/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=361793&r1=361792&r2=361793&view=diff
==============================================================================
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Mon May 27 23:38:16 2019
@@ -126,13 +126,27 @@ if( NOT CLANG_BUILT_STANDALONE )
 endif()
 
 if (CLANG_ENABLE_STATIC_ANALYZER)
-  if (LLVM_ENABLE_PLUGINS)
-    set(CLANG_ANALYZER_PLUGIN_DEPS
-      SampleAnalyzerPlugin
-      CheckerDependencyHandlingAnalyzerPlugin
-      CheckerOptionHandlingAnalyzerPlugin
-      )
+  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")
   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