]> granicus.if.org Git - clang/commitdiff
Create PathDiagnosticCallEnter and PathDiagnosticCallExit, to remark calls in PathDia...
authorTed Kremenek <kremenek@apple.com>
Tue, 7 Feb 2012 02:27:37 +0000 (02:27 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 7 Feb 2012 02:27:37 +0000 (02:27 +0000)
have potential uses later.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149960 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
lib/StaticAnalyzer/Core/PathDiagnostic.cpp
lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

index 30b133200ffba69f3b3e4285648ae41d2dcdcd1f..9516fcea83ccf766ce3d019f40515b25a28e6499 100644 (file)
@@ -261,7 +261,7 @@ public:
 
 class PathDiagnosticPiece {
 public:
-  enum Kind { ControlFlow, Event, Macro };
+  enum Kind { ControlFlow, Event, Macro, CallEnter, CallExit };
   enum DisplayHint { Above, Below };
 
 private:
@@ -356,6 +356,32 @@ public:
     return P->getKind() == Event;
   }
 };
+  
+class PathDiagnosticCallEnterPiece : public PathDiagnosticSpotPiece {
+public:
+  PathDiagnosticCallEnterPiece(const PathDiagnosticLocation &pos,
+                              StringRef s)
+    : PathDiagnosticSpotPiece(pos, s, CallEnter, false) {}
+  
+  ~PathDiagnosticCallEnterPiece();
+  
+  static inline bool classof(const PathDiagnosticPiece *P) {
+    return P->getKind() == CallEnter;
+  }  
+};
+
+class PathDiagnosticCallExitPiece : public PathDiagnosticSpotPiece {
+public:
+  PathDiagnosticCallExitPiece(const PathDiagnosticLocation &pos,
+                             StringRef s)
+  : PathDiagnosticSpotPiece(pos, s, CallExit, false) {}
+  
+  ~PathDiagnosticCallExitPiece();
+  
+  static inline bool classof(const PathDiagnosticPiece *P) {
+    return P->getKind() == CallExit;
+  }  
+};
 
 class PathDiagnosticControlFlowPiece : public PathDiagnosticPiece {
   std::vector<PathDiagnosticLocationPair> LPairs;
index c0804e7340e256c328ca3fa023a8ea7a75a114df..3ea08cde00632b110f5fa33db9e3c4ca6fa90151 100644 (file)
@@ -758,6 +758,10 @@ CallEnterExitBRVisitor::VisitNode(const ExplodedNode *N,
       Out << "Entering call to block";
     else if (const NamedDecl *ND = dyn_cast<NamedDecl>(callee))
       Out << "Entering call to '" << ND->getNameAsString() << "'";
+    StringRef msg = Out.str();
+    if (msg.empty())
+      return 0;
+    return new PathDiagnosticCallEnterPiece(pos, msg);
   }
   else if (const CallExit *CExit = dyn_cast<CallExit>(&PP)) {
     const Decl *caller = CExit->getLocationContext()->getParent()->getDecl();
@@ -765,15 +769,9 @@ CallEnterExitBRVisitor::VisitNode(const ExplodedNode *N,
     if (const NamedDecl *ND = dyn_cast<NamedDecl>(caller))
       Out << "Returning to '" << ND->getNameAsString() << "'";
     else
-      Out << "Returning to caller"; 
+      Out << "Returning to caller";
+    return new PathDiagnosticCallExitPiece(pos, Out.str());
   }
-  
-  if (!pos.isValid())
-    return 0;
-    
-  StringRef msg = Out.str();
-  if (msg.empty())
-    return 0;
 
-  return new PathDiagnosticEventPiece(pos, msg);
+  return 0;
 } 
index 933e15c0dec789d259b6212eeaebafb5179bb619..2b3dcdc5c89e3febf1bc827e039556631a75260d 100644 (file)
@@ -334,6 +334,8 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R, FileID BugFileID,
 
   const char *Kind = 0;
   switch (P.getKind()) {
+  case PathDiagnosticPiece::CallEnter:
+  case PathDiagnosticPiece::CallExit:
   case PathDiagnosticPiece::Event:  Kind = "Event"; break;
   case PathDiagnosticPiece::ControlFlow: Kind = "Control"; break;
     // Setting Kind to "Control" is intentional.
index c0bb180c82e5fded65524fa55576bb410b938f58..0d2c2e82d97cf719bf79f9410119c5c3c6920d8f 100644 (file)
@@ -52,6 +52,8 @@ PathDiagnosticPiece::PathDiagnosticPiece(Kind k, DisplayHint hint)
 
 PathDiagnosticPiece::~PathDiagnosticPiece() {}
 PathDiagnosticEventPiece::~PathDiagnosticEventPiece() {}
+PathDiagnosticCallEnterPiece::~PathDiagnosticCallEnterPiece() {}
+PathDiagnosticCallExitPiece::~PathDiagnosticCallExitPiece() {}
 PathDiagnosticControlFlowPiece::~PathDiagnosticControlFlowPiece() {}
 
 PathDiagnosticMacroPiece::~PathDiagnosticMacroPiece() {
index cc8c315c4e34ac40a183909df0e49f59d4ca63ef..89b44c1ca04eb90ec0e99d3d6319e96fc8e37f5d 100644 (file)
@@ -275,8 +275,10 @@ static void ReportDiag(raw_ostream &o, const PathDiagnosticPiece& P,
     ReportControlFlow(o, cast<PathDiagnosticControlFlowPiece>(P), FM, SM,
                       LangOpts, indent);
     break;
+  case PathDiagnosticPiece::CallEnter:
+  case PathDiagnosticPiece::CallExit:
   case PathDiagnosticPiece::Event:
-    ReportEvent(o, cast<PathDiagnosticEventPiece>(P), FM, SM, LangOpts,
+    ReportEvent(o, cast<PathDiagnosticSpotPiece>(P), FM, SM, LangOpts,
                 indent);
     break;
   case PathDiagnosticPiece::Macro: