From a6215b93c45ee5931536b57d10b987747143313b Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 7 Feb 2012 02:27:37 +0000 Subject: [PATCH] Create PathDiagnosticCallEnter and PathDiagnosticCallExit, to remark calls in PathDiagnostics from other events. This will have potential uses later. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149960 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Core/BugReporter/PathDiagnostic.h | 28 ++++++++++++++++++- .../Core/BugReporterVisitors.cpp | 16 +++++------ lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp | 2 ++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp | 2 ++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp | 4 ++- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h b/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h index 30b133200f..9516fcea83 100644 --- a/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h +++ b/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h @@ -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 LPairs; diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index c0804e7340..3ea08cde00 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -758,6 +758,10 @@ CallEnterExitBRVisitor::VisitNode(const ExplodedNode *N, Out << "Entering call to block"; else if (const NamedDecl *ND = dyn_cast(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(&PP)) { const Decl *caller = CExit->getLocationContext()->getParent()->getDecl(); @@ -765,15 +769,9 @@ CallEnterExitBRVisitor::VisitNode(const ExplodedNode *N, if (const NamedDecl *ND = dyn_cast(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; } diff --git a/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp index 933e15c0de..2b3dcdc5c8 100644 --- a/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ b/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp @@ -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. diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index c0bb180c82..0d2c2e82d9 100644 --- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -52,6 +52,8 @@ PathDiagnosticPiece::PathDiagnosticPiece(Kind k, DisplayHint hint) PathDiagnosticPiece::~PathDiagnosticPiece() {} PathDiagnosticEventPiece::~PathDiagnosticEventPiece() {} +PathDiagnosticCallEnterPiece::~PathDiagnosticCallEnterPiece() {} +PathDiagnosticCallExitPiece::~PathDiagnosticCallExitPiece() {} PathDiagnosticControlFlowPiece::~PathDiagnosticControlFlowPiece() {} PathDiagnosticMacroPiece::~PathDiagnosticMacroPiece() { diff --git a/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp index cc8c315c4e..89b44c1ca0 100644 --- a/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp +++ b/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp @@ -275,8 +275,10 @@ static void ReportDiag(raw_ostream &o, const PathDiagnosticPiece& P, ReportControlFlow(o, cast(P), FM, SM, LangOpts, indent); break; + case PathDiagnosticPiece::CallEnter: + case PathDiagnosticPiece::CallExit: case PathDiagnosticPiece::Event: - ReportEvent(o, cast(P), FM, SM, LangOpts, + ReportEvent(o, cast(P), FM, SM, LangOpts, indent); break; case PathDiagnosticPiece::Macro: -- 2.40.0