From: Kristof Umann Date: Sat, 26 Jan 2019 17:27:40 +0000 (+0000) Subject: [analyzer] Fix an bug where statically linked, but not registered checkers weren... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb6faaff295526961edd4b76eb28ac88c591948c;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352284 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h b/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h index a69dca3be0..8424564028 100644 --- a/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h +++ b/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h @@ -81,8 +81,11 @@ namespace ento { /// "core.builtin", or the full name "core.builtin.NoReturnFunctionChecker". class CheckerRegistry { public: - CheckerRegistry(ArrayRef plugins, DiagnosticsEngine &diags, - AnalyzerOptions &AnOpts, const LangOptions &LangOpts); + CheckerRegistry( + ArrayRef plugins, DiagnosticsEngine &diags, + AnalyzerOptions &AnOpts, const LangOptions &LangOpts, + ArrayRef> + checkerRegistrationFns = {}); /// Initialization functions perform any necessary setup for a checker. /// They should include a call to CheckerManager::registerChecker. diff --git a/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp b/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp index fbf9e5b00d..58f81b4ffb 100644 --- a/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp +++ b/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp @@ -33,10 +33,8 @@ std::unique_ptr ento::createCheckerManager( DiagnosticsEngine &diags) { auto checkerMgr = llvm::make_unique(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(); diff --git a/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp b/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp index 08633ce740..8850b2895c 100644 --- a/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp +++ b/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp @@ -91,10 +91,11 @@ CheckerRegistry::getMutableCheckersForCmdLineArg(StringRef CmdLineArg) { return { it, it + size }; } -CheckerRegistry::CheckerRegistry(ArrayRef plugins, - DiagnosticsEngine &diags, - AnalyzerOptions &AnOpts, - const LangOptions &LangOpts) +CheckerRegistry::CheckerRegistry( + ArrayRef plugins, DiagnosticsEngine &diags, + AnalyzerOptions &AnOpts, const LangOptions &LangOpts, + ArrayRef> + checkerRegistrationFns) : Diags(diags), AnOpts(AnOpts), LangOpts(LangOpts) { // Register builtin checkers. @@ -137,6 +138,13 @@ CheckerRegistry::CheckerRegistry(ArrayRef plugins, 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