[clang] 20a3d64 - [Analyzer][NFC] Change parameter of NoteTag lambdas to PathSensitiveBugReport

Adam Balogh via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 10 03:38:07 PDT 2020


Author: Adam Balogh
Date: 2020-03-10T11:30:28+01:00
New Revision: 20a3d64c8883c8be550f0759525b1550b7c2d35f

URL: https://github.com/llvm/llvm-project/commit/20a3d64c8883c8be550f0759525b1550b7c2d35f
DIFF: https://github.com/llvm/llvm-project/commit/20a3d64c8883c8be550f0759525b1550b7c2d35f.diff

LOG: [Analyzer][NFC] Change parameter of NoteTag lambdas to PathSensitiveBugReport

Lambdas creating path notes using NoteTags still take BugReport as their
parameter. Since path notes obviously only appear in PathSensitiveBugReports
it is straightforward that lambdas of NoteTags take PathSensitiveBugReport
as their parameter.

Differential Revision: https://reviews.llvm.org/D75898

Added: 
    

Modified: 
    clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
    clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
    clang/lib/StaticAnalyzer/Checkers/CXXSelfAssignmentChecker.cpp
    clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
    clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
    clang/lib/StaticAnalyzer/Checkers/ReturnValueChecker.cpp
    clang/lib/StaticAnalyzer/Core/CoreEngine.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
index 1b39cdf12c80..d45c4b71e780 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -726,7 +726,8 @@ class BugReporterContext {
 class NoteTag : public ProgramPointTag {
 public:
   using Callback =
-      std::function<std::string(BugReporterContext &, BugReport &)>;
+      std::function<std::string(BugReporterContext &,
+                                PathSensitiveBugReport &)>;
 
 private:
   static int Kind;
@@ -743,7 +744,7 @@ class NoteTag : public ProgramPointTag {
   }
 
   Optional<std::string> generateMessage(BugReporterContext &BRC,
-                                        BugReport &R) const {
+                                        PathSensitiveBugReport &R) const {
     std::string Msg = Cb(BRC, R);
     if (Msg.empty())
       return None;

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
index aee26db95fd1..2b5d37b6cc41 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -258,10 +258,12 @@ class CheckerContext {
   /// @param IsPrunable Whether the note is prunable. It allows BugReporter
   ///        to omit the note from the report if it would make the displayed
   ///        bug path significantly shorter.
-  const NoteTag *getNoteTag(std::function<std::string(BugReport &)> &&Cb,
-                            bool IsPrunable = false) {
+  const NoteTag
+  *getNoteTag(std::function<std::string(PathSensitiveBugReport &)> &&Cb,
+              bool IsPrunable = false) {
     return getNoteTag(
-        [Cb](BugReporterContext &, BugReport &BR) { return Cb(BR); },
+        [Cb](BugReporterContext &,
+             PathSensitiveBugReport &BR) { return Cb(BR); },
         IsPrunable);
   }
 
@@ -274,7 +276,8 @@ class CheckerContext {
   ///        bug path significantly shorter.
   const NoteTag *getNoteTag(std::function<std::string()> &&Cb,
                             bool IsPrunable = false) {
-    return getNoteTag([Cb](BugReporterContext &, BugReport &) { return Cb(); },
+    return getNoteTag([Cb](BugReporterContext &,
+                           PathSensitiveBugReport &) { return Cb(); },
                       IsPrunable);
   }
 
@@ -286,7 +289,8 @@ class CheckerContext {
   ///        bug path significantly shorter.
   const NoteTag *getNoteTag(StringRef Note, bool IsPrunable = false) {
     return getNoteTag(
-        [Note](BugReporterContext &, BugReport &) { return std::string(Note); },
+        [Note](BugReporterContext &,
+               PathSensitiveBugReport &) { return std::string(Note); },
         IsPrunable);
   }
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CXXSelfAssignmentChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CXXSelfAssignmentChecker.cpp
index f7cee71ef0a1..aada05db2cbc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CXXSelfAssignmentChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CXXSelfAssignmentChecker.cpp
@@ -53,7 +53,7 @@ void CXXSelfAssignmentChecker::checkBeginFunction(CheckerContext &C) const {
 
   ProgramStateRef SelfAssignState = State->bindLoc(Param, ThisVal, LCtx);
   const NoteTag *SelfAssignTag =
-    C.getNoteTag([MD](BugReport &BR) -> std::string {
+    C.getNoteTag([MD](PathSensitiveBugReport &BR) -> std::string {
         SmallString<256> Msg;
         llvm::raw_svector_ostream Out(Msg);
         Out << "Assuming " << MD->getParamDecl(0)->getName() << " == *this";
@@ -63,7 +63,7 @@ void CXXSelfAssignmentChecker::checkBeginFunction(CheckerContext &C) const {
 
   ProgramStateRef NonSelfAssignState = State->bindLoc(Param, ParamVal, LCtx);
   const NoteTag *NonSelfAssignTag =
-    C.getNoteTag([MD](BugReport &BR) -> std::string {
+    C.getNoteTag([MD](PathSensitiveBugReport &BR) -> std::string {
         SmallString<256> Msg;
         llvm::raw_svector_ostream Out(Msg);
         Out << "Assuming " << MD->getParamDecl(0)->getName() << " != *this";

diff  --git a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
index 3a56a941ff31..dee2212cd5d8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
@@ -382,8 +382,8 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent &Call,
   }
   const NoteTag *T = nullptr;
   if (!Notes.empty()) {
-    T = C.getNoteTag(
-        [this, Notes{std::move(Notes)}](BugReport &BR) -> std::string {
+    T = C.getNoteTag([this, Notes{std::move(Notes)}](
+                         PathSensitiveBugReport &BR) -> std::string {
           if (&BR.getBugType() != &UseAfterReleaseBugType &&
               &BR.getBugType() != &LeakBugType &&
               &BR.getBugType() != &DoubleReleaseBugType)

diff  --git a/clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
index 2259c1222ead..d7555b78ac40 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
@@ -210,15 +210,16 @@ void MIGChecker::checkPostCall(const CallEvent &Call, CheckerContext &C) const {
   if (!PVD || State->contains<RefCountedParameters>(PVD))
     return;
 
-  const NoteTag *T = C.getNoteTag([this, PVD](BugReport &BR) -> std::string {
-    if (&BR.getBugType() != &BT)
-      return "";
-    SmallString<64> Str;
-    llvm::raw_svector_ostream OS(Str);
-    OS << "Value passed through parameter '" << PVD->getName()
-       << "\' is deallocated";
-    return std::string(OS.str());
-  });
+  const NoteTag *T =
+    C.getNoteTag([this, PVD](PathSensitiveBugReport &BR) -> std::string {
+        if (&BR.getBugType() != &BT)
+          return "";
+        SmallString<64> Str;
+        llvm::raw_svector_ostream OS(Str);
+        OS << "Value passed through parameter '" << PVD->getName()
+           << "\' is deallocated";
+        return std::string(OS.str());
+      });
   C.addTransition(State->set<ReleasedParameter>(true), T);
 }
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/ReturnValueChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ReturnValueChecker.cpp
index 7352f3e8d717..f98065492726 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ReturnValueChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ReturnValueChecker.cpp
@@ -99,7 +99,7 @@ void ReturnValueChecker::checkPostCall(const CallEvent &Call,
 
   std::string Name = getName(Call);
   const NoteTag *CallTag = C.getNoteTag(
-      [Name, ExpectedValue](BugReport &) -> std::string {
+      [Name, ExpectedValue](PathSensitiveBugReport &) -> std::string {
         SmallString<128> Msg;
         llvm::raw_svector_ostream Out(Msg);
 

diff  --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 94cf74de8293..5a49b18aecf1 100644
--- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -221,7 +221,7 @@ void CoreEngine::HandleBlockEdge(const BlockEdge &L, ExplodedNode *Pred) {
   if (L.getSrc()->getTerminator().isVirtualBaseBranch() &&
       L.getDst() == *L.getSrc()->succ_begin()) {
     ProgramPoint P = L.withTag(getNoteTags().makeNoteTag(
-        [](BugReporterContext &, BugReport &) -> std::string {
+        [](BugReporterContext &, PathSensitiveBugReport &) -> std::string {
           // TODO: Just call out the name of the most derived class
           // when we know it.
           return "Virtual base initialization skipped because "


        


More information about the cfe-commits mailing list