Skip to content

Commit b9bd6eb

Browse files
committed
[analyzer][NFC] Refactoring BugReporter.cpp P1.: Store interesting symbols/regions in a simple set
The goal of this refactoring effort was to better understand how interestingness was propagated in BugReporter.cpp, which eventually turned out to be a dead end, but with such a twist, I wouldn't even want to spoil it ahead of time. However, I did get to learn a lot about how things are working in there. In these series of patches, as well as cleaning up the code big time, I invite you to study how BugReporter.cpp operates, and discuss how we could design this file to reduce the horrible mess that it is. This patch reverts a great part of rC162028, which holds the title "Allow multiple PathDiagnosticConsumers to be used with a BugReporter at the same time.". This, however doesn't imply that there's any need for multiple "layers" or stacks of interesting symbols and regions, quite the contrary, I would argue that we would like to generate the same amount of information for all output types, and only process them differently. Differential Revision: https://reviews.llvm.org/D65378 llvm-svn: 368689
1 parent 7f7b296 commit b9bd6eb

File tree

2 files changed

+12
-64
lines changed

2 files changed

+12
-64
lines changed

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,19 @@ class BugReport : public llvm::ilist_node<BugReport> {
107107
ExtraTextList ExtraText;
108108
NoteList Notes;
109109

110-
using Symbols = llvm::DenseSet<SymbolRef>;
111-
using Regions = llvm::DenseSet<const MemRegion *>;
112-
113110
/// A (stack of) a set of symbols that are registered with this
114111
/// report as being "interesting", and thus used to help decide which
115112
/// diagnostics to include when constructing the final path diagnostic.
116113
/// The stack is largely used by BugReporter when generating PathDiagnostics
117114
/// for multiple PathDiagnosticConsumers.
118-
SmallVector<Symbols *, 2> interestingSymbols;
115+
llvm::DenseSet<SymbolRef> InterestingSymbols;
119116

120117
/// A (stack of) set of regions that are registered with this report as being
121118
/// "interesting", and thus used to help decide which diagnostics
122119
/// to include when constructing the final path diagnostic.
123120
/// The stack is largely used by BugReporter when generating PathDiagnostics
124121
/// for multiple PathDiagnosticConsumers.
125-
SmallVector<Regions *, 2> interestingRegions;
122+
llvm::DenseSet<const MemRegion *> InterestingRegions;
126123

127124
/// A set of location contexts that correspoind to call sites which should be
128125
/// considered "interesting".
@@ -156,15 +153,6 @@ class BugReport : public llvm::ilist_node<BugReport> {
156153
/// Conditions we're already tracking.
157154
llvm::SmallSet<const ExplodedNode *, 4> TrackedConditions;
158155

159-
private:
160-
// Used internally by BugReporter.
161-
Symbols &getInterestingSymbols();
162-
Regions &getInterestingRegions();
163-
164-
void lazyInitializeInterestingSets();
165-
void pushInterestingSymbolsAndRegions();
166-
void popInterestingSymbolsAndRegions();
167-
168156
public:
169157
BugReport(const BugType& bt, StringRef desc, const ExplodedNode *errornode)
170158
: BT(bt), Description(desc), ErrorNode(errornode) {}
@@ -189,7 +177,7 @@ class BugReport : public llvm::ilist_node<BugReport> {
189177
: BT(bt), Description(desc), UniqueingLocation(LocationToUnique),
190178
UniqueingDecl(DeclToUnique), ErrorNode(errornode) {}
191179

192-
virtual ~BugReport();
180+
virtual ~BugReport() = default;
193181

194182
const BugType& getBugType() const { return BT; }
195183
//BugType& getBugType() { return BT; }
@@ -381,7 +369,6 @@ class BugReportEquivClass : public llvm::FoldingSetNode {
381369

382370
public:
383371
BugReportEquivClass(std::unique_ptr<BugReport> R) { AddReport(std::move(R)); }
384-
~BugReportEquivClass();
385372

386373
void Profile(llvm::FoldingSetNodeID& ID) const {
387374
assert(!Reports.empty());
@@ -404,7 +391,7 @@ class BugReportEquivClass : public llvm::FoldingSetNode {
404391

405392
class BugReporterData {
406393
public:
407-
virtual ~BugReporterData();
394+
virtual ~BugReporterData() = default;
408395

409396
virtual DiagnosticsEngine& getDiagnostic() = 0;
410397
virtual ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() = 0;
@@ -526,7 +513,7 @@ class GRBugReporter : public BugReporter {
526513
GRBugReporter(BugReporterData& d, ExprEngine& eng)
527514
: BugReporter(d, GRBugReporterKind), Eng(eng) {}
528515

529-
~GRBugReporter() override;
516+
~GRBugReporter() override = default;;
530517

531518
/// getGraph - Get the exploded graph created by the analysis engine
532519
/// for the analyzed method or function.

clang/lib/StaticAnalyzer/Core/BugReporter.cpp

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,12 +2058,6 @@ void BugReport::clearVisitors() {
20582058
Callbacks.clear();
20592059
}
20602060

2061-
BugReport::~BugReport() {
2062-
while (!interestingSymbols.empty()) {
2063-
popInterestingSymbolsAndRegions();
2064-
}
2065-
}
2066-
20672061
const Decl *BugReport::getDeclWithIssue() const {
20682062
if (DeclWithIssue)
20692063
return DeclWithIssue;
@@ -2101,21 +2095,21 @@ void BugReport::markInteresting(SymbolRef sym) {
21012095
if (!sym)
21022096
return;
21032097

2104-
getInterestingSymbols().insert(sym);
2098+
InterestingSymbols.insert(sym);
21052099

21062100
if (const auto *meta = dyn_cast<SymbolMetadata>(sym))
2107-
getInterestingRegions().insert(meta->getRegion());
2101+
InterestingRegions.insert(meta->getRegion());
21082102
}
21092103

21102104
void BugReport::markInteresting(const MemRegion *R) {
21112105
if (!R)
21122106
return;
21132107

21142108
R = R->getBaseRegion();
2115-
getInterestingRegions().insert(R);
2109+
InterestingRegions.insert(R);
21162110

21172111
if (const auto *SR = dyn_cast<SymbolicRegion>(R))
2118-
getInterestingSymbols().insert(SR->getSymbol());
2112+
InterestingSymbols.insert(SR->getSymbol());
21192113
}
21202114

21212115
void BugReport::markInteresting(SVal V) {
@@ -2138,18 +2132,18 @@ bool BugReport::isInteresting(SymbolRef sym) {
21382132
return false;
21392133
// We don't currently consider metadata symbols to be interesting
21402134
// even if we know their region is interesting. Is that correct behavior?
2141-
return getInterestingSymbols().count(sym);
2135+
return InterestingSymbols.count(sym);
21422136
}
21432137

21442138
bool BugReport::isInteresting(const MemRegion *R) {
21452139
if (!R)
21462140
return false;
21472141
R = R->getBaseRegion();
2148-
bool b = getInterestingRegions().count(R);
2142+
bool b = InterestingRegions.count(R);
21492143
if (b)
21502144
return true;
21512145
if (const auto *SR = dyn_cast<SymbolicRegion>(R))
2152-
return getInterestingSymbols().count(SR->getSymbol());
2146+
return InterestingSymbols.count(SR->getSymbol());
21532147
return false;
21542148
}
21552149

@@ -2159,33 +2153,6 @@ bool BugReport::isInteresting(const LocationContext *LC) {
21592153
return InterestingLocationContexts.count(LC);
21602154
}
21612155

2162-
void BugReport::lazyInitializeInterestingSets() {
2163-
if (interestingSymbols.empty()) {
2164-
interestingSymbols.push_back(new Symbols());
2165-
interestingRegions.push_back(new Regions());
2166-
}
2167-
}
2168-
2169-
BugReport::Symbols &BugReport::getInterestingSymbols() {
2170-
lazyInitializeInterestingSets();
2171-
return *interestingSymbols.back();
2172-
}
2173-
2174-
BugReport::Regions &BugReport::getInterestingRegions() {
2175-
lazyInitializeInterestingSets();
2176-
return *interestingRegions.back();
2177-
}
2178-
2179-
void BugReport::pushInterestingSymbolsAndRegions() {
2180-
interestingSymbols.push_back(new Symbols(getInterestingSymbols()));
2181-
interestingRegions.push_back(new Regions(getInterestingRegions()));
2182-
}
2183-
2184-
void BugReport::popInterestingSymbolsAndRegions() {
2185-
delete interestingSymbols.pop_back_val();
2186-
delete interestingRegions.pop_back_val();
2187-
}
2188-
21892156
const Stmt *BugReport::getStmt() const {
21902157
if (!ErrorNode)
21912158
return nullptr;
@@ -2236,12 +2203,6 @@ PathDiagnosticLocation BugReport::getLocation(const SourceManager &SM) const {
22362203
// Methods for BugReporter and subclasses.
22372204
//===----------------------------------------------------------------------===//
22382205

2239-
BugReportEquivClass::~BugReportEquivClass() = default;
2240-
2241-
GRBugReporter::~GRBugReporter() = default;
2242-
2243-
BugReporterData::~BugReporterData() = default;
2244-
22452206
ExplodedGraph &GRBugReporter::getGraph() { return Eng.getGraph(); }
22462207

22472208
ProgramStateManager&

0 commit comments

Comments
 (0)