[analyzer] Add the Preprocessor to CheckerManager

This commit is contained in:
Kirstóf Umann 2020-03-26 17:27:13 +01:00
parent 40076c14fe
commit 4dc8472942
6 changed files with 20 additions and 16 deletions

View File

@ -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 @@ public:
// 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 @@ public:
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 {

View File

@ -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(

View File

@ -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");

View File

@ -208,7 +208,7 @@ public:
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,

View File

@ -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,

View File

@ -56,8 +56,9 @@ protected:
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()),