Skip to content

Commit 4dc8472

Browse files
committed
[analyzer] Add the Preprocessor to CheckerManager
1 parent 40076c1 commit 4dc8472

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

clang/include/clang/StaticAnalyzer/Core/CheckerManager.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ enum class ObjCMessageVisitKind {
122122
};
123123

124124
class CheckerManager {
125-
ASTContext *Context;
125+
ASTContext *Context = nullptr;
126126
const LangOptions LangOpts;
127-
AnalyzerOptions &AOptions;
127+
const AnalyzerOptions &AOptions;
128+
const Preprocessor *PP = nullptr;
128129
CheckerNameRef CurrentCheckerName;
129130
DiagnosticsEngine &Diags;
130131
std::unique_ptr<CheckerRegistry> Registry;
@@ -137,15 +138,16 @@ class CheckerManager {
137138
// dependencies look like this: Core -> Checkers -> Frontend.
138139

139140
CheckerManager(
140-
ASTContext &Context, AnalyzerOptions &AOptions,
141+
ASTContext &Context, AnalyzerOptions &AOptions, const Preprocessor &PP,
141142
ArrayRef<std::string> plugins,
142143
ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns);
143144

144145
/// Constructs a CheckerManager that ignores all non TblGen-generated
145146
/// checkers. Useful for unit testing, unless the checker infrastructure
146147
/// itself is tested.
147-
CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions)
148-
: CheckerManager(Context, AOptions, {}, {}) {}
148+
CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions,
149+
const Preprocessor &PP)
150+
: CheckerManager(Context, AOptions, PP, {}, {}) {}
149151

150152
/// Constructs a CheckerManager without requiring an AST. No checker
151153
/// registration will take place. Only useful for retrieving the
@@ -163,7 +165,11 @@ class CheckerManager {
163165
void finishedCheckerRegistration();
164166

165167
const LangOptions &getLangOpts() const { return LangOpts; }
166-
AnalyzerOptions &getAnalyzerOptions() const { return AOptions; }
168+
const AnalyzerOptions &getAnalyzerOptions() const { return AOptions; }
169+
const Preprocessor &getPreprocessor() const {
170+
assert(PP);
171+
return *PP;
172+
}
167173
const CheckerRegistry &getCheckerRegistry() const { return *Registry; }
168174
DiagnosticsEngine &getDiagnostics() const { return Diags; }
169175
ASTContext &getASTContext() const {

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ bool ento::shouldRegisterRetainCountBase(const LangOptions &LO) {
14851485
// it should be possible to enable the NS/CF retain count checker as
14861486
// osx.cocoa.RetainCount, and it should be possible to disable
14871487
// osx.OSObjectRetainCount using osx.cocoa.RetainCount:CheckOSObject=false.
1488-
static bool getOption(AnalyzerOptions &Options,
1488+
static bool getOption(const AnalyzerOptions &Options,
14891489
StringRef Postfix,
14901490
StringRef Value) {
14911491
auto I = Options.Config.find(

clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ std::string clang::ento::getVariableName(const FieldDecl *Field) {
608608
void ento::registerUninitializedObjectChecker(CheckerManager &Mgr) {
609609
auto Chk = Mgr.registerChecker<UninitializedObjectChecker>();
610610

611-
AnalyzerOptions &AnOpts = Mgr.getAnalyzerOptions();
611+
const AnalyzerOptions &AnOpts = Mgr.getAnalyzerOptions();
612612
UninitObjCheckerOptions &ChOpts = Chk->Opts;
613613

614614
ChOpts.IsPedantic = AnOpts.getCheckerBooleanOption(Chk, "Pedantic");

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class AnalysisConsumer : public AnalysisASTConsumer,
208208

209209
void Initialize(ASTContext &Context) override {
210210
Ctx = &Context;
211-
checkerMgr = std::make_unique<CheckerManager>(*Ctx, *Opts, Plugins,
211+
checkerMgr = std::make_unique<CheckerManager>(*Ctx, *Opts, PP, Plugins,
212212
CheckerRegistrationFns);
213213

214214
Mgr = std::make_unique<AnalysisManager>(*Ctx, PP, PathConsumers,

clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ namespace clang {
1818
namespace ento {
1919

2020
CheckerManager::CheckerManager(
21-
ASTContext &Context, AnalyzerOptions &AOptions,
21+
ASTContext &Context, AnalyzerOptions &AOptions, const Preprocessor &PP,
2222
ArrayRef<std::string> plugins,
2323
ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns)
2424
: Context(&Context), LangOpts(Context.getLangOpts()), AOptions(AOptions),
25-
Diags(Context.getDiagnostics()),
25+
PP(&PP), Diags(Context.getDiagnostics()),
2626
Registry(
2727
std::make_unique<CheckerRegistry>(plugins, Context.getDiagnostics(),
2828
AOptions, checkerRegistrationFns)) {
@@ -31,9 +31,6 @@ CheckerManager::CheckerManager(
3131
finishedCheckerRegistration();
3232
}
3333

34-
/// Constructs a CheckerManager without requiring an AST. No checker
35-
/// registration will take place. Only useful for retrieving the
36-
/// CheckerRegistry and print for help flags where the AST is unavalaible.
3734
CheckerManager::CheckerManager(AnalyzerOptions &AOptions,
3835
const LangOptions &LangOpts,
3936
DiagnosticsEngine &Diags,

clang/unittests/StaticAnalyzer/Reusables.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ class ExprEngineConsumer : public ASTConsumer {
5656

5757
public:
5858
ExprEngineConsumer(CompilerInstance &C)
59-
: C(C), ChkMgr(C.getASTContext(), *C.getAnalyzerOpts()), CTU(C),
60-
Consumers(),
59+
: C(C),
60+
ChkMgr(C.getASTContext(), *C.getAnalyzerOpts(), C.getPreprocessor()),
61+
CTU(C), Consumers(),
6162
AMgr(C.getASTContext(), C.getPreprocessor(), Consumers,
6263
CreateRegionStoreManager, CreateRangeConstraintManager, &ChkMgr,
6364
*C.getAnalyzerOpts()),

0 commit comments

Comments
 (0)