Skip to content

Commit 6b9d7c9

Browse files
committed
Removed some dead code in BugReporter and related files
Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66473 llvm-svn: 369504
1 parent 9cb3179 commit 6b9d7c9

File tree

10 files changed

+13
-143
lines changed

10 files changed

+13
-143
lines changed

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

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,6 @@ using DiagnosticForConsumerMapTy =
7474
/// individual bug reports.
7575
class BugReport : public llvm::ilist_node<BugReport> {
7676
public:
77-
class NodeResolver {
78-
virtual void anchor();
79-
80-
public:
81-
virtual ~NodeResolver() = default;
82-
83-
virtual const ExplodedNode*
84-
getOriginalNode(const ExplodedNode *N) = 0;
85-
};
86-
8777
using ranges_iterator = const SourceRange *;
8878
using VisitorList = SmallVector<std::unique_ptr<BugReporterVisitor>, 8>;
8979
using visitor_iterator = VisitorList::iterator;
@@ -391,7 +381,6 @@ class BugReporterData {
391381
public:
392382
virtual ~BugReporterData() = default;
393383

394-
virtual DiagnosticsEngine& getDiagnostic() = 0;
395384
virtual ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() = 0;
396385
virtual ASTContext &getASTContext() = 0;
397386
virtual SourceManager &getSourceManager() = 0;
@@ -404,11 +393,7 @@ class BugReporterData {
404393
///
405394
/// The base class is used for generating path-insensitive
406395
class BugReporter {
407-
public:
408-
enum Kind { BasicBRKind, PathSensitiveBRKind };
409-
410396
private:
411-
const Kind kind;
412397
BugReporterData& D;
413398

414399
/// Generate and flush the diagnostics for the given bug report.
@@ -426,23 +411,13 @@ class BugReporter {
426411
/// A vector of BugReports for tracking the allocated pointers and cleanup.
427412
std::vector<BugReportEquivClass *> EQClassesVector;
428413

429-
protected:
430-
BugReporter(BugReporterData& d, Kind k)
431-
: kind(k), D(d) {}
432-
433414
public:
434-
BugReporter(BugReporterData &d) : kind(BasicBRKind), D(d) {}
415+
BugReporter(BugReporterData &d) : D(d) {}
435416
virtual ~BugReporter();
436417

437418
/// Generate and flush diagnostics for all bug reports.
438419
void FlushReports();
439420

440-
Kind getKind() const { return kind; }
441-
442-
DiagnosticsEngine& getDiagnostic() {
443-
return D.getDiagnostic();
444-
}
445-
446421
ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() {
447422
return D.getPathDiagnosticConsumers();
448423
}
@@ -496,16 +471,14 @@ class PathSensitiveBugReporter : public BugReporter {
496471

497472
public:
498473
PathSensitiveBugReporter(BugReporterData& d, ExprEngine& eng)
499-
: BugReporter(d, PathSensitiveBRKind), Eng(eng) {}
474+
: BugReporter(d), Eng(eng) {}
500475

501476
/// getGraph - Get the exploded graph created by the analysis engine
502477
/// for the analyzed method or function.
503478
const ExplodedGraph &getGraph() const;
504479

505480
/// getStateManager - Return the state manager used by the analysis
506481
/// engine.
507-
ProgramStateManager &getStateManager();
508-
509482
ProgramStateManager &getStateManager() const;
510483

511484
/// \p bugReports A set of bug reports within a *single* equivalence class
@@ -516,50 +489,25 @@ class PathSensitiveBugReporter : public BugReporter {
516489
std::unique_ptr<DiagnosticForConsumerMapTy>
517490
generatePathDiagnostics(ArrayRef<PathDiagnosticConsumer *> consumers,
518491
ArrayRef<BugReport *> &bugReports) override;
519-
520-
/// classof - Used by isa<>, cast<>, and dyn_cast<>.
521-
static bool classof(const BugReporter* R) {
522-
return R->getKind() == PathSensitiveBRKind;
523-
}
524492
};
525493

526494

527-
class NodeMapClosure : public BugReport::NodeResolver {
528-
InterExplodedGraphMap &M;
529-
530-
public:
531-
NodeMapClosure(InterExplodedGraphMap &m) : M(m) {}
532-
533-
const ExplodedNode *getOriginalNode(const ExplodedNode *N) override {
534-
return M.lookup(N);
535-
}
536-
};
537-
538495
class BugReporterContext {
539496
PathSensitiveBugReporter &BR;
540-
NodeMapClosure NMC;
541497

542498
virtual void anchor();
543499

544500
public:
545-
BugReporterContext(PathSensitiveBugReporter &br,
546-
InterExplodedGraphMap &Backmap)
547-
: BR(br), NMC(Backmap) {}
501+
BugReporterContext(PathSensitiveBugReporter &br) : BR(br) {}
548502

549503
virtual ~BugReporterContext() = default;
550504

551505
PathSensitiveBugReporter& getBugReporter() { return BR; }
552506

553-
const ExplodedGraph &getGraph() const { return BR.getGraph(); }
554-
555507
ProgramStateManager& getStateManager() const {
556508
return BR.getStateManager();
557509
}
558510

559-
SValBuilder &getSValBuilder() const {
560-
return getStateManager().getSValBuilder();
561-
}
562-
563511
ASTContext &getASTContext() const {
564512
return BR.getContext();
565513
}
@@ -571,8 +519,6 @@ class BugReporterContext {
571519
const AnalyzerOptions &getAnalyzerOptions() const {
572520
return BR.getAnalyzerOptions();
573521
}
574-
575-
NodeMapClosure& getNodeResolver() { return NMC; }
576522
};
577523

578524

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ class FindLastStoreBRVisitor final : public BugReporterVisitor {
135135
const StackFrameContext *OriginSFC;
136136

137137
public:
138-
/// Creates a visitor for every VarDecl inside a Stmt and registers it with
139-
/// the BugReport.
140-
static void registerStatementVarDecls(BugReport &BR, const Stmt *S,
141-
bool EnableNullFPSuppression,
142-
TrackingKind TKind);
143-
144138
/// \param V We're searching for the store where \c R received this value.
145139
/// \param R The region we're tracking.
146140
/// \param TKind May limit the amount of notes added to the bug report.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,6 @@ class PathDiagnosticMacroPiece : public PathDiagnosticSpotPiece {
735735

736736
PathPieces subPieces;
737737

738-
bool containsEvent() const;
739-
740738
void flattenLocations() override {
741739
PathDiagnosticSpotPiece::flattenLocations();
742740
for (const auto &I : subPieces)

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class AnalysisManager : public BugReporterData {
3232
AnalysisDeclContextManager AnaCtxMgr;
3333

3434
ASTContext &Ctx;
35-
DiagnosticsEngine &Diags;
3635
const LangOptions &LangOpts;
3736
PathDiagnosticConsumers PathConsumers;
3837

@@ -45,7 +44,7 @@ class AnalysisManager : public BugReporterData {
4544
public:
4645
AnalyzerOptions &options;
4746

48-
AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
47+
AnalysisManager(ASTContext &ctx,
4948
const PathDiagnosticConsumers &Consumers,
5049
StoreManagerCreator storemgr,
5150
ConstraintManagerCreator constraintmgr,
@@ -84,10 +83,6 @@ class AnalysisManager : public BugReporterData {
8483
return getASTContext().getSourceManager();
8584
}
8685

87-
DiagnosticsEngine &getDiagnostic() override {
88-
return Diags;
89-
}
90-
9186
const LangOptions &getLangOpts() const {
9287
return LangOpts;
9388
}

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

clang/lib/StaticAnalyzer/Core/BugReporter.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,8 +2049,6 @@ void BuiltinBug::anchor() {}
20492049
// Methods for BugReport and subclasses.
20502050
//===----------------------------------------------------------------------===//
20512051

2052-
void BugReport::NodeResolver::anchor() {}
2053-
20542052
void BugReport::addVisitor(std::unique_ptr<BugReporterVisitor> visitor) {
20552053
if (!visitor)
20562054
return;
@@ -2218,10 +2216,6 @@ const ExplodedGraph &PathSensitiveBugReporter::getGraph() const {
22182216
return Eng.getGraph();
22192217
}
22202218

2221-
ProgramStateManager &PathSensitiveBugReporter::getStateManager() {
2222-
return Eng.getStateManager();
2223-
}
2224-
22252219
ProgramStateManager &PathSensitiveBugReporter::getStateManager() const {
22262220
return Eng.getStateManager();
22272221
}
@@ -2256,11 +2250,9 @@ void BugReporter::FlushReports() {
22562250
namespace {
22572251

22582252
/// A wrapper around an ExplodedGraph that contains a single path from the root
2259-
/// to the error node, and a map that maps the nodes in this path to the ones in
2260-
/// the original ExplodedGraph.
2253+
/// to the error node.
22612254
class BugPathInfo {
22622255
public:
2263-
InterExplodedGraphMap MapToOriginNodes;
22642256
std::unique_ptr<ExplodedGraph> BugPath;
22652257
BugReport *Report;
22662258
const ExplodedNode *ErrorNode;
@@ -2271,9 +2263,6 @@ class BugPathInfo {
22712263
class BugPathGetter {
22722264
std::unique_ptr<ExplodedGraph> TrimmedGraph;
22732265

2274-
/// Map from the trimmed graph to the original.
2275-
InterExplodedGraphMap InverseMap;
2276-
22772266
using PriorityMapTy = llvm::DenseMap<const ExplodedNode *, unsigned>;
22782267

22792268
/// Assign each node with its distance from the root.
@@ -2336,7 +2325,7 @@ BugPathGetter::BugPathGetter(const ExplodedGraph *OriginalGraph,
23362325
// The trimmed graph is created in the body of the constructor to ensure
23372326
// that the DenseMaps have been initialized already.
23382327
InterExplodedGraphMap ForwardMap;
2339-
TrimmedGraph = OriginalGraph->trim(Nodes, &ForwardMap, &InverseMap);
2328+
TrimmedGraph = OriginalGraph->trim(Nodes, &ForwardMap);
23402329

23412330
// Find the (first) error node in the trimmed graph. We just need to consult
23422331
// the node map which maps from nodes in the original graph to nodes
@@ -2399,7 +2388,6 @@ BugPathInfo *BugPathGetter::getNextBugPath() {
23992388
// Create a new graph with a single path. This is the graph that will be
24002389
// returned to the caller.
24012390
auto GNew = std::make_unique<ExplodedGraph>();
2402-
CurrentBugPath.MapToOriginNodes.clear();
24032391

24042392
// Now walk from the error node up the BFS path, always taking the
24052393
// predeccessor with the lowest number.
@@ -2410,11 +2398,6 @@ BugPathInfo *BugPathGetter::getNextBugPath() {
24102398
ExplodedNode *NewN = GNew->createUncachedNode(
24112399
OrigN->getLocation(), OrigN->getState(), OrigN->isSink());
24122400

2413-
// Store the mapping to the original node.
2414-
InterExplodedGraphMap::const_iterator IMitr = InverseMap.find(OrigN);
2415-
assert(IMitr != InverseMap.end() && "No mapping to original node.");
2416-
CurrentBugPath.MapToOriginNodes[NewN] = IMitr->second;
2417-
24182401
// Link up the new node with the previous node.
24192402
if (Succ)
24202403
Succ->addPredecessor(NewN, *GNew);
@@ -2613,7 +2596,7 @@ PathDiagnosticBuilder::findValidReport(ArrayRef<BugReport *> &bugReports,
26132596
R->addVisitor(std::make_unique<ConditionBRVisitor>());
26142597
R->addVisitor(std::make_unique<TagVisitor>());
26152598

2616-
BugReporterContext BRC(Reporter, BugPath->MapToOriginNodes);
2599+
BugReporterContext BRC(Reporter);
26172600

26182601
// Run all visitors on a given graph, once.
26192602
std::unique_ptr<VisitorsDiagnosticsTy> visitorNotes =

clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,41 +1166,6 @@ void FindLastStoreBRVisitor::Profile(llvm::FoldingSetNodeID &ID) const {
11661166
ID.AddBoolean(EnableNullFPSuppression);
11671167
}
11681168

1169-
void FindLastStoreBRVisitor::registerStatementVarDecls(
1170-
BugReport &BR, const Stmt *S, bool EnableNullFPSuppression,
1171-
TrackingKind TKind) {
1172-
1173-
const ExplodedNode *N = BR.getErrorNode();
1174-
std::deque<const Stmt *> WorkList;
1175-
WorkList.push_back(S);
1176-
1177-
while (!WorkList.empty()) {
1178-
const Stmt *Head = WorkList.front();
1179-
WorkList.pop_front();
1180-
1181-
ProgramStateManager &StateMgr = N->getState()->getStateManager();
1182-
1183-
if (const auto *DR = dyn_cast<DeclRefExpr>(Head)) {
1184-
if (const auto *VD = dyn_cast<VarDecl>(DR->getDecl())) {
1185-
const VarRegion *R =
1186-
StateMgr.getRegionManager().getVarRegion(VD, N->getLocationContext());
1187-
1188-
// What did we load?
1189-
SVal V = N->getSVal(S);
1190-
1191-
if (V.getAs<loc::ConcreteInt>() || V.getAs<nonloc::ConcreteInt>()) {
1192-
// Register a new visitor with the BugReport.
1193-
BR.addVisitor(std::make_unique<FindLastStoreBRVisitor>(
1194-
V.castAs<KnownSVal>(), R, EnableNullFPSuppression, TKind));
1195-
}
1196-
}
1197-
}
1198-
1199-
for (const Stmt *SubStmt : Head->children())
1200-
WorkList.push_back(SubStmt);
1201-
}
1202-
}
1203-
12041169
/// Returns true if \p N represents the DeclStmt declaring and initializing
12051170
/// \p VR.
12061171
static bool isInitializationOfVar(const ExplodedNode *N, const VarRegion *VR) {

clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@
5353
using namespace clang;
5454
using namespace ento;
5555

56-
bool PathDiagnosticMacroPiece::containsEvent() const {
57-
for (const auto &P : subPieces) {
58-
if (isa<PathDiagnosticEventPiece>(*P))
59-
return true;
60-
if (const auto *MP = dyn_cast<PathDiagnosticMacroPiece>(P.get()))
61-
if (MP->containsEvent())
62-
return true;
63-
}
64-
return false;
65-
}
66-
6756
static StringRef StripTrailingDots(StringRef s) {
6857
for (StringRef::size_type i = s.size(); i != 0; --i)
6958
if (s[i - 1] != '.')

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ class AnalysisConsumer : public AnalysisASTConsumer,
311311
checkerMgr = createCheckerManager(
312312
*Ctx, *Opts, Plugins, CheckerRegistrationFns, PP.getDiagnostics());
313313

314-
Mgr = std::make_unique<AnalysisManager>(
315-
*Ctx, PP.getDiagnostics(), PathConsumers, CreateStoreMgr,
316-
CreateConstraintMgr, checkerMgr.get(), *Opts, Injector);
314+
Mgr = std::make_unique<AnalysisManager>(*Ctx, PathConsumers, CreateStoreMgr,
315+
CreateConstraintMgr,
316+
checkerMgr.get(), *Opts, Injector);
317317
}
318318

319319
/// Store the top level decls in the set to be processed later on.

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(), C.getDiagnostics(), Consumers,
61+
AMgr(C.getASTContext(), Consumers,
6262
CreateRegionStoreManager, CreateRangeConstraintManager, &ChkMgr,
6363
*C.getAnalyzerOpts()),
6464
VisitedCallees(), FS(),

0 commit comments

Comments
 (0)