forked from OSchip/llvm-project
[analyzer] CheckerContext: Make the Preprocessor available
Summary: This patch hooks the `Preprocessor` trough `BugReporter` to the `CheckerContext` so the checkers could look for macro definitions. Reviewed By: NoQ Differential Revision: https://reviews.llvm.org/D69731
This commit is contained in:
parent
fdc496a3d3
commit
38ab3b876b
|
@ -17,12 +17,13 @@
|
|||
#include "clang/Analysis/PathDiagnostic.h"
|
||||
#include "clang/Basic/LLVM.h"
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
|
||||
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
#include "llvm/ADT/FoldingSet.h"
|
||||
|
@ -566,6 +567,7 @@ public:
|
|||
virtual ASTContext &getASTContext() = 0;
|
||||
virtual SourceManager &getSourceManager() = 0;
|
||||
virtual AnalyzerOptions &getAnalyzerOptions() = 0;
|
||||
virtual Preprocessor &getPreprocessor() = 0;
|
||||
};
|
||||
|
||||
/// BugReporter is a utility class for generating PathDiagnostics for analysis.
|
||||
|
@ -608,6 +610,8 @@ public:
|
|||
|
||||
const AnalyzerOptions &getAnalyzerOptions() { return D.getAnalyzerOptions(); }
|
||||
|
||||
Preprocessor &getPreprocessor() { return D.getPreprocessor(); }
|
||||
|
||||
/// Add the given report to the set of reports tracked by BugReporter.
|
||||
///
|
||||
/// The reports are usually generated by the checkers. Further, they are
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "clang/Analysis/AnalysisDeclContext.h"
|
||||
#include "clang/Analysis/PathDiagnostic.h"
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
|
||||
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
|
||||
|
@ -32,6 +33,7 @@ class AnalysisManager : public BugReporterData {
|
|||
AnalysisDeclContextManager AnaCtxMgr;
|
||||
|
||||
ASTContext &Ctx;
|
||||
Preprocessor &PP;
|
||||
const LangOptions &LangOpts;
|
||||
PathDiagnosticConsumers PathConsumers;
|
||||
|
||||
|
@ -44,7 +46,7 @@ class AnalysisManager : public BugReporterData {
|
|||
public:
|
||||
AnalyzerOptions &options;
|
||||
|
||||
AnalysisManager(ASTContext &ctx,
|
||||
AnalysisManager(ASTContext &ctx, Preprocessor &PP,
|
||||
const PathDiagnosticConsumers &Consumers,
|
||||
StoreManagerCreator storemgr,
|
||||
ConstraintManagerCreator constraintmgr,
|
||||
|
@ -61,6 +63,8 @@ public:
|
|||
return AnaCtxMgr;
|
||||
}
|
||||
|
||||
Preprocessor &getPreprocessor() override { return PP; }
|
||||
|
||||
StoreManagerCreator getStoreManagerCreator() {
|
||||
return CreateStoreMgr;
|
||||
}
|
||||
|
|
|
@ -107,6 +107,8 @@ public:
|
|||
return getBugReporter().getSourceManager();
|
||||
}
|
||||
|
||||
Preprocessor &getPreprocessor() { return getBugReporter().getPreprocessor(); }
|
||||
|
||||
SValBuilder &getSValBuilder() {
|
||||
return Eng.getSValBuilder();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ using namespace ento;
|
|||
|
||||
void AnalysisManager::anchor() { }
|
||||
|
||||
AnalysisManager::AnalysisManager(ASTContext &ASTCtx,
|
||||
AnalysisManager::AnalysisManager(ASTContext &ASTCtx, Preprocessor &PP,
|
||||
const PathDiagnosticConsumers &PDC,
|
||||
StoreManagerCreator storemgr,
|
||||
ConstraintManagerCreator constraintmgr,
|
||||
|
@ -38,7 +38,7 @@ AnalysisManager::AnalysisManager(ASTContext &ASTCtx,
|
|||
Options.ShouldElideConstructors,
|
||||
/*addVirtualBaseBranches=*/true,
|
||||
injector),
|
||||
Ctx(ASTCtx), LangOpts(ASTCtx.getLangOpts()),
|
||||
Ctx(ASTCtx), PP(PP), LangOpts(ASTCtx.getLangOpts()),
|
||||
PathConsumers(PDC), CreateStoreMgr(storemgr),
|
||||
CreateConstraintMgr(constraintmgr), CheckerMgr(checkerMgr),
|
||||
options(Options) {
|
||||
|
|
|
@ -193,7 +193,7 @@ class AnalysisConsumer : public AnalysisASTConsumer,
|
|||
|
||||
public:
|
||||
ASTContext *Ctx;
|
||||
const Preprocessor &PP;
|
||||
Preprocessor &PP;
|
||||
const std::string OutDir;
|
||||
AnalyzerOptionsRef Opts;
|
||||
ArrayRef<std::string> Plugins;
|
||||
|
@ -336,8 +336,8 @@ public:
|
|||
checkerMgr = createCheckerManager(
|
||||
*Ctx, *Opts, Plugins, CheckerRegistrationFns, PP.getDiagnostics());
|
||||
|
||||
Mgr = std::make_unique<AnalysisManager>(*Ctx, PathConsumers, CreateStoreMgr,
|
||||
CreateConstraintMgr,
|
||||
Mgr = std::make_unique<AnalysisManager>(*Ctx, PP, PathConsumers,
|
||||
CreateStoreMgr, CreateConstraintMgr,
|
||||
checkerMgr.get(), *Opts, Injector);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
ExprEngineConsumer(CompilerInstance &C)
|
||||
: C(C), ChkMgr(C.getASTContext(), *C.getAnalyzerOpts()), CTU(C),
|
||||
Consumers(),
|
||||
AMgr(C.getASTContext(), Consumers,
|
||||
AMgr(C.getASTContext(), C.getPreprocessor(), Consumers,
|
||||
CreateRegionStoreManager, CreateRangeConstraintManager, &ChkMgr,
|
||||
*C.getAnalyzerOpts()),
|
||||
VisitedCallees(), FS(),
|
||||
|
|
Loading…
Reference in New Issue