[clang] 4dc8472 - [analyzer] Add the Preprocessor to CheckerManager
Kirstóf Umann via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 26 09:30:53 PDT 2020
Author: Kirstóf Umann
Date: 2020-03-26T17:29:52+01:00
New Revision: 4dc8472942ce60f29de9587b9451cc3d49df7abf
URL: https://github.com/llvm/llvm-project/commit/4dc8472942ce60f29de9587b9451cc3d49df7abf
DIFF: https://github.com/llvm/llvm-project/commit/4dc8472942ce60f29de9587b9451cc3d49df7abf.diff
LOG: [analyzer] Add the Preprocessor to CheckerManager
Added:
Modified:
clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp
clang/unittests/StaticAnalyzer/Reusables.h
Removed:
################################################################################
diff --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index 4635ca35736a..f34f5c239290 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -122,9 +122,10 @@ enum class ObjCMessageVisitKind {
};
class CheckerManager {
- ASTContext *Context;
+ ASTContext *Context = nullptr;
const LangOptions LangOpts;
- AnalyzerOptions &AOptions;
+ const AnalyzerOptions &AOptions;
+ const Preprocessor *PP = nullptr;
CheckerNameRef CurrentCheckerName;
DiagnosticsEngine &Diags;
std::unique_ptr<CheckerRegistry> Registry;
@@ -137,15 +138,16 @@ class CheckerManager {
// dependencies look like this: Core -> Checkers -> Frontend.
CheckerManager(
- ASTContext &Context, AnalyzerOptions &AOptions,
+ ASTContext &Context, AnalyzerOptions &AOptions, const Preprocessor &PP,
ArrayRef<std::string> plugins,
ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns);
/// Constructs a CheckerManager that ignores all non TblGen-generated
/// checkers. Useful for unit testing, unless the checker infrastructure
/// itself is tested.
- CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions)
- : CheckerManager(Context, AOptions, {}, {}) {}
+ CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions,
+ const Preprocessor &PP)
+ : CheckerManager(Context, AOptions, PP, {}, {}) {}
/// Constructs a CheckerManager without requiring an AST. No checker
/// registration will take place. Only useful for retrieving the
@@ -163,7 +165,11 @@ class CheckerManager {
void finishedCheckerRegistration();
const LangOptions &getLangOpts() const { return LangOpts; }
- AnalyzerOptions &getAnalyzerOptions() const { return AOptions; }
+ const AnalyzerOptions &getAnalyzerOptions() const { return AOptions; }
+ const Preprocessor &getPreprocessor() const {
+ assert(PP);
+ return *PP;
+ }
const CheckerRegistry &getCheckerRegistry() const { return *Registry; }
DiagnosticsEngine &getDiagnostics() const { return Diags; }
ASTContext &getASTContext() const {
diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
index 6f8cb1432bb1..1af93cc45363 100644
--- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -1485,7 +1485,7 @@ bool ento::shouldRegisterRetainCountBase(const LangOptions &LO) {
// it should be possible to enable the NS/CF retain count checker as
// osx.cocoa.RetainCount, and it should be possible to disable
// osx.OSObjectRetainCount using osx.cocoa.RetainCount:CheckOSObject=false.
-static bool getOption(AnalyzerOptions &Options,
+static bool getOption(const AnalyzerOptions &Options,
StringRef Postfix,
StringRef Value) {
auto I = Options.Config.find(
diff --git a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index 14f551403d98..562d553b8a84 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -608,7 +608,7 @@ std::string clang::ento::getVariableName(const FieldDecl *Field) {
void ento::registerUninitializedObjectChecker(CheckerManager &Mgr) {
auto Chk = Mgr.registerChecker<UninitializedObjectChecker>();
- AnalyzerOptions &AnOpts = Mgr.getAnalyzerOptions();
+ const AnalyzerOptions &AnOpts = Mgr.getAnalyzerOptions();
UninitObjCheckerOptions &ChOpts = Chk->Opts;
ChOpts.IsPedantic = AnOpts.getCheckerBooleanOption(Chk, "Pedantic");
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 6c123521e5f8..74c689730e58 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -208,7 +208,7 @@ class AnalysisConsumer : public AnalysisASTConsumer,
void Initialize(ASTContext &Context) override {
Ctx = &Context;
- checkerMgr = std::make_unique<CheckerManager>(*Ctx, *Opts, Plugins,
+ checkerMgr = std::make_unique<CheckerManager>(*Ctx, *Opts, PP, Plugins,
CheckerRegistrationFns);
Mgr = std::make_unique<AnalysisManager>(*Ctx, PP, PathConsumers,
diff --git a/clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp b/clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp
index f93e328c47b2..140f80751443 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp
@@ -18,11 +18,11 @@ namespace clang {
namespace ento {
CheckerManager::CheckerManager(
- ASTContext &Context, AnalyzerOptions &AOptions,
+ ASTContext &Context, AnalyzerOptions &AOptions, const Preprocessor &PP,
ArrayRef<std::string> plugins,
ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns)
: Context(&Context), LangOpts(Context.getLangOpts()), AOptions(AOptions),
- Diags(Context.getDiagnostics()),
+ PP(&PP), Diags(Context.getDiagnostics()),
Registry(
std::make_unique<CheckerRegistry>(plugins, Context.getDiagnostics(),
AOptions, checkerRegistrationFns)) {
@@ -31,9 +31,6 @@ CheckerManager::CheckerManager(
finishedCheckerRegistration();
}
-/// Constructs a CheckerManager without requiring an AST. No checker
-/// registration will take place. Only useful for retrieving the
-/// CheckerRegistry and print for help flags where the AST is unavalaible.
CheckerManager::CheckerManager(AnalyzerOptions &AOptions,
const LangOptions &LangOpts,
DiagnosticsEngine &Diags,
diff --git a/clang/unittests/StaticAnalyzer/Reusables.h b/clang/unittests/StaticAnalyzer/Reusables.h
index 1346adbac90a..3f2fd6164200 100644
--- a/clang/unittests/StaticAnalyzer/Reusables.h
+++ b/clang/unittests/StaticAnalyzer/Reusables.h
@@ -56,8 +56,9 @@ class ExprEngineConsumer : public ASTConsumer {
public:
ExprEngineConsumer(CompilerInstance &C)
- : C(C), ChkMgr(C.getASTContext(), *C.getAnalyzerOpts()), CTU(C),
- Consumers(),
+ : C(C),
+ ChkMgr(C.getASTContext(), *C.getAnalyzerOpts(), C.getPreprocessor()),
+ CTU(C), Consumers(),
AMgr(C.getASTContext(), C.getPreprocessor(), Consumers,
CreateRegionStoreManager, CreateRangeConstraintManager, &ChkMgr,
*C.getAnalyzerOpts()),
More information about the cfe-commits
mailing list