[PATCH] D67418: [analyzer] NFC: Move PathDiagnostic::resetDiagnosticLocationToMainFile to bug reporter.

2019-09-11 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL371660: [analyzer] NFC: Move 
resetDiagnosticLocationToMainFile() to BugReporter. (authored by dergachev, 
committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67418?vs=219624&id=219795#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67418/new/

https://reviews.llvm.org/D67418

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp

Index: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
@@ -792,11 +792,6 @@
 VerboseDesc += S;
   }
 
-  /// If the last piece of the report point to the header file, resets
-  /// the location of the report to be the last location in the main source
-  /// file.
-  void resetDiagnosticLocationToMainFile();
-
   StringRef getVerboseDescription() const { return VerboseDesc; }
 
   StringRef getShortDescription() const {
@@ -807,11 +802,6 @@
   StringRef getBugType() const { return BugType; }
   StringRef getCategory() const { return Category; }
 
-  /// Return the semantic context where an issue occurred.  If the
-  /// issue occurs along a path, this represents the "central" area
-  /// where the bug manifests.
-  const Decl *getDeclWithIssue() const { return DeclWithIssue; }
-
   using meta_iterator = std::deque::const_iterator;
 
   meta_iterator meta_begin() const { return OtherDesc.begin(); }
@@ -826,10 +816,23 @@
 return *ExecutedLines;
   }
 
+  /// Return the semantic context where an issue occurred.  If the
+  /// issue occurs along a path, this represents the "central" area
+  /// where the bug manifests.
+  const Decl *getDeclWithIssue() const { return DeclWithIssue; }
+
+  void setDeclWithIssue(const Decl *D) {
+DeclWithIssue = D;
+  }
+
   PathDiagnosticLocation getLocation() const {
 return Loc;
   }
 
+  void setLocation(PathDiagnosticLocation NewLoc) {
+Loc = NewLoc;
+  }
+
   /// Get the location on which the report should be uniqued.
   PathDiagnosticLocation getUniqueingLoc() const {
 return UniqueingLoc;
Index: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -29,7 +29,6 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/None.h"
@@ -130,69 +129,6 @@
   UniqueingDecl(DeclToUnique), ExecutedLines(std::move(ExecutedLines)),
   path(pathImpl) {}
 
-static PathDiagnosticCallPiece *
-getFirstStackedCallToHeaderFile(PathDiagnosticCallPiece *CP,
-const SourceManager &SMgr) {
-  SourceLocation CallLoc = CP->callEnter.asLocation();
-
-  // If the call is within a macro, don't do anything (for now).
-  if (CallLoc.isMacroID())
-return nullptr;
-
-  assert(AnalysisManager::isInCodeFile(CallLoc, SMgr) &&
- "The call piece should not be in a header file.");
-
-  // Check if CP represents a path through a function outside of the main file.
-  if (!AnalysisManager::isInCodeFile(CP->callEnterWithin.asLocation(), SMgr))
-return CP;
-
-  const PathPieces &Path = CP->path;
-  if (Path.empty())
-return nullptr;
-
-  // Check if the last piece in the callee path is a call to a function outside
-  // of the main file.
-  if (auto *CPInner = dyn_cast(Path.back().get()))
-return getFirstStackedCallToHeaderFile(CPInner, SMgr);
-
-  // Otherwise, the last piece is in the main file.
-  return nullptr;
-}
-
-void PathDiagnostic::resetDiagnosticLocationToMainFile() {
-  if (path.empty())
-return;
-
-  PathDiagnosticPiece *LastP = path.back().get();
-  assert(LastP);
-  const SourceManager &SMgr = LastP->getLocation().getManager();
-
-  // We only need to check if the report ends inside headers, if the last piece
-  // is a call piece.
-  if (auto *CP = dyn_cast(LastP)) {
-CP = getFirstStackedCallToHeaderFile(CP, SMgr);
-if (CP) {
-  // Mark the piece.
-   CP->setAsLastInMainSourceFile();
-
-  // Update the path diagnostic message.
-  const auto *ND = dyn_cast(CP->getCallee());
-  if (ND) {
-SmallString<200> buf;
-llvm::raw_svector_ostream os(buf);
-os << " (within a call to '" << ND->getDeclName() << "')";
-appendToDesc(os.str());
-  }
-
-  // Re

[PATCH] D67418: [analyzer] NFC: Move PathDiagnostic::resetDiagnosticLocationToMainFile to bug reporter.

2019-09-11 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

Sure!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67418/new/

https://reviews.llvm.org/D67418



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67418: [analyzer] NFC: Move PathDiagnostic::resetDiagnosticLocationToMainFile to bug reporter.

2019-09-10 Thread Artem Dergachev via Phabricator via cfe-commits
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.
Herald added a project: clang.
NoQ added a parent revision: D67382: [analyzer] NFC: Move getStmt() and 
createEndOfPath() out of PathDiagnostic..

This function uses `AnalysisManager`, which is Static Analyzer-specific entity, 
but i want path diagnostics to be independent of the Static Analyzer.

In fact it only uses `AnalysisManager::isInCodeFile()` which is essentially 
static and might be useful outside of the Analyzer; however, Clang-Tidy has its 
own idea of what code to analyze, so i feel i can't enforce this method on them.

More importantly, though, i'm only handing off the PathDiagnostic data 
structure, but not the procedure of constructing those particularly neat 
analyzer-like path diagnostics. And this whole function is definitely part of 
the construction procedure, not of the data structure itself, so it shouldn't 
be handed off.


Repository:
  rC Clang

https://reviews.llvm.org/D67418

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

Index: clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -29,7 +29,6 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/None.h"
@@ -130,69 +129,6 @@
   UniqueingDecl(DeclToUnique), ExecutedLines(std::move(ExecutedLines)),
   path(pathImpl) {}
 
-static PathDiagnosticCallPiece *
-getFirstStackedCallToHeaderFile(PathDiagnosticCallPiece *CP,
-const SourceManager &SMgr) {
-  SourceLocation CallLoc = CP->callEnter.asLocation();
-
-  // If the call is within a macro, don't do anything (for now).
-  if (CallLoc.isMacroID())
-return nullptr;
-
-  assert(AnalysisManager::isInCodeFile(CallLoc, SMgr) &&
- "The call piece should not be in a header file.");
-
-  // Check if CP represents a path through a function outside of the main file.
-  if (!AnalysisManager::isInCodeFile(CP->callEnterWithin.asLocation(), SMgr))
-return CP;
-
-  const PathPieces &Path = CP->path;
-  if (Path.empty())
-return nullptr;
-
-  // Check if the last piece in the callee path is a call to a function outside
-  // of the main file.
-  if (auto *CPInner = dyn_cast(Path.back().get()))
-return getFirstStackedCallToHeaderFile(CPInner, SMgr);
-
-  // Otherwise, the last piece is in the main file.
-  return nullptr;
-}
-
-void PathDiagnostic::resetDiagnosticLocationToMainFile() {
-  if (path.empty())
-return;
-
-  PathDiagnosticPiece *LastP = path.back().get();
-  assert(LastP);
-  const SourceManager &SMgr = LastP->getLocation().getManager();
-
-  // We only need to check if the report ends inside headers, if the last piece
-  // is a call piece.
-  if (auto *CP = dyn_cast(LastP)) {
-CP = getFirstStackedCallToHeaderFile(CP, SMgr);
-if (CP) {
-  // Mark the piece.
-   CP->setAsLastInMainSourceFile();
-
-  // Update the path diagnostic message.
-  const auto *ND = dyn_cast(CP->getCallee());
-  if (ND) {
-SmallString<200> buf;
-llvm::raw_svector_ostream os(buf);
-os << " (within a call to '" << ND->getDeclName() << "')";
-appendToDesc(os.str());
-  }
-
-  // Reset the report containing declaration and location.
-  DeclWithIssue = CP->getCaller();
-  Loc = CP->getLocation();
-
-  return;
-}
-  }
-}
-
 void PathDiagnosticConsumer::anchor() {}
 
 PathDiagnosticConsumer::~PathDiagnosticConsumer() {
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3130,6 +3130,71 @@
   return Out;
 }
 
+static PathDiagnosticCallPiece *
+getFirstStackedCallToHeaderFile(PathDiagnosticCallPiece *CP,
+const SourceManager &SMgr) {
+  SourceLocation CallLoc = CP->callEnter.asLocation();
+
+  // If the call is within a macro, don't do anything (for now).
+  if (CallLoc.isMacroID())
+return nullptr;
+
+  assert(AnalysisManager::isInCodeFile(CallLoc, SMgr) &&
+ "The call piece should not be in a header file.");
+
+  // Check if CP represents a path through a function outside of the main file.
+  if (!AnalysisManager::isInCodeFile(CP->callEnterWithin.asLocation(), SMgr))
+return CP;
+
+  const PathPieces &Path = CP->path;
+