NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a_sidorin, rnkovacs, Szelethus, 
baloghadamsoftware, Charusso.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, szepet, dylanmckay.
Herald added a project: clang.

They are said to be more efficient and they're definitely less brain-damaging. 
Suggested <https://reviews.llvm.org/D66572?id=216706#inline-598709> by 
@gribozavr.


Repository:
  rC Clang

https://reviews.llvm.org/D67024

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3004,8 +3004,8 @@
         llvm::make_range(BR.EQClasses_begin(), BR.EQClasses_end());
 
     for (const auto &EQ : EQClasses) {
-      for (const BugReport &R : EQ) {
-        const auto *PR = dyn_cast<PathSensitiveBugReport>(&R);
+      for (const auto &I : EQ) {
+        const auto *PR = dyn_cast<PathSensitiveBugReport>(I.get());
         if (!PR)
           continue;
         const ExplodedNode *EN = PR->getErrorNode();
@@ -3135,7 +3135,7 @@
     // Iterate through the reports and get their nodes.
     for (BugReporter::EQClasses_iterator
            EI = BR.EQClasses_begin(), EE = BR.EQClasses_end(); EI != EE; ++EI) {
-      const auto *R = dyn_cast<PathSensitiveBugReport>(&*EI->begin());
+      const auto *R = dyn_cast<PathSensitiveBugReport>(EI->begin()->get());
       if (!R)
         continue;
       const auto *N = const_cast<ExplodedNode *>(R->getErrorNode());
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -2800,17 +2800,17 @@
 
 BugReport *PathSensitiveBugReporter::findReportInEquivalenceClass(
     BugReportEquivClass &EQ, SmallVectorImpl<BugReport *> &bugReports) {
-  BugReportEquivClass::iterator I = EQ.begin(), E = EQ.end();
+  auto I = EQ.begin(), E = EQ.end();
   assert(I != E);
-  const BugType& BT = I->getBugType();
+  const BugType& BT = (*I)->getBugType();
 
   // If we don't need to suppress any of the nodes because they are
   // post-dominated by a sink, simply add all the nodes in the equivalence class
   // to 'Nodes'.  Any of the reports will serve as a "representative" report.
   if (!BT.isSuppressOnSink()) {
-    BugReport *R = &*I;
-    for (auto &I : EQ) {
-      if (auto *PR = dyn_cast<PathSensitiveBugReport>(&I)) {
+    BugReport *R = I->get();
+    for (auto &J : EQ) {
+      if (auto *PR = dyn_cast<PathSensitiveBugReport>(J.get())) {
         R = PR;
         bugReports.push_back(PR);
       }
@@ -2827,7 +2827,7 @@
   BugReport *exampleReport = nullptr;
 
   for (; I != E; ++I) {
-    auto *R = dyn_cast<PathSensitiveBugReport>(&*I);
+    auto *R = dyn_cast<PathSensitiveBugReport>(I->get());
     if (!R)
       continue;
 
Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -72,7 +72,7 @@
 
 /// This class provides an interface through which checkers can create
 /// individual bug reports.
-class BugReport : public llvm::ilist_node<BugReport> {
+class BugReport {
 public:
   using ranges_iterator = const SourceRange *;
   using NoteList = SmallVector<std::shared_ptr<PathDiagnosticNotePiece>, 4>;
@@ -454,11 +454,18 @@
 class BugReportEquivClass : public llvm::FoldingSetNode {
   friend class BugReporter;
 
+public:
+  typedef llvm::SmallVector<std::unique_ptr<BugReport>, 4> ReportList;
+  using iterator = ReportList::iterator;
+  using const_iterator = ReportList::const_iterator;
+
+
+private:
   /// List of *owned* BugReport objects.
-  llvm::ilist<BugReport> Reports;
+  ReportList Reports;
 
-  void AddReport(std::unique_ptr<BugReport> R) {
-    Reports.push_back(R.release());
+  void AddReport(std::unique_ptr<BugReport> &&R) {
+    Reports.push_back(std::move(R));
   }
 
 public:
@@ -466,12 +473,9 @@
 
   void Profile(llvm::FoldingSetNodeID& ID) const {
     assert(!Reports.empty());
-    Reports.front().Profile(ID);
+    Reports.front()->Profile(ID);
   }
 
-  using iterator = llvm::ilist<BugReport>::iterator;
-  using const_iterator = llvm::ilist<BugReport>::const_iterator;
-
   iterator begin() { return Reports.begin(); }
   iterator end() { return Reports.end(); }
 
@@ -563,7 +567,7 @@
   virtual BugReport *
   findReportInEquivalenceClass(BugReportEquivClass &eqClass,
                                SmallVectorImpl<BugReport *> &bugReports) {
-    return &*eqClass.begin();
+    return eqClass.begin()->get();
   }
 
 protected:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to