r352284 - [analyzer] Fix an bug where statically linked, but not registered checkers weren't recognized

Kristof Umann via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 26 09:27:41 PST 2019


Author: szelethus
Date: Sat Jan 26 09:27:40 2019
New Revision: 352284

URL: http://llvm.org/viewvc/llvm-project?rev=352284&view=rev
Log:
[analyzer] Fix an bug where statically linked, but not registered checkers weren't recognized

My last patch, D56989, moved the validation of whether a checker exists into
its constructor, but we do support statically linked (and non-plugin) checkers
that were do not have an entry in Checkers.td. However, the handling of this
happens after the creation of the CheckerRegistry object.

This patch fixes this bug by moving even this functionality into
CheckerRegistry's constructor.

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
    cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
    cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h?rev=352284&r1=352283&r2=352284&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h Sat Jan 26 09:27:40 2019
@@ -81,8 +81,11 @@ namespace ento {
 /// "core.builtin", or the full name "core.builtin.NoReturnFunctionChecker".
 class CheckerRegistry {
 public:
-  CheckerRegistry(ArrayRef<std::string> plugins, DiagnosticsEngine &diags,
-                  AnalyzerOptions &AnOpts, const LangOptions &LangOpts);
+  CheckerRegistry(
+      ArrayRef<std::string> plugins, DiagnosticsEngine &diags,
+      AnalyzerOptions &AnOpts, const LangOptions &LangOpts,
+      ArrayRef<std::function<void(CheckerRegistry &)>>
+          checkerRegistrationFns = {});
 
   /// Initialization functions perform any necessary setup for a checker.
   /// They should include a call to CheckerManager::registerChecker.

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp?rev=352284&r1=352283&r2=352284&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp Sat Jan 26 09:27:40 2019
@@ -33,10 +33,8 @@ std::unique_ptr<CheckerManager> ento::cr
     DiagnosticsEngine &diags) {
   auto checkerMgr = llvm::make_unique<CheckerManager>(context, opts);
 
-  CheckerRegistry allCheckers(plugins, diags, opts, context.getLangOpts());
-
-  for (const auto &Fn : checkerRegistrationFns)
-    Fn(allCheckers);
+  CheckerRegistry allCheckers(plugins, diags, opts, context.getLangOpts(),
+                              checkerRegistrationFns);
 
   allCheckers.initializeManager(*checkerMgr);
   allCheckers.validateCheckerOptions();

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp?rev=352284&r1=352283&r2=352284&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp Sat Jan 26 09:27:40 2019
@@ -91,10 +91,11 @@ CheckerRegistry::getMutableCheckersForCm
   return { it, it + size };
 }
 
-CheckerRegistry::CheckerRegistry(ArrayRef<std::string> plugins,
-                                 DiagnosticsEngine &diags,
-                                 AnalyzerOptions &AnOpts,
-                                 const LangOptions &LangOpts)
+CheckerRegistry::CheckerRegistry(
+     ArrayRef<std::string> plugins, DiagnosticsEngine &diags,
+     AnalyzerOptions &AnOpts, const LangOptions &LangOpts,
+     ArrayRef<std::function<void(CheckerRegistry &)>>
+         checkerRegistrationFns)
   : Diags(diags), AnOpts(AnOpts), LangOpts(LangOpts) {
 
   // Register builtin checkers.
@@ -137,6 +138,13 @@ CheckerRegistry::CheckerRegistry(ArrayRe
       registerPluginCheckers(*this);
   }
 
+  // Register statically linked checkers, that aren't generated from the tblgen
+  // file, but rather passed their registry function as a parameter in 
+  // checkerRegistrationFns. 
+
+  for (const auto &Fn : checkerRegistrationFns)
+    Fn(*this);
+
   // Sort checkers for efficient collection.
   // FIXME: Alphabetical sort puts 'experimental' in the middle.
   // Would it be better to name it '~experimental' or something else




More information about the cfe-commits mailing list