[cfe-commits] r151338 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h lib/StaticAnalyzer/Core/BugReporter.cpp lib/StaticAnalyzer/Core/BugReporterVisitors.cpp lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp lib/StaticAnalyzer/Core/PathDiagnostic.cpp lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
Chad Rosier
mcrosier at apple.com
Thu Feb 23 18:06:33 PST 2012
Author: mcrosier
Date: Thu Feb 23 20:06:33 2012
New Revision: 151338
URL: http://llvm.org/viewvc/llvm-project?rev=151338&view=rev
Log:
Revert r151317 - Rework PathDiagnostics creation.. - to appease buildbots.
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h?rev=151338&r1=151337&r2=151338&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h Thu Feb 23 20:06:33 2012
@@ -170,6 +170,23 @@
llvm::raw_ostream &Out,
BugReporterContext &BRC);
};
+
+class CallEnterExitBRVisitor : public BugReporterVisitor {
+ const bool showTopLevelCall;
+public:
+ void Profile(llvm::FoldingSetNodeID &ID) const {
+ static int x = 0;
+ ID.AddPointer(&x);
+ }
+
+ CallEnterExitBRVisitor(bool showTopLevel)
+ : showTopLevelCall(showTopLevel) {}
+
+ PathDiagnosticPiece *VisitNode(const ExplodedNode *N,
+ const ExplodedNode *PrevN,
+ BugReporterContext &BRC,
+ BugReport &BR);
+};
namespace bugreporter {
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=151338&r1=151337&r2=151338&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h Thu Feb 23 20:06:33 2012
@@ -15,7 +15,6 @@
#define LLVM_CLANG_PATH_DIAGNOSTIC_H
#include "clang/Basic/SourceLocation.h"
-#include "clang/Analysis/ProgramPoint.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/PointerUnion.h"
@@ -263,7 +262,7 @@
class PathDiagnosticPiece : public RefCountedBaseVPTR {
public:
- enum Kind { ControlFlow, Event, Macro, Call };
+ enum Kind { ControlFlow, Event, Macro, CallEnter, CallExit };
enum DisplayHint { Above, Below };
private:
@@ -365,53 +364,31 @@
return P->getKind() == Event;
}
};
-
-class PathDiagnosticCallPiece : public PathDiagnosticPiece {
- PathDiagnosticCallPiece(const Decl *callerD,
- const PathDiagnosticLocation &callReturnPos)
- : PathDiagnosticPiece(Call), Caller(callerD),
- Callee(0), callReturn(callReturnPos) {}
-
- PathDiagnosticCallPiece(PathPieces &oldPath)
- : PathDiagnosticPiece(Call), Caller(0), Callee(0), path(oldPath) {}
- const Decl *Caller;
- const Decl *Callee;
+class PathDiagnosticCallEnterPiece : public PathDiagnosticSpotPiece {
public:
- PathDiagnosticLocation callEnter;
- PathDiagnosticLocation callReturn;
- PathPieces path;
+ PathDiagnosticCallEnterPiece(const PathDiagnosticLocation &pos,
+ StringRef s)
+ : PathDiagnosticSpotPiece(pos, s, CallEnter, false) {}
- virtual ~PathDiagnosticCallPiece();
+ ~PathDiagnosticCallEnterPiece();
- const Decl *getCaller() const { return Caller; }
-
- const Decl *getCallee() const { return Callee; }
- void setCallee(const CallEnter &CE, const SourceManager &SM);
-
- virtual PathDiagnosticLocation getLocation() const {
- return callEnter;
- }
-
- IntrusiveRefCntPtr<PathDiagnosticEventPiece> getCallEnterEvent() const;
- IntrusiveRefCntPtr<PathDiagnosticEventPiece> getCallExitEvent() const;
+ static inline bool classof(const PathDiagnosticPiece *P) {
+ return P->getKind() == CallEnter;
+ }
+};
- virtual void flattenLocations() {
- callEnter.flatten();
- callReturn.flatten();
- for (PathPieces::iterator I = path.begin(),
- E = path.end(); I != E; ++I) (*I)->flattenLocations();
- }
-
- static PathDiagnosticCallPiece *construct(const ExplodedNode *N,
- const CallExit &CE,
- const SourceManager &SM);
+class PathDiagnosticCallExitPiece : public PathDiagnosticSpotPiece {
+public:
+ PathDiagnosticCallExitPiece(const PathDiagnosticLocation &pos,
+ StringRef s)
+ : PathDiagnosticSpotPiece(pos, s, CallExit, false) {}
- static PathDiagnosticCallPiece *construct(PathPieces &pieces);
+ ~PathDiagnosticCallExitPiece();
static inline bool classof(const PathDiagnosticPiece *P) {
- return P->getKind() == Call;
- }
+ return P->getKind() == CallExit;
+ }
};
class PathDiagnosticControlFlowPiece : public PathDiagnosticPiece {
@@ -502,27 +479,8 @@
std::string Desc;
std::string Category;
std::deque<std::string> OtherDesc;
- PathPieces pathImpl;
- llvm::SmallVector<PathPieces *, 3> pathStack;
public:
- const PathPieces &path;
-
- /// Return the path currently used by builders for constructing the
- /// PathDiagnostic.
- PathPieces &getActivePath() {
- if (pathStack.empty())
- return pathImpl;
- return *pathStack.back();
- }
-
- /// Return a mutable version of 'path'.
- PathPieces &getMutablePieces() {
- return pathImpl;
- }
-
-
- void pushActivePath(PathPieces *p) { pathStack.push_back(p); }
- void popActivePath() { if (!pathStack.empty()) pathStack.pop_back(); }
+ PathPieces path;
PathDiagnostic();
PathDiagnostic(StringRef bugtype, StringRef desc,
@@ -547,7 +505,7 @@
}
void flattenLocations() {
- for (PathPieces::iterator I = pathImpl.begin(), E = pathImpl.end();
+ for (PathPieces::iterator I = path.begin(), E = path.end();
I != E; ++I) (*I)->flattenLocations();
}
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=151338&r1=151337&r2=151338&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Thu Feb 23 20:06:33 2012
@@ -447,7 +447,7 @@
PathDiagnosticLocation L =
PathDiagnosticLocation::createBegin(S, BR.getSourceManager(),
Pred->getLocationContext());
- PD.getActivePath().push_front(new PathDiagnosticEventPiece(L, os.str()));
+ PD.path.push_front(new PathDiagnosticEventPiece(L, os.str()));
}
return true;
@@ -529,32 +529,6 @@
NextNode = GetPredecessorNode(N);
ProgramPoint P = N->getLocation();
-
- if (const CallExit *CE = dyn_cast<CallExit>(&P)) {
- PathDiagnosticCallPiece *C =
- PathDiagnosticCallPiece::construct(N, *CE, SMgr);
- PD.getActivePath().push_front(C);
- PD.pushActivePath(&C->path);
- continue;
- }
-
- if (const CallEnter *CE = dyn_cast<CallEnter>(&P)) {
- PD.popActivePath();
- // The current active path should never be empty. Either we
- // just added a bunch of stuff to the top-level path, or
- // we have a previous CallExit. If the front of the active
- // path is not a PathDiagnosticCallPiece, it means that the
- // path terminated within a function call. We must then take the
- // current contents of the active path and place it within
- // a new PathDiagnosticCallPiece.
- assert(!PD.getActivePath().empty());
- PathDiagnosticCallPiece *C =
- dyn_cast<PathDiagnosticCallPiece>(PD.getActivePath().front());
- if (!C)
- C = PathDiagnosticCallPiece::construct(PD.getActivePath());
- C->setCallee(*CE, SMgr);
- continue;
- }
if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
const CFGBlock *Src = BE->getSrc();
@@ -585,7 +559,7 @@
os << "Control jumps to line "
<< End.asLocation().getExpansionLineNumber();
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
break;
}
@@ -637,13 +611,13 @@
break;
}
}
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
}
else {
os << "'Default' branch taken. ";
const PathDiagnosticLocation &End = PDB.ExecutionContinues(os, N);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
}
@@ -655,7 +629,7 @@
std::string sbuf;
llvm::raw_string_ostream os(sbuf);
PathDiagnosticLocation End = PDB.ExecutionContinues(os, N);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
break;
}
@@ -677,7 +651,7 @@
if (const Stmt *S = End.asStmt())
End = PDB.getEnclosingStmtLocation(S);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
break;
}
@@ -700,14 +674,14 @@
PathDiagnosticLocation End(B->getLHS(), SMgr, LC);
PathDiagnosticLocation Start =
PathDiagnosticLocation::createOperatorLoc(B, SMgr);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
}
else {
os << "true";
PathDiagnosticLocation Start(B->getLHS(), SMgr, LC);
PathDiagnosticLocation End = PDB.ExecutionContinues(N);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
}
}
@@ -719,7 +693,7 @@
os << "false";
PathDiagnosticLocation Start(B->getLHS(), SMgr, LC);
PathDiagnosticLocation End = PDB.ExecutionContinues(N);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
}
else {
@@ -727,7 +701,7 @@
PathDiagnosticLocation End(B->getLHS(), SMgr, LC);
PathDiagnosticLocation Start =
PathDiagnosticLocation::createOperatorLoc(B, SMgr);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
}
}
@@ -746,7 +720,7 @@
if (const Stmt *S = End.asStmt())
End = PDB.getEnclosingStmtLocation(S);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
}
else {
@@ -755,7 +729,7 @@
if (const Stmt *S = End.asStmt())
End = PDB.getEnclosingStmtLocation(S);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
"Loop condition is false. Exiting loop"));
}
@@ -773,7 +747,7 @@
if (const Stmt *S = End.asStmt())
End = PDB.getEnclosingStmtLocation(S);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
os.str()));
}
else {
@@ -781,7 +755,7 @@
if (const Stmt *S = End.asStmt())
End = PDB.getEnclosingStmtLocation(S);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
"Loop condition is true. Entering loop body"));
}
@@ -795,10 +769,10 @@
End = PDB.getEnclosingStmtLocation(S);
if (*(Src->succ_begin()+1) == Dst)
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
"Taking false branch"));
else
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(Start, End,
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(Start, End,
"Taking true branch"));
break;
@@ -812,7 +786,7 @@
for (BugReport::visitor_iterator I = R->visitor_begin(),
E = R->visitor_end(); I!=E; ++I) {
if (PathDiagnosticPiece *p = (*I)->VisitNode(N, NextNode, PDB, *R))
- PD.getActivePath().push_front(p);
+ PD.path.push_front(p);
}
}
@@ -1045,7 +1019,7 @@
PrevLocClean.asLocation().getExpansionLoc())
return;
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(NewLocClean, PrevLocClean));
+ PD.path.push_front(new PathDiagnosticControlFlowPiece(NewLocClean, PrevLocClean));
PrevLoc = NewLoc;
}
@@ -1172,10 +1146,6 @@
LCtx);
EB.addEdge(Loc, true);
EB.flushLocations();
- PathDiagnosticCallPiece *C =
- PathDiagnosticCallPiece::construct(N, *CE, SM);
- PD.getActivePath().push_front(C);
- PD.pushActivePath(&C->path);
break;
}
@@ -1186,27 +1156,6 @@
N->getLocationContext()->getCurrentStackFrame()) {
EB.flushLocations();
}
-
- // Pop the call hierarchy if we are done walking the contents
- // of a function call.
- if (const CallEnter *CE = dyn_cast<CallEnter>(&P)) {
- PD.popActivePath();
- // The current active path should never be empty. Either we
- // just added a bunch of stuff to the top-level path, or
- // we have a previous CallExit. If the front of the active
- // path is not a PathDiagnosticCallPiece, it means that the
- // path terminated within a function call. We must then take the
- // current contents of the active path and place it within
- // a new PathDiagnosticCallPiece.
- assert(!PD.getActivePath().empty());
- PathDiagnosticCallPiece *C =
- dyn_cast<PathDiagnosticCallPiece>(PD.getActivePath().front());
- if (!C)
- C = PathDiagnosticCallPiece::construct(PD.getActivePath());
- C->setCallee(*CE, SM);
- EB.addContext(CE->getCallExpr());
- break;
- }
// Block edges.
if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
@@ -1230,7 +1179,7 @@
"Looping back to the head of the loop");
EB.addEdge(p->getLocation(), true);
- PD.getActivePath().push_front(p);
+ PD.path.push_front(p);
if (CS) {
PathDiagnosticLocation BL =
@@ -1272,7 +1221,7 @@
if (PathDiagnosticPiece *p = (*I)->VisitNode(N, NextNode, PDB, *R)) {
const PathDiagnosticLocation &Loc = p->getLocation();
EB.addEdge(Loc, true);
- PD.getActivePath().push_front(p);
+ PD.path.push_front(p);
if (const Stmt *S = Loc.asStmt())
EB.addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt());
}
@@ -1603,8 +1552,8 @@
/// CompactPathDiagnostic - This function postprocesses a PathDiagnostic object
/// and collapses PathDiagosticPieces that are expanded by macros.
static void CompactPathDiagnostic(PathDiagnostic &PD, const SourceManager& SM) {
- typedef std::vector<std::pair<IntrusiveRefCntPtr<PathDiagnosticMacroPiece>,
- SourceLocation> > MacroStackTy;
+ typedef std::vector<std::pair<IntrusiveRefCntPtr<PathDiagnosticMacroPiece>, SourceLocation> >
+ MacroStackTy;
typedef std::vector<IntrusiveRefCntPtr<PathDiagnosticPiece> >
PiecesTy;
@@ -1612,8 +1561,7 @@
MacroStackTy MacroStack;
PiecesTy Pieces;
- for (PathPieces::const_iterator I = PD.path.begin(), E = PD.path.end();
- I!=E; ++I) {
+ for (PathPieces::iterator I = PD.path.begin(), E = PD.path.end(); I!=E; ++I) {
// Get the location of the PathDiagnosticPiece.
const FullSourceLoc Loc = (*I)->getLocation().asLocation();
@@ -1682,13 +1630,13 @@
}
// Now take the pieces and construct a new PathDiagnostic.
- PD.getMutablePieces().clear();
+ PD.path.clear();
for (PiecesTy::iterator I=Pieces.begin(), E=Pieces.end(); I!=E; ++I) {
if (PathDiagnosticMacroPiece *MP = dyn_cast<PathDiagnosticMacroPiece>(*I))
if (!MP->containsEvent())
continue;
- PD.getMutablePieces().push_back(*I);
+ PD.path.push_back(*I);
}
}
@@ -1724,6 +1672,11 @@
// Register additional node visitors.
R->addVisitor(new NilReceiverBRVisitor());
R->addVisitor(new ConditionBRVisitor());
+
+ // If inlining is turning out, emit diagnostics for CallEnter and
+ // CallExit at the top level.
+ bool showTopLevel = Eng.getAnalysisManager().shouldInlineCall();
+ R->addVisitor(new CallEnterExitBRVisitor(showTopLevel));
// Generate the very last diagnostic piece - the piece is visible before
// the trace is expanded.
@@ -1739,7 +1692,7 @@
if (!LastPiece)
LastPiece = BugReporterVisitor::getDefaultEndPath(PDB, N, *R);
if (LastPiece)
- PD.getActivePath().push_back(LastPiece);
+ PD.path.push_back(LastPiece);
else
return;
@@ -2004,7 +1957,7 @@
exampleReport->getDescription());
for ( ; Beg != End; ++Beg) piece->addRange(*Beg);
- D->getActivePath().push_back(piece);
+ D->path.push_back(piece);
}
PD->HandlePathDiagnostic(D.take());
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=151338&r1=151337&r2=151338&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Thu Feb 23 20:06:33 2012
@@ -709,3 +709,51 @@
return new PathDiagnosticEventPiece(Loc, Out.str());
}
+static PathDiagnosticLocation getLastStmtLoc(const ExplodedNode *N,
+ const SourceManager &SM) {
+ while (N) {
+ ProgramPoint PP = N->getLocation();
+ if (const StmtPoint *SP = dyn_cast<StmtPoint>(&PP))
+ return PathDiagnosticLocation(SP->getStmt(), SM, PP.getLocationContext());
+ if (N->pred_empty())
+ break;
+ N = *N->pred_begin();
+ }
+ return PathDiagnosticLocation();
+}
+
+PathDiagnosticPiece *
+CallEnterExitBRVisitor::VisitNode(const ExplodedNode *N,
+ const ExplodedNode *PrevN,
+ BugReporterContext &BRC,
+ BugReport &BR) {
+ ProgramPoint PP = N->getLocation();
+ SmallString<256> buf;
+ llvm::raw_svector_ostream Out(buf);
+ PathDiagnosticLocation pos;
+
+ if (const CallEnter *CEnter = dyn_cast<CallEnter>(&PP)) {
+ const Decl *callee = CEnter->getCalleeContext()->getDecl();
+ pos = PathDiagnosticLocation(CEnter->getCallExpr(), BRC.getSourceManager(),
+ PP.getLocationContext());
+ if (isa<BlockDecl>(callee))
+ Out << "Entering call to block";
+ else if (const NamedDecl *ND = dyn_cast<NamedDecl>(callee))
+ Out << "Entering call to '" << *ND << "'";
+ 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();
+ pos = getLastStmtLoc(PrevN, BRC.getSourceManager());
+ if (const NamedDecl *ND = dyn_cast<NamedDecl>(caller))
+ Out << "Returning to '" << *ND << "'";
+ else
+ Out << "Returning to caller";
+ return new PathDiagnosticCallExitPiece(pos, Out.str());
+ }
+
+ return 0;
+}
Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=151338&r1=151337&r2=151338&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Thu Feb 23 20:06:33 2012
@@ -95,31 +95,8 @@
}
}
-static void flattenPath(PathPieces &path, const PathPieces &oldPath) {
- for (PathPieces::const_iterator it = oldPath.begin(), et = oldPath.end();
- it != et; ++it ) {
- PathDiagnosticPiece *piece = it->getPtr();
- if (const PathDiagnosticCallPiece *call =
- dyn_cast<PathDiagnosticCallPiece>(piece)) {
- IntrusiveRefCntPtr<PathDiagnosticEventPiece> callEnter =
- call->getCallEnterEvent();
- if (callEnter)
- path.push_back(callEnter);
- flattenPath(path, call->path);
- IntrusiveRefCntPtr<PathDiagnosticEventPiece> callExit =
- call->getCallExitEvent();
- if (callExit)
- path.push_back(callExit);
- continue;
- }
-
- path.push_back(piece);
- }
-}
-
void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
- SmallVectorImpl<std::string> *FilesMade) {
-
+ SmallVectorImpl<std::string> *FilesMade){
// Create the HTML directory if it is missing.
if (!createdDir) {
createdDir = true;
@@ -142,15 +119,11 @@
if (noDir)
return;
- // First flatten out the entire path to make it easier to use.
- PathPieces path;
- flattenPath(path, D.path);
-
- const SourceManager &SMgr = (*path.begin())->getLocation().getManager();
+ const SourceManager &SMgr = (*D.path.begin())->getLocation().getManager();
FileID FID;
// Verify that the entire path is from the same FileID.
- for (PathPieces::const_iterator I = path.begin(), E = path.end();
+ for (PathPieces::const_iterator I = D.path.begin(), E = D.path.end();
I != E; ++I) {
FullSourceLoc L = (*I)->getLocation().asLocation().getExpansionLoc();
@@ -179,11 +152,10 @@
Rewriter R(const_cast<SourceManager&>(SMgr), PP.getLangOptions());
// Process the path.
- unsigned n = path.size();
+ unsigned n = D.path.size();
unsigned max = n;
- for (PathPieces::const_reverse_iterator I = path.rbegin(),
- E = path.rend();
+ for (PathPieces::const_reverse_iterator I = D.path.rbegin(), E=D.path.rend();
I != E; ++I, --n)
HandlePiece(R, FID, **I, n, max);
@@ -228,9 +200,9 @@
<< html::EscapeText(Entry->getName())
<< "</td></tr>\n<tr><td class=\"rowname\">Location:</td><td>"
"<a href=\"#EndPath\">line "
- << (*path.rbegin())->getLocation().asLocation().getExpansionLineNumber()
+ << (*D.path.rbegin())->getLocation().asLocation().getExpansionLineNumber()
<< ", column "
- << (*path.rbegin())->getLocation().asLocation().getExpansionColumnNumber()
+ << (*D.path.rbegin())->getLocation().asLocation().getExpansionColumnNumber()
<< "</a></td></tr>\n"
"<tr><td class=\"rowname\">Description:</td><td>"
<< D.getDescription() << "</td></tr>\n";
@@ -268,10 +240,10 @@
os << "\n<!-- BUGFILE " << DirName << Entry->getName() << " -->\n";
os << "\n<!-- BUGLINE "
- << path.back()->getLocation().asLocation().getExpansionLineNumber()
+ << D.path.back()->getLocation().asLocation().getExpansionLineNumber()
<< " -->\n";
- os << "\n<!-- BUGPATHLENGTH " << path.size() << " -->\n";
+ os << "\n<!-- BUGPATHLENGTH " << D.path.size() << " -->\n";
// Mark the end of the tags.
os << "\n<!-- BUGMETAEND -->\n";
@@ -360,8 +332,8 @@
const char *Kind = 0;
switch (P.getKind()) {
- case PathDiagnosticPiece::Call:
- llvm_unreachable("Calls should already be handled");
+ case PathDiagnosticPiece::CallEnter:
+ case PathDiagnosticPiece::CallExit:
case PathDiagnosticPiece::Event: Kind = "Event"; break;
case PathDiagnosticPiece::ControlFlow: Kind = "Control"; break;
// Setting Kind to "Control" is intentional.
Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=151338&r1=151337&r2=151338&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Thu Feb 23 20:06:33 2012
@@ -51,10 +51,11 @@
PathDiagnosticPiece::~PathDiagnosticPiece() {}
PathDiagnosticEventPiece::~PathDiagnosticEventPiece() {}
-PathDiagnosticCallPiece::~PathDiagnosticCallPiece() {}
+PathDiagnosticCallEnterPiece::~PathDiagnosticCallEnterPiece() {}
+PathDiagnosticCallExitPiece::~PathDiagnosticCallExitPiece() {}
PathDiagnosticControlFlowPiece::~PathDiagnosticControlFlowPiece() {}
PathDiagnosticMacroPiece::~PathDiagnosticMacroPiece() {}
-PathDiagnostic::PathDiagnostic() : path(pathImpl) {}
+PathDiagnostic::PathDiagnostic() {}
PathPieces::~PathPieces() {}
PathDiagnostic::~PathDiagnostic() {}
@@ -62,8 +63,7 @@
StringRef category)
: BugType(StripTrailingDots(bugtype)),
Desc(StripTrailingDots(desc)),
- Category(StripTrailingDots(category)),
- path(pathImpl) {}
+ Category(StripTrailingDots(category)) {}
void PathDiagnosticConsumer::anchor() { }
@@ -421,78 +421,6 @@
}
}
-
-//===----------------------------------------------------------------------===//
-// Manipulation of PathDiagnosticCallPieces.
-//===----------------------------------------------------------------------===//
-
-static PathDiagnosticLocation getLastStmtLoc(const ExplodedNode *N,
- const SourceManager &SM) {
- while (N) {
- ProgramPoint PP = N->getLocation();
- if (const StmtPoint *SP = dyn_cast<StmtPoint>(&PP))
- return PathDiagnosticLocation(SP->getStmt(), SM, PP.getLocationContext());
- if (N->pred_empty())
- break;
- N = *N->pred_begin();
- }
- return PathDiagnosticLocation();
-}
-
-PathDiagnosticCallPiece *
-PathDiagnosticCallPiece::construct(const ExplodedNode *N,
- const CallExit &CE,
- const SourceManager &SM) {
- const Decl *caller = CE.getLocationContext()->getParent()->getDecl();
- PathDiagnosticLocation pos = getLastStmtLoc(N, SM);
- return new PathDiagnosticCallPiece(caller, pos);
-}
-
-PathDiagnosticCallPiece *
-PathDiagnosticCallPiece::construct(PathPieces &path) {
- PathDiagnosticCallPiece *C = new PathDiagnosticCallPiece(path);
- path.clear();
- path.push_front(C);
- return C;
-}
-
-void PathDiagnosticCallPiece::setCallee(const CallEnter &CE,
- const SourceManager &SM) {
- const Decl *D = CE.getCalleeContext()->getDecl();
- Caller = D;
- callEnter = PathDiagnosticLocation(CE.getCallExpr(), SM,
- CE.getLocationContext());
-}
-
-IntrusiveRefCntPtr<PathDiagnosticEventPiece>
-PathDiagnosticCallPiece::getCallEnterEvent() const {
- if (!Callee)
- return 0;
- SmallString<256> buf;
- llvm::raw_svector_ostream Out(buf);
- if (isa<BlockDecl>(Callee))
- Out << "Entering call to block";
- else if (const NamedDecl *ND = dyn_cast<NamedDecl>(Callee))
- Out << "Entering call to '" << *ND << "'";
- StringRef msg = Out.str();
- if (msg.empty())
- return 0;
- return new PathDiagnosticEventPiece(callEnter, msg);
-}
-
-IntrusiveRefCntPtr<PathDiagnosticEventPiece>
-PathDiagnosticCallPiece::getCallExitEvent() const {
- if (!Caller)
- return 0;
- SmallString<256> buf;
- llvm::raw_svector_ostream Out(buf);
- if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(Caller))
- Out << "Returning to '" << *ND << "'";
- else
- Out << "Returning to caller";
- return new PathDiagnosticEventPiece(callReturn, Out.str());
-}
-
//===----------------------------------------------------------------------===//
// FoldingSet profiling methods.
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp?rev=151338&r1=151337&r2=151338&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp Thu Feb 23 20:06:33 2012
@@ -240,33 +240,6 @@
Indent(o, indent); o << "</dict>\n";
}
-static void ReportPiece(raw_ostream &o,
- const PathDiagnosticPiece &P,
- const FIDMap& FM, const SourceManager &SM,
- const LangOptions &LangOpts,
- unsigned indent,
- bool includeControlFlow);
-
-static void ReportCall(raw_ostream &o,
- const PathDiagnosticCallPiece &P,
- const FIDMap& FM, const SourceManager &SM,
- const LangOptions &LangOpts,
- unsigned indent) {
-
- IntrusiveRefCntPtr<PathDiagnosticEventPiece> callExit =
- P.getCallExitEvent();
- if (callExit)
- ReportPiece(o, *callExit, FM, SM, LangOpts, indent, true);
-
- for (PathPieces::const_iterator I = P.path.begin(), E = P.path.end();I!=E;++I)
- ReportPiece(o, **I, FM, SM, LangOpts, indent, true);
-
- IntrusiveRefCntPtr<PathDiagnosticEventPiece> callEnter =
- P.getCallEnterEvent();
- if (callEnter)
- ReportPiece(o, *callEnter, FM, SM, LangOpts, indent, true);
-}
-
static void ReportMacro(raw_ostream &o,
const PathDiagnosticMacroPiece& P,
const FIDMap& FM, const SourceManager &SM,
@@ -275,40 +248,43 @@
for (PathPieces::const_iterator I = P.subPieces.begin(), E=P.subPieces.end();
I!=E; ++I) {
- ReportPiece(o, **I, FM, SM, LangOpts, indent, false);
- }
-}
-
-static void ReportDiag(raw_ostream &o, const PathDiagnosticPiece& P,
- const FIDMap& FM, const SourceManager &SM,
- const LangOptions &LangOpts) {
- ReportPiece(o, P, FM, SM, LangOpts, 4, true);
-}
-static void ReportPiece(raw_ostream &o,
- const PathDiagnosticPiece &P,
- const FIDMap& FM, const SourceManager &SM,
- const LangOptions &LangOpts,
- unsigned indent,
- bool includeControlFlow) {
- switch (P.getKind()) {
- case PathDiagnosticPiece::ControlFlow:
- if (includeControlFlow)
- ReportControlFlow(o, cast<PathDiagnosticControlFlowPiece>(P), FM, SM,
- LangOpts, indent);
- break;
- case PathDiagnosticPiece::Call:
- ReportCall(o, cast<PathDiagnosticCallPiece>(P), FM, SM, LangOpts,
- indent);
+ switch ((*I)->getKind()) {
+ default:
break;
case PathDiagnosticPiece::Event:
- ReportEvent(o, cast<PathDiagnosticSpotPiece>(P), FM, SM, LangOpts,
+ ReportEvent(o, cast<PathDiagnosticEventPiece>(**I), FM, SM, LangOpts,
indent);
break;
case PathDiagnosticPiece::Macro:
- ReportMacro(o, cast<PathDiagnosticMacroPiece>(P), FM, SM, LangOpts,
+ ReportMacro(o, cast<PathDiagnosticMacroPiece>(**I), FM, SM, LangOpts,
indent);
break;
+ }
+ }
+}
+
+static void ReportDiag(raw_ostream &o, const PathDiagnosticPiece& P,
+ const FIDMap& FM, const SourceManager &SM,
+ const LangOptions &LangOpts) {
+
+ unsigned indent = 4;
+
+ switch (P.getKind()) {
+ case PathDiagnosticPiece::ControlFlow:
+ ReportControlFlow(o, cast<PathDiagnosticControlFlowPiece>(P), FM, SM,
+ LangOpts, indent);
+ break;
+ case PathDiagnosticPiece::CallEnter:
+ case PathDiagnosticPiece::CallExit:
+ case PathDiagnosticPiece::Event:
+ ReportEvent(o, cast<PathDiagnosticSpotPiece>(P), FM, SM, LangOpts,
+ indent);
+ break;
+ case PathDiagnosticPiece::Macro:
+ ReportMacro(o, cast<PathDiagnosticMacroPiece>(P), FM, SM, LangOpts,
+ indent);
+ break;
}
}
More information about the cfe-commits
mailing list