This revision was automatically updated to reflect the committed changes.
Closed by commit rL360799: [analyzer] Add a test for plugins using checker
dependencies (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D59464?vs=196083&id=199663#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59464/new/
https://reviews.llvm.org/D59464
Files:
cfe/trunk/examples/CMakeLists.txt
cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp
cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
cfe/trunk/test/Analysis/checker-plugins.c
cfe/trunk/test/Analysis/lit.local.cfg
cfe/trunk/test/Analysis/plugins/CMakeLists.txt
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/SampleAnalyzer/CMakeLists.txt
cfe/trunk/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
cfe/trunk/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
cfe/trunk/test/CMakeLists.txt
Index: cfe/trunk/test/CMakeLists.txt
===================================================================
--- cfe/trunk/test/CMakeLists.txt
+++ cfe/trunk/test/CMakeLists.txt
@@ -139,13 +139,15 @@
# 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
Index: cfe/trunk/test/Analysis/checker-plugins.c
===================================================================
--- cfe/trunk/test/Analysis/checker-plugins.c
+++ cfe/trunk/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 @@
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: cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
===================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
+++ cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandlingAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Index: cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt
===================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt
+++ cfe/trunk/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()
Index: cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
===================================================================
--- cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CheckerDependencyHandling.cpp
+++ cfe/trunk/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 ®istry) {
+ 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: cfe/trunk/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
===================================================================
--- cfe/trunk/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
+++ cfe/trunk/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
@@ -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()
Index: cfe/trunk/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
===================================================================
--- cfe/trunk/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
+++ cfe/trunk/test/Analysis/plugins/SampleAnalyzer/SampleAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Index: cfe/trunk/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
===================================================================
--- cfe/trunk/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
+++ cfe/trunk/test/Analysis/plugins/SampleAnalyzer/MainCallChecker.cpp
@@ -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 ®istry) {
+ registry.addChecker<MainCallChecker>(
+ "example.MainCallChecker", "Disallows calls to functions called main",
+ "");
+}
+
+extern "C" const char clang_analyzerAPIVersionString[] =
+ CLANG_ANALYZER_API_VERSION_STRING;
Index: cfe/trunk/test/Analysis/plugins/CMakeLists.txt
===================================================================
--- cfe/trunk/test/Analysis/plugins/CMakeLists.txt
+++ cfe/trunk/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})
Index: cfe/trunk/test/Analysis/lit.local.cfg
===================================================================
--- cfe/trunk/test/Analysis/lit.local.cfg
+++ cfe/trunk/test/Analysis/lit.local.cfg
@@ -18,5 +18,7 @@
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
Index: cfe/trunk/examples/CMakeLists.txt
===================================================================
--- cfe/trunk/examples/CMakeLists.txt
+++ cfe/trunk/examples/CMakeLists.txt
@@ -3,9 +3,6 @@
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)
Index: cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
===================================================================
--- cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
+++ cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
@@ -1,11 +0,0 @@
-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()
Index: cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
===================================================================
--- cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
+++ cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
@@ -1,2 +0,0 @@
-clang_registerCheckers
-clang_analyzerAPIVersionString
Index: cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp
===================================================================
--- cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp
+++ cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp
@@ -1,54 +0,0 @@
-#include "clang/StaticAnalyzer/Core/Checker.h"
-#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
-#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.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 ®istry) {
- registry.addChecker<MainCallChecker>(
- "example.MainCallChecker", "Disallows calls to functions called main",
- "");
-}
-
-extern "C"
-const char clang_analyzerAPIVersionString[] = CLANG_ANALYZER_API_VERSION_STRING;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits