saugustine created this revision.
saugustine added reviewers: echristo, Szelethus, martong.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, dkrupp, 
donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a project: clang.

This reverts commit 33fb9cbe211d1b43d4b84edf34e11001f04cddf0 
<https://reviews.llvm.org/rG33fb9cbe211d1b43d4b84edf34e11001f04cddf0>.

That commit violates layering by adding a dependency from StaticAnalyzer/Core
back to StaticAnalyzer/FrontEnd, creating a circular dependency.

I can't see a clean way to fix it except refactoring.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81752

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

Index: clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -94,10 +94,6 @@
 // Methods of CmdLineOption, PackageInfo and CheckerInfo.
 //===----------------------------------------------------------------------===//
 
-LLVM_DUMP_METHOD void CheckerRegistry::CmdLineOption::dump() const {
-  dumpToStream(llvm::errs());
-}
-
 LLVM_DUMP_METHOD void
 CheckerRegistry::CmdLineOption::dumpToStream(llvm::raw_ostream &Out) const {
   // The description can be just checked in Checkers.inc, the point here is to
@@ -119,10 +115,6 @@
   llvm_unreachable("Unhandled CheckerRegistry::StateFromCmdLine enum");
 }
 
-LLVM_DUMP_METHOD void CheckerRegistry::CheckerInfo::dump() const {
-  dumpToStream(llvm::errs());
-}
-
 LLVM_DUMP_METHOD void
 CheckerRegistry::CheckerInfo::dumpToStream(llvm::raw_ostream &Out) const {
   // The description can be just checked in Checkers.inc, the point here is to
@@ -145,10 +137,6 @@
   }
 }
 
-LLVM_DUMP_METHOD void CheckerRegistry::PackageInfo::dump() const {
-  dumpToStream(llvm::errs());
-}
-
 LLVM_DUMP_METHOD void
 CheckerRegistry::PackageInfo::dumpToStream(llvm::raw_ostream &Out) const {
   Out << FullName << "\n";
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -40,7 +40,6 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
-#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
@@ -2107,32 +2106,6 @@
 // Methods for BugReport and subclasses.
 //===----------------------------------------------------------------------===//
 
-static bool isDependency(const CheckerRegistry &Registry,
-                         StringRef CheckerName) {
-  for (const std::pair<StringRef, StringRef> &Pair : Registry.Dependencies) {
-    if (Pair.second == CheckerName)
-      return true;
-  }
-  return false;
-}
-
-PathSensitiveBugReport::PathSensitiveBugReport(
-    const BugType &bt, StringRef shortDesc, StringRef desc,
-    const ExplodedNode *errorNode, PathDiagnosticLocation LocationToUnique,
-    const Decl *DeclToUnique)
-    : BugReport(Kind::PathSensitive, bt, shortDesc, desc), ErrorNode(errorNode),
-      ErrorNodeRange(getStmt() ? getStmt()->getSourceRange() : SourceRange()),
-      UniqueingLocation(LocationToUnique), UniqueingDecl(DeclToUnique) {
-  assert(!isDependency(ErrorNode->getState()
-                           ->getAnalysisManager()
-                           .getCheckerManager()
-                           ->getCheckerRegistry(),
-                       bt.getCheckerName()) &&
-         "Some checkers depend on this one! We don't allow dependency "
-         "checkers to emit warnings, because checkers should depend on "
-         "*modeling*, not *diagnostics*.");
-}
-
 void PathSensitiveBugReport::addVisitor(
     std::unique_ptr<BugReporterVisitor> visitor) {
   if (!visitor)
@@ -2221,12 +2194,12 @@
       return;
     case bugreporter::TrackingKind::Condition:
       return;
-    }
+  }
 
-    llvm_unreachable(
-        "BugReport::markInteresting currently can only handle 2 different "
-        "tracking kinds! Please define what tracking kind should this entitiy"
-        "have, if it was already marked as interesting with a different kind!");
+  llvm_unreachable(
+      "BugReport::markInteresting currently can only handle 2 different "
+      "tracking kinds! Please define what tracking kind should this entitiy"
+      "have, if it was already marked as interesting with a different kind!");
 }
 
 void PathSensitiveBugReport::markInteresting(SymbolRef sym,
Index: clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
+++ clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
@@ -135,7 +135,7 @@
              "Invalid development status!");
     }
 
-    LLVM_DUMP_METHOD void dump() const;
+    LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
     LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &Out) const;
   };
 
@@ -195,7 +195,7 @@
     // Used for lower_bound.
     explicit CheckerInfo(StringRef FullName) : FullName(FullName) {}
 
-    LLVM_DUMP_METHOD void dump() const;
+    LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
     LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &Out) const;
   };
 
@@ -215,7 +215,7 @@
 
     explicit PackageInfo(StringRef FullName) : FullName(FullName) {}
 
-    LLVM_DUMP_METHOD void dump() const;
+    LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
     LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &Out) const;
   };
 
@@ -317,30 +317,30 @@
   /// For example, it'll return the checkers for the core package, if
   /// \p CmdLineArg is "core".
   CheckerInfoListRange getMutableCheckersForCmdLineArg(StringRef CmdLineArg);
-  /// Used for couting how many checkers belong to a certain package in the
-  /// \c Checkers field. For convenience purposes.
-  llvm::StringMap<size_t> PackageSizes;
-
-  void resolveCheckerAndPackageOptions();
-  template <bool IsWeak> void resolveDependencies();
 
-  DiagnosticsEngine &Diags;
-  AnalyzerOptions &AnOpts;
-
-public:
   CheckerInfoList Checkers;
   PackageInfoList Packages;
+  /// Used for couting how many checkers belong to a certain package in the
+  /// \c Checkers field. For convenience purposes.
+  llvm::StringMap<size_t> PackageSizes;
 
   /// Contains all (Dependendent checker, Dependency) pairs. We need this, as
   /// we'll resolve dependencies after all checkers were added first.
   llvm::SmallVector<std::pair<StringRef, StringRef>, 0> Dependencies;
   llvm::SmallVector<std::pair<StringRef, StringRef>, 0> WeakDependencies;
 
+  template <bool IsWeak> void resolveDependencies();
+
   /// Contains all (FullName, CmdLineOption) pairs. Similarly to dependencies,
   /// we only modify the actual CheckerInfo and PackageInfo objects once all
   /// of them have been added.
   llvm::SmallVector<std::pair<StringRef, CmdLineOption>, 0> PackageOptions;
   llvm::SmallVector<std::pair<StringRef, CmdLineOption>, 0> CheckerOptions;
+
+  void resolveCheckerAndPackageOptions();
+
+  DiagnosticsEngine &Diags;
+  AnalyzerOptions &AnOpts;
   CheckerInfoSet EnabledCheckers;
 };
 
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
@@ -19,7 +19,6 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
-#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
@@ -136,7 +135,7 @@
   SmallVector<FixItHint, 4> Fixits;
 
   BugReport(Kind kind, const BugType &bt, StringRef desc)
-      : BugReport(kind, bt, "", desc) {}
+      : K(kind), BT(bt), Description(desc) {}
 
   BugReport(Kind K, const BugType &BT, StringRef ShortDescription,
             StringRef Description)
@@ -370,13 +369,16 @@
 public:
   PathSensitiveBugReport(const BugType &bt, StringRef desc,
                          const ExplodedNode *errorNode)
-      : PathSensitiveBugReport(bt, desc, desc, errorNode) {}
+      : BugReport(Kind::PathSensitive, bt, desc), ErrorNode(errorNode),
+        ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()
+                                 : SourceRange()) {}
 
   PathSensitiveBugReport(const BugType &bt, StringRef shortDesc, StringRef desc,
                          const ExplodedNode *errorNode)
-      : PathSensitiveBugReport(bt, shortDesc, desc, errorNode,
-                               /*LocationToUnique*/ {},
-                               /*DeclToUnique*/ nullptr) {}
+      : BugReport(Kind::PathSensitive, bt, shortDesc, desc),
+        ErrorNode(errorNode),
+        ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()
+                                 : SourceRange()) {}
 
   /// Create a PathSensitiveBugReport with a custom uniqueing location.
   ///
@@ -389,13 +391,11 @@
                          const ExplodedNode *errorNode,
                          PathDiagnosticLocation LocationToUnique,
                          const Decl *DeclToUnique)
-      : PathSensitiveBugReport(bt, desc, desc, errorNode, LocationToUnique,
-                               DeclToUnique) {}
-
-  PathSensitiveBugReport(const BugType &bt, StringRef shortDesc, StringRef desc,
-                         const ExplodedNode *errorNode,
-                         PathDiagnosticLocation LocationToUnique,
-                         const Decl *DeclToUnique);
+      : BugReport(Kind::PathSensitive, bt, desc), ErrorNode(errorNode),
+        ErrorNodeRange(getStmt() ? getStmt()->getSourceRange() : SourceRange()),
+        UniqueingLocation(LocationToUnique), UniqueingDecl(DeclToUnique) {
+    assert(errorNode);
+  }
 
   static bool classof(const BugReport *R) {
     return R->getKind() == Kind::PathSensitive;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D81752: Revert ... Sterling Augustine via Phabricator via cfe-commits

Reply via email to