aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Umann <kristof.umann@ericsson.com>2019-05-15 19:47:26 +0000
committerKristof Umann <kristof.umann@ericsson.com>2019-05-15 19:47:26 +0000
commit47241aaff70bcf2dbc535465c2d8075ae5c6ee44 (patch)
treeca966eaee6a956dd7cf684ff1358c9caac534b77
parent1ca049959f579c1d5f51ffc0ed8a4d74e8a1c6c8 (diff)
downloadllvm-47241aaff70bcf2dbc535465c2d8075ae5c6ee44.zip
llvm-47241aaff70bcf2dbc535465c2d8075ae5c6ee44.tar.gz
llvm-47241aaff70bcf2dbc535465c2d8075ae5c6ee44.tar.bz2
[analyzer] Add a test for plugins using checker dependencies
Also, I moved the existing analyzer plugin to test/ as well, in order not to give the illusion that the analyzer supports plugins -- it's capable of handling them, but does not _support_ them. Differential Revision: https://reviews.llvm.org/D59464 llvm-svn: 360799
-rw-r--r--clang/examples/CMakeLists.txt3
-rw-r--r--clang/test/Analysis/checker-plugins.c26
-rw-r--r--clang/test/Analysis/lit.local.cfg2
-rw-r--r--clang/test/Analysis/plugins/CMakeLists.txt10
-rw-r--r--clang/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt11
-rw-r--r--clang/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp28
-rw-r--r--clang/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports (renamed from clang/examples/analyzer-plugin/SampleAnalyzerPlugin.exports)0
-rw-r--r--clang/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt (renamed from clang/examples/analyzer-plugin/CMakeLists.txt)0
-rw-r--r--clang/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp (renamed from clang/examples/analyzer-plugin/MainCallChecker.cpp)18
-rw-r--r--clang/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports2
-rw-r--r--clang/test/CMakeLists.txt4
11 files changed, 89 insertions, 15 deletions
diff --git a/clang/examples/CMakeLists.txt b/clang/examples/CMakeLists.txt
index 8c26548..e4fedf3 100644
--- a/clang/examples/CMakeLists.txt
+++ b/clang/examples/CMakeLists.txt
@@ -3,9 +3,6 @@ if(NOT CLANG_BUILD_EXAMPLES)
set(EXCLUDE_FROM_ALL ON)
endif()
-if(CLANG_ENABLE_STATIC_ANALYZER)
-add_subdirectory(analyzer-plugin)
-endif()
add_subdirectory(clang-interpreter)
add_subdirectory(PrintFunctionNames)
add_subdirectory(AnnotateFunctions)
diff --git a/clang/test/Analysis/checker-plugins.c b/clang/test/Analysis/checker-plugins.c
index ee60ec6..f0a5484 100644
--- a/clang/test/Analysis/checker-plugins.c
+++ b/clang/test/Analysis/checker-plugins.c
@@ -1,5 +1,8 @@
-// RUN: %clang_analyze_cc1 -load %llvmshlibdir/SampleAnalyzerPlugin%pluginext -analyzer-checker='example.MainCallChecker' -verify %s
-// REQUIRES: plugins, examples
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN: -load %llvmshlibdir/SampleAnalyzerPlugin%pluginext \
+// RUN: -analyzer-checker='example.MainCallChecker'
+
+// REQUIRES: plugins
// Test that the MainCallChecker example analyzer plugin loads and runs.
@@ -8,3 +11,22 @@ int main();
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
diff --git a/clang/test/Analysis/lit.local.cfg b/clang/test/Analysis/lit.local.cfg
index 84f7569..b77cae8 100644
--- a/clang/test/Analysis/lit.local.cfg
+++ b/clang/test/Analysis/lit.local.cfg
@@ -18,5 +18,7 @@ config.substitutions.append(('%diff_plist',
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
diff --git a/clang/test/Analysis/plugins/CMakeLists.txt b/clang/test/Analysis/plugins/CMakeLists.txt
new file mode 100644
index 0000000..3f538d9
--- /dev/null
+++ b/clang/test/Analysis/plugins/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_subdirectory(SampleAnalyzer)
+add_subdirectory(CheckerDependencyHandling)
+
+set(CLANG_ANALYZER_PLUGIN_DEPS
+ SampleAnalyzerPlugin
+ CheckerDependencyHandlingAnalyzerPlugin
+ )
+
+add_custom_target(clang-analyzer-plugin
+ DEPENDS ${CLANG_ANALYZER_PLUGIN_DEPS})
diff --git a/clang/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt b/clang/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt
new file mode 100644
index 0000000..80e2cdb
--- /dev/null
+++ b/clang/test/Analysis/plugins/CheckerDependencyHandling/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()
diff --git a/clang/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp b/clang/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
new file mode 100644
index 0000000..be8e120
--- /dev/null
+++ b/clang/test/Analysis/plugins/CheckerDependencyHandling/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;
diff --git a/clang/examples/analyzer-plugin/SampleAnalyzerPlugin.exports b/clang/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
index 8d9ff88..8d9ff88 100644
--- a/clang/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
+++ b/clang/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
diff --git a/clang/examples/analyzer-plugin/CMakeLists.txt b/clang/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
index 7c7b2ae..7c7b2ae 100644
--- a/clang/examples/analyzer-plugin/CMakeLists.txt
+++ b/clang/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
diff --git a/clang/examples/analyzer-plugin/MainCallChecker.cpp b/clang/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
index 77316d6..8bd4085 100644
--- a/clang/examples/analyzer-plugin/MainCallChecker.cpp
+++ b/clang/test/Analysis/plugins/SampleAnalyzer/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 @@ public:
};
} // 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 @@ void MainCallChecker::checkPreStmt(const CallExpr *CE, CheckerContext &C) const
// 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 @@ void MainCallChecker::checkPreStmt(const CallExpr *CE, CheckerContext &C) const
}
// 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;
diff --git a/clang/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports b/clang/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
new file mode 100644
index 0000000..8d9ff88
--- /dev/null
+++ b/clang/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 65a1d6e9..43e49d5 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -139,13 +139,15 @@ if (CLANG_ENABLE_STATIC_ANALYZER)
# check-all would launch those tests via check-clang.
set(EXCLUDE_FROM_ALL ON)
+ add_subdirectory(Analysis/plugins)
+ list(APPEND CLANG_TEST_DEPS clang-analyzer-plugin)
+
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