Skip to content

Commit 38ab3b8

Browse files
author
Charusso
committed
[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
1 parent fdc496a commit 38ab3b8

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
#include "clang/Analysis/PathDiagnostic.h"
1818
#include "clang/Basic/LLVM.h"
1919
#include "clang/Basic/SourceLocation.h"
20+
#include "clang/Lex/Preprocessor.h"
2021
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
2122
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
23+
#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
2224
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
2325
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
2426
#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
25-
#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
2627
#include "llvm/ADT/ArrayRef.h"
2728
#include "llvm/ADT/DenseSet.h"
2829
#include "llvm/ADT/FoldingSet.h"
@@ -566,6 +567,7 @@ class BugReporterData {
566567
virtual ASTContext &getASTContext() = 0;
567568
virtual SourceManager &getSourceManager() = 0;
568569
virtual AnalyzerOptions &getAnalyzerOptions() = 0;
570+
virtual Preprocessor &getPreprocessor() = 0;
569571
};
570572

571573
/// BugReporter is a utility class for generating PathDiagnostics for analysis.
@@ -608,6 +610,8 @@ class BugReporter {
608610

609611
const AnalyzerOptions &getAnalyzerOptions() { return D.getAnalyzerOptions(); }
610612

613+
Preprocessor &getPreprocessor() { return D.getPreprocessor(); }
614+
611615
/// Add the given report to the set of reports tracked by BugReporter.
612616
///
613617
/// The reports are usually generated by the checkers. Further, they are

clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "clang/Analysis/AnalysisDeclContext.h"
1818
#include "clang/Analysis/PathDiagnostic.h"
19+
#include "clang/Lex/Preprocessor.h"
1920
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
2021
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
2122
#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
@@ -32,6 +33,7 @@ class AnalysisManager : public BugReporterData {
3233
AnalysisDeclContextManager AnaCtxMgr;
3334

3435
ASTContext &Ctx;
36+
Preprocessor &PP;
3537
const LangOptions &LangOpts;
3638
PathDiagnosticConsumers PathConsumers;
3739

@@ -44,7 +46,7 @@ class AnalysisManager : public BugReporterData {
4446
public:
4547
AnalyzerOptions &options;
4648

47-
AnalysisManager(ASTContext &ctx,
49+
AnalysisManager(ASTContext &ctx, Preprocessor &PP,
4850
const PathDiagnosticConsumers &Consumers,
4951
StoreManagerCreator storemgr,
5052
ConstraintManagerCreator constraintmgr,
@@ -61,6 +63,8 @@ class AnalysisManager : public BugReporterData {
6163
return AnaCtxMgr;
6264
}
6365

66+
Preprocessor &getPreprocessor() override { return PP; }
67+
6468
StoreManagerCreator getStoreManagerCreator() {
6569
return CreateStoreMgr;
6670
}

clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class CheckerContext {
107107
return getBugReporter().getSourceManager();
108108
}
109109

110+
Preprocessor &getPreprocessor() { return getBugReporter().getPreprocessor(); }
111+
110112
SValBuilder &getSValBuilder() {
111113
return Eng.getSValBuilder();
112114
}

clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using namespace ento;
1313

1414
void AnalysisManager::anchor() { }
1515

16-
AnalysisManager::AnalysisManager(ASTContext &ASTCtx,
16+
AnalysisManager::AnalysisManager(ASTContext &ASTCtx, Preprocessor &PP,
1717
const PathDiagnosticConsumers &PDC,
1818
StoreManagerCreator storemgr,
1919
ConstraintManagerCreator constraintmgr,
@@ -38,7 +38,7 @@ AnalysisManager::AnalysisManager(ASTContext &ASTCtx,
3838
Options.ShouldElideConstructors,
3939
/*addVirtualBaseBranches=*/true,
4040
injector),
41-
Ctx(ASTCtx), LangOpts(ASTCtx.getLangOpts()),
41+
Ctx(ASTCtx), PP(PP), LangOpts(ASTCtx.getLangOpts()),
4242
PathConsumers(PDC), CreateStoreMgr(storemgr),
4343
CreateConstraintMgr(constraintmgr), CheckerMgr(checkerMgr),
4444
options(Options) {

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class AnalysisConsumer : public AnalysisASTConsumer,
193193

194194
public:
195195
ASTContext *Ctx;
196-
const Preprocessor &PP;
196+
Preprocessor &PP;
197197
const std::string OutDir;
198198
AnalyzerOptionsRef Opts;
199199
ArrayRef<std::string> Plugins;
@@ -336,8 +336,8 @@ class AnalysisConsumer : public AnalysisASTConsumer,
336336
checkerMgr = createCheckerManager(
337337
*Ctx, *Opts, Plugins, CheckerRegistrationFns, PP.getDiagnostics());
338338

339-
Mgr = std::make_unique<AnalysisManager>(*Ctx, PathConsumers, CreateStoreMgr,
340-
CreateConstraintMgr,
339+
Mgr = std::make_unique<AnalysisManager>(*Ctx, PP, PathConsumers,
340+
CreateStoreMgr, CreateConstraintMgr,
341341
checkerMgr.get(), *Opts, Injector);
342342
}
343343

clang/unittests/StaticAnalyzer/Reusables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ExprEngineConsumer : public ASTConsumer {
5858
ExprEngineConsumer(CompilerInstance &C)
5959
: C(C), ChkMgr(C.getASTContext(), *C.getAnalyzerOpts()), CTU(C),
6060
Consumers(),
61-
AMgr(C.getASTContext(), Consumers,
61+
AMgr(C.getASTContext(), C.getPreprocessor(), Consumers,
6262
CreateRegionStoreManager, CreateRangeConstraintManager, &ChkMgr,
6363
*C.getAnalyzerOpts()),
6464
VisitedCallees(), FS(),

0 commit comments

Comments
 (0)