From 8dae128d16bf98759b7a678ce3eebb613bd17109 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 16 Apr 2013 21:10:05 +0000 Subject: [PATCH] Factor CheckerManager to be able to pass AnalyzerOptions to checkers during checker registration. There are no immediate clients of this, but this provides a way for checkers to query the options table at startup instead. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179626 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../StaticAnalyzer/Core/AnalyzerOptions.h | 2 +- .../StaticAnalyzer/Core/CheckerManager.h | 24 +++++++++++++++++-- .../Frontend/CheckerRegistration.h | 2 +- .../Frontend/CheckerRegistration.cpp | 5 ++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h index 6dbdbbf89b..fb35f518ef 100644 --- a/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -232,6 +232,7 @@ private: /// \sa getMaxNodesPerTopLevelFunction Optional MaxNodesPerTopLevelFunction; +public: /// Interprets an option's string value as a boolean. /// /// Accepts the strings "true" and "false". @@ -244,7 +245,6 @@ private: /// Interprets an option's string value as an integer value. int getOptionAsInteger(StringRef Name, int DefaultVal); -public: /// \brief Retrieves and sets the UserMode. This is a high-level option, /// which is used to set other low-level options. It is not accessible /// outside of AnalyzerOptions. diff --git a/include/clang/StaticAnalyzer/Core/CheckerManager.h b/include/clang/StaticAnalyzer/Core/CheckerManager.h index 6f99fc1457..b2411e6e65 100644 --- a/include/clang/StaticAnalyzer/Core/CheckerManager.h +++ b/include/clang/StaticAnalyzer/Core/CheckerManager.h @@ -17,6 +17,7 @@ #include "clang/Analysis/ProgramPoint.h" #include "clang/Basic/LangOptions.h" #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h" +#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/SmallVector.h" @@ -134,9 +135,13 @@ enum PointerEscapeKind { class CheckerManager { const LangOptions LangOpts; - + AnalyzerOptionsRef AOptions; public: - CheckerManager(const LangOptions &langOpts) : LangOpts(langOpts) { } + CheckerManager(const LangOptions &langOpts, + AnalyzerOptionsRef AOptions) + : LangOpts(langOpts), + AOptions(AOptions) {} + ~CheckerManager(); bool hasPathSensitiveCheckers() const; @@ -144,6 +149,7 @@ public: void finishedCheckerRegistration(); const LangOptions &getLangOpts() const { return LangOpts; } + AnalyzerOptions &getAnalyzerOptions() { return *AOptions; } typedef CheckerBase *CheckerRef; typedef const void *CheckerTag; @@ -170,6 +176,20 @@ public: return checker; } + template + CHECKER *registerChecker(AnalyzerOptions &AOpts) { + CheckerTag tag = getTag(); + CheckerRef &ref = CheckerTags[tag]; + if (ref) + return static_cast(ref); // already registered. + + CHECKER *checker = new CHECKER(AOpts); + CheckerDtors.push_back(CheckerDtor(checker, destruct)); + CHECKER::_register(checker, *this); + ref = checker; + return checker; + } + //===----------------------------------------------------------------------===// // Functions for running checkers for AST traversing.. //===----------------------------------------------------------------------===// diff --git a/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h b/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h index 492edd4ccb..1df8c098d9 100644 --- a/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h +++ b/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h @@ -21,7 +21,7 @@ namespace clang { namespace ento { class CheckerManager; -CheckerManager *createCheckerManager(const AnalyzerOptions &opts, +CheckerManager *createCheckerManager(AnalyzerOptions &opts, const LangOptions &langOpts, ArrayRef plugins, DiagnosticsEngine &diags); diff --git a/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp b/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp index 4fad5a8a7c..e7def08819 100644 --- a/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp +++ b/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp @@ -100,11 +100,12 @@ void ClangCheckerRegistry::warnIncompatible(DiagnosticsEngine *diags, } -CheckerManager *ento::createCheckerManager(const AnalyzerOptions &opts, +CheckerManager *ento::createCheckerManager(AnalyzerOptions &opts, const LangOptions &langOpts, ArrayRef plugins, DiagnosticsEngine &diags) { - OwningPtr checkerMgr(new CheckerManager(langOpts)); + OwningPtr checkerMgr(new CheckerManager(langOpts, + &opts)); SmallVector checkerOpts; for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {