Skip to content

Commit decdf63

Browse files
committed
[analyzer] NFC: Simplify bug report equivalence classes to not be ilists.
Use a vector of unique pointers instead. Differential Revision: https://reviews.llvm.org/D67024 llvm-svn: 371451 (cherry picked from commit 589273b)
1 parent 9dbd22a commit decdf63

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ using DiagnosticForConsumerMapTy =
7272

7373
/// This class provides an interface through which checkers can create
7474
/// individual bug reports.
75-
class BugReport : public llvm::ilist_node<BugReport> {
75+
class BugReport {
7676
public:
7777
enum class Kind { Basic, PathSensitive };
7878

@@ -465,28 +465,21 @@ class BugReportEquivClass : public llvm::FoldingSetNode {
465465
friend class BugReporter;
466466

467467
/// List of *owned* BugReport objects.
468-
llvm::ilist<BugReport> Reports;
468+
llvm::SmallVector<std::unique_ptr<BugReport>, 4> Reports;
469469

470-
void AddReport(std::unique_ptr<BugReport> R) {
471-
Reports.push_back(R.release());
470+
void AddReport(std::unique_ptr<BugReport> &&R) {
471+
Reports.push_back(std::move(R));
472472
}
473473

474474
public:
475475
BugReportEquivClass(std::unique_ptr<BugReport> R) { AddReport(std::move(R)); }
476476

477+
ArrayRef<std::unique_ptr<BugReport>> getReports() const { return Reports; }
478+
477479
void Profile(llvm::FoldingSetNodeID& ID) const {
478480
assert(!Reports.empty());
479-
Reports.front().Profile(ID);
481+
Reports.front()->Profile(ID);
480482
}
481-
482-
using iterator = llvm::ilist<BugReport>::iterator;
483-
using const_iterator = llvm::ilist<BugReport>::const_iterator;
484-
485-
iterator begin() { return Reports.begin(); }
486-
iterator end() { return Reports.end(); }
487-
488-
const_iterator begin() const { return Reports.begin(); }
489-
const_iterator end() const { return Reports.end(); }
490483
};
491484

492485
//===----------------------------------------------------------------------===//
@@ -573,7 +566,7 @@ class BugReporter {
573566
virtual BugReport *
574567
findReportInEquivalenceClass(BugReportEquivClass &eqClass,
575568
SmallVectorImpl<BugReport *> &bugReports) {
576-
return &*eqClass.begin();
569+
return eqClass.getReports()[0].get();
577570
}
578571

579572
protected:

clang/lib/StaticAnalyzer/Core/BugReporter.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,17 +2796,15 @@ struct FRIEC_WLItem {
27962796

27972797
BugReport *PathSensitiveBugReporter::findReportInEquivalenceClass(
27982798
BugReportEquivClass &EQ, SmallVectorImpl<BugReport *> &bugReports) {
2799-
BugReportEquivClass::iterator I = EQ.begin(), E = EQ.end();
2800-
assert(I != E);
2801-
const BugType& BT = I->getBugType();
2802-
28032799
// If we don't need to suppress any of the nodes because they are
28042800
// post-dominated by a sink, simply add all the nodes in the equivalence class
28052801
// to 'Nodes'. Any of the reports will serve as a "representative" report.
2802+
assert(EQ.getReports().size() > 0);
2803+
const BugType& BT = EQ.getReports()[0]->getBugType();
28062804
if (!BT.isSuppressOnSink()) {
2807-
BugReport *R = &*I;
2808-
for (auto &I : EQ) {
2809-
if (auto *PR = dyn_cast<PathSensitiveBugReport>(&I)) {
2805+
BugReport *R = EQ.getReports()[0].get();
2806+
for (auto &J : EQ.getReports()) {
2807+
if (auto *PR = dyn_cast<PathSensitiveBugReport>(J.get())) {
28102808
R = PR;
28112809
bugReports.push_back(PR);
28122810
}
@@ -2822,8 +2820,8 @@ BugReport *PathSensitiveBugReporter::findReportInEquivalenceClass(
28222820
// stack for very long paths.
28232821
BugReport *exampleReport = nullptr;
28242822

2825-
for (; I != E; ++I) {
2826-
auto *R = dyn_cast<PathSensitiveBugReport>(&*I);
2823+
for (const auto &I: EQ.getReports()) {
2824+
auto *R = dyn_cast<PathSensitiveBugReport>(I.get());
28272825
if (!R)
28282826
continue;
28292827

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,8 +3003,8 @@ struct DOTGraphTraits<ExplodedGraph*> : public DefaultDOTGraphTraits {
30033003
llvm::make_range(BR.EQClasses_begin(), BR.EQClasses_end());
30043004

30053005
for (const auto &EQ : EQClasses) {
3006-
for (const BugReport &R : EQ) {
3007-
const auto *PR = dyn_cast<PathSensitiveBugReport>(&R);
3006+
for (const auto &I : EQ.getReports()) {
3007+
const auto *PR = dyn_cast<PathSensitiveBugReport>(I.get());
30083008
if (!PR)
30093009
continue;
30103010
const ExplodedNode *EN = PR->getErrorNode();
@@ -3134,7 +3134,8 @@ std::string ExprEngine::DumpGraph(bool trim, StringRef Filename) {
31343134
// Iterate through the reports and get their nodes.
31353135
for (BugReporter::EQClasses_iterator
31363136
EI = BR.EQClasses_begin(), EE = BR.EQClasses_end(); EI != EE; ++EI) {
3137-
const auto *R = dyn_cast<PathSensitiveBugReport>(&*EI->begin());
3137+
const auto *R =
3138+
dyn_cast<PathSensitiveBugReport>(EI->getReports()[0].get());
31383139
if (!R)
31393140
continue;
31403141
const auto *N = const_cast<ExplodedNode *>(R->getErrorNode());

0 commit comments

Comments
 (0)