summaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Core/BugReporter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/StaticAnalyzer/Core/BugReporter.cpp')
-rw-r--r--lib/StaticAnalyzer/Core/BugReporter.cpp298
1 files changed, 151 insertions, 147 deletions
diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp
index 53b4e699f7ad..2114033ba8b5 100644
--- a/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -111,15 +111,15 @@ static void removeRedundantMsgs(PathPieces &path) {
// grabbing the front, processing it, and if we decide to keep it append
// it to the end of the path. The entire path is processed in this way.
for (unsigned i = 0; i < N; ++i) {
- IntrusiveRefCntPtr<PathDiagnosticPiece> piece(path.front());
+ auto piece = std::move(path.front());
path.pop_front();
switch (piece->getKind()) {
case PathDiagnosticPiece::Call:
- removeRedundantMsgs(cast<PathDiagnosticCallPiece>(piece)->path);
+ removeRedundantMsgs(cast<PathDiagnosticCallPiece>(*piece).path);
break;
case PathDiagnosticPiece::Macro:
- removeRedundantMsgs(cast<PathDiagnosticMacroPiece>(piece)->subPieces);
+ removeRedundantMsgs(cast<PathDiagnosticMacroPiece>(*piece).subPieces);
break;
case PathDiagnosticPiece::ControlFlow:
break;
@@ -130,13 +130,13 @@ static void removeRedundantMsgs(PathPieces &path) {
if (PathDiagnosticEventPiece *nextEvent =
dyn_cast<PathDiagnosticEventPiece>(path.front().get())) {
PathDiagnosticEventPiece *event =
- cast<PathDiagnosticEventPiece>(piece);
+ cast<PathDiagnosticEventPiece>(piece.get());
// Check to see if we should keep one of the two pieces. If we
// come up with a preference, record which piece to keep, and consume
// another piece from the path.
- if (PathDiagnosticEventPiece *pieceToKeep =
- eventsDescribeSameCondition(event, nextEvent)) {
- piece = pieceToKeep;
+ if (auto *pieceToKeep =
+ eventsDescribeSameCondition(event, nextEvent)) {
+ piece = std::move(pieceToKeep == event ? piece : path.front());
path.pop_front();
++i;
}
@@ -146,7 +146,7 @@ static void removeRedundantMsgs(PathPieces &path) {
case PathDiagnosticPiece::Note:
break;
}
- path.push_back(piece);
+ path.push_back(std::move(piece));
}
}
@@ -166,38 +166,38 @@ static bool removeUnneededCalls(PathPieces &pieces, BugReport *R,
for (unsigned i = 0 ; i < N ; ++i) {
// Remove the front piece from the path. If it is still something we
// want to keep once we are done, we will push it back on the end.
- IntrusiveRefCntPtr<PathDiagnosticPiece> piece(pieces.front());
+ auto piece = std::move(pieces.front());
pieces.pop_front();
switch (piece->getKind()) {
case PathDiagnosticPiece::Call: {
- PathDiagnosticCallPiece *call = cast<PathDiagnosticCallPiece>(piece);
+ auto &call = cast<PathDiagnosticCallPiece>(*piece);
// Check if the location context is interesting.
- assert(LCM.count(&call->path));
- if (R->isInteresting(LCM[&call->path])) {
+ assert(LCM.count(&call.path));
+ if (R->isInteresting(LCM[&call.path])) {
containsSomethingInteresting = true;
break;
}
- if (!removeUnneededCalls(call->path, R, LCM))
+ if (!removeUnneededCalls(call.path, R, LCM))
continue;
containsSomethingInteresting = true;
break;
}
case PathDiagnosticPiece::Macro: {
- PathDiagnosticMacroPiece *macro = cast<PathDiagnosticMacroPiece>(piece);
- if (!removeUnneededCalls(macro->subPieces, R, LCM))
+ auto &macro = cast<PathDiagnosticMacroPiece>(*piece);
+ if (!removeUnneededCalls(macro.subPieces, R, LCM))
continue;
containsSomethingInteresting = true;
break;
}
case PathDiagnosticPiece::Event: {
- PathDiagnosticEventPiece *event = cast<PathDiagnosticEventPiece>(piece);
+ auto &event = cast<PathDiagnosticEventPiece>(*piece);
// We never throw away an event, but we do throw it away wholesale
// as part of a path if we throw the entire path away.
- containsSomethingInteresting |= !event->isPrunable();
+ containsSomethingInteresting |= !event.isPrunable();
break;
}
case PathDiagnosticPiece::ControlFlow:
@@ -207,7 +207,7 @@ static bool removeUnneededCalls(PathPieces &pieces, BugReport *R,
break;
}
- pieces.push_back(piece);
+ pieces.push_back(std::move(piece));
}
return containsSomethingInteresting;
@@ -226,7 +226,7 @@ static void
adjustCallLocations(PathPieces &Pieces,
PathDiagnosticLocation *LastCallLocation = nullptr) {
for (PathPieces::iterator I = Pieces.begin(), E = Pieces.end(); I != E; ++I) {
- PathDiagnosticCallPiece *Call = dyn_cast<PathDiagnosticCallPiece>(*I);
+ PathDiagnosticCallPiece *Call = dyn_cast<PathDiagnosticCallPiece>(I->get());
if (!Call) {
assert((*I)->getLocation().asLocation().isValid());
@@ -260,14 +260,13 @@ adjustCallLocations(PathPieces &Pieces,
/// explicitly in a constructor or braced list.
static void removeEdgesToDefaultInitializers(PathPieces &Pieces) {
for (PathPieces::iterator I = Pieces.begin(), E = Pieces.end(); I != E;) {
- if (PathDiagnosticCallPiece *C = dyn_cast<PathDiagnosticCallPiece>(*I))
+ if (auto *C = dyn_cast<PathDiagnosticCallPiece>(I->get()))
removeEdgesToDefaultInitializers(C->path);
- if (PathDiagnosticMacroPiece *M = dyn_cast<PathDiagnosticMacroPiece>(*I))
+ if (auto *M = dyn_cast<PathDiagnosticMacroPiece>(I->get()))
removeEdgesToDefaultInitializers(M->subPieces);
- if (PathDiagnosticControlFlowPiece *CF =
- dyn_cast<PathDiagnosticControlFlowPiece>(*I)) {
+ if (auto *CF = dyn_cast<PathDiagnosticControlFlowPiece>(I->get())) {
const Stmt *Start = CF->getStartLocation().asStmt();
const Stmt *End = CF->getEndLocation().asStmt();
if (Start && isa<CXXDefaultInitExpr>(Start)) {
@@ -276,8 +275,8 @@ static void removeEdgesToDefaultInitializers(PathPieces &Pieces) {
} else if (End && isa<CXXDefaultInitExpr>(End)) {
PathPieces::iterator Next = std::next(I);
if (Next != E) {
- if (PathDiagnosticControlFlowPiece *NextCF =
- dyn_cast<PathDiagnosticControlFlowPiece>(*Next)) {
+ if (auto *NextCF =
+ dyn_cast<PathDiagnosticControlFlowPiece>(Next->get())) {
NextCF->setStartLocation(CF->getStartLocation());
}
}
@@ -295,10 +294,10 @@ static void removeEdgesToDefaultInitializers(PathPieces &Pieces) {
/// Farm generated functions.
static void removePiecesWithInvalidLocations(PathPieces &Pieces) {
for (PathPieces::iterator I = Pieces.begin(), E = Pieces.end(); I != E;) {
- if (PathDiagnosticCallPiece *C = dyn_cast<PathDiagnosticCallPiece>(*I))
+ if (auto *C = dyn_cast<PathDiagnosticCallPiece>(I->get()))
removePiecesWithInvalidLocations(C->path);
- if (PathDiagnosticMacroPiece *M = dyn_cast<PathDiagnosticMacroPiece>(*I))
+ if (auto *M = dyn_cast<PathDiagnosticMacroPiece>(I->get()))
removePiecesWithInvalidLocations(M->subPieces);
if (!(*I)->getLocation().isValid() ||
@@ -518,11 +517,9 @@ static bool GenerateVisitorsOnlyPathDiagnostic(
BugReport *R = PDB.getBugReport();
while (const ExplodedNode *Pred = N->getFirstPred()) {
- for (auto &V : visitors) {
+ for (auto &V : visitors)
// Visit all the node pairs, but throw the path pieces away.
- PathDiagnosticPiece *Piece = V->VisitNode(N, Pred, PDB, *R);
- delete Piece;
- }
+ V->VisitNode(N, Pred, PDB, *R);
N = Pred;
}
@@ -536,12 +533,11 @@ static bool GenerateVisitorsOnlyPathDiagnostic(
typedef std::pair<PathDiagnosticCallPiece*, const ExplodedNode*> StackDiagPair;
typedef SmallVector<StackDiagPair, 6> StackDiagVector;
-static void updateStackPiecesWithMessage(PathDiagnosticPiece *P,
+static void updateStackPiecesWithMessage(PathDiagnosticPiece &P,
StackDiagVector &CallStack) {
// If the piece contains a special message, add it to all the call
// pieces on the active stack.
- if (PathDiagnosticEventPiece *ep =
- dyn_cast<PathDiagnosticEventPiece>(P)) {
+ if (PathDiagnosticEventPiece *ep = dyn_cast<PathDiagnosticEventPiece>(&P)) {
if (ep->hasCallStackHint())
for (StackDiagVector::iterator I = CallStack.begin(),
@@ -582,13 +578,13 @@ static bool GenerateMinimalPathDiagnostic(
do {
if (Optional<CallExitEnd> CE = P.getAs<CallExitEnd>()) {
- PathDiagnosticCallPiece *C =
- PathDiagnosticCallPiece::construct(N, *CE, SMgr);
+ auto C = PathDiagnosticCallPiece::construct(N, *CE, SMgr);
// Record the mapping from call piece to LocationContext.
LCM[&C->path] = CE->getCalleeContext();
- PD.getActivePath().push_front(C);
- PD.pushActivePath(&C->path);
- CallStack.push_back(StackDiagPair(C, N));
+ auto *P = C.get();
+ PD.getActivePath().push_front(std::move(C));
+ PD.pushActivePath(&P->path);
+ CallStack.push_back(StackDiagPair(P, N));
break;
}
@@ -604,7 +600,7 @@ static bool GenerateMinimalPathDiagnostic(
// a new PathDiagnosticCallPiece.
PathDiagnosticCallPiece *C;
if (VisitedEntireCall) {
- C = cast<PathDiagnosticCallPiece>(PD.getActivePath().front());
+ C = cast<PathDiagnosticCallPiece>(PD.getActivePath().front().get());
} else {
const Decl *Caller = CE->getLocationContext()->getDecl();
C = PathDiagnosticCallPiece::construct(PD.getActivePath(), Caller);
@@ -649,8 +645,9 @@ static bool GenerateMinimalPathDiagnostic(
os << "Control jumps to line "
<< End.asLocation().getExpansionLineNumber();
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(Start, End,
+ os.str()));
break;
}
@@ -701,14 +698,16 @@ static bool GenerateMinimalPathDiagnostic(
break;
}
}
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<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, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(Start, End,
+ os.str()));
}
break;
@@ -719,8 +718,9 @@ static bool GenerateMinimalPathDiagnostic(
std::string sbuf;
llvm::raw_string_ostream os(sbuf);
PathDiagnosticLocation End = PDB.ExecutionContinues(os, N);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(Start, End,
+ os.str()));
break;
}
@@ -741,8 +741,9 @@ static bool GenerateMinimalPathDiagnostic(
if (const Stmt *S = End.asStmt())
End = PDB.getEnclosingStmtLocation(S);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(Start, End,
+ os.str()));
break;
}
@@ -764,15 +765,17 @@ static bool GenerateMinimalPathDiagnostic(
PathDiagnosticLocation End(B->getLHS(), SMgr, LC);
PathDiagnosticLocation Start =
PathDiagnosticLocation::createOperatorLoc(B, SMgr);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<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, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(Start, End,
+ os.str()));
}
}
else {
@@ -783,16 +786,18 @@ static bool GenerateMinimalPathDiagnostic(
os << "false";
PathDiagnosticLocation Start(B->getLHS(), SMgr, LC);
PathDiagnosticLocation End = PDB.ExecutionContinues(N);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(Start, End,
+ os.str()));
}
else {
os << "true";
PathDiagnosticLocation End(B->getLHS(), SMgr, LC);
PathDiagnosticLocation Start =
PathDiagnosticLocation::createOperatorLoc(B, SMgr);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(Start, End,
+ os.str()));
}
}
@@ -810,8 +815,9 @@ static bool GenerateMinimalPathDiagnostic(
if (const Stmt *S = End.asStmt())
End = PDB.getEnclosingStmtLocation(S);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(Start, End,
+ os.str()));
}
else {
PathDiagnosticLocation End = PDB.ExecutionContinues(N);
@@ -819,8 +825,9 @@ static bool GenerateMinimalPathDiagnostic(
if (const Stmt *S = End.asStmt())
End = PDB.getEnclosingStmtLocation(S);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, "Loop condition is false. Exiting loop"));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(
+ Start, End, "Loop condition is false. Exiting loop"));
}
break;
@@ -837,16 +844,18 @@ static bool GenerateMinimalPathDiagnostic(
if (const Stmt *S = End.asStmt())
End = PDB.getEnclosingStmtLocation(S);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, os.str()));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(Start, End,
+ os.str()));
}
else {
PathDiagnosticLocation End = PDB.ExecutionContinues(N);
if (const Stmt *S = End.asStmt())
End = PDB.getEnclosingStmtLocation(S);
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, "Loop condition is true. Entering loop body"));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(
+ Start, End, "Loop condition is true. Entering loop body"));
}
break;
@@ -859,11 +868,13 @@ static bool GenerateMinimalPathDiagnostic(
End = PDB.getEnclosingStmtLocation(S);
if (*(Src->succ_begin()+1) == Dst)
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, "Taking false branch"));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(
+ Start, End, "Taking false branch"));
else
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(
- Start, End, "Taking true branch"));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(
+ Start, End, "Taking true branch"));
break;
}
@@ -875,9 +886,9 @@ static bool GenerateMinimalPathDiagnostic(
// Add diagnostic pieces from custom visitors.
BugReport *R = PDB.getBugReport();
for (auto &V : visitors) {
- if (PathDiagnosticPiece *p = V->VisitNode(N, NextNode, PDB, *R)) {
- PD.getActivePath().push_front(p);
- updateStackPiecesWithMessage(p, CallStack);
+ if (auto p = V->VisitNode(N, NextNode, PDB, *R)) {
+ updateStackPiecesWithMessage(*p, CallStack);
+ PD.getActivePath().push_front(std::move(p));
}
}
}
@@ -1118,7 +1129,9 @@ void EdgeBuilder::rawAddEdge(PathDiagnosticLocation NewLoc) {
PrevLocClean.asLocation().getExpansionLoc())
return;
- PD.getActivePath().push_front(new PathDiagnosticControlFlowPiece(NewLocClean, PrevLocClean));
+ PD.getActivePath().push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(NewLocClean,
+ PrevLocClean));
PrevLoc = NewLoc;
}
@@ -1423,16 +1436,16 @@ static bool GenerateExtensivePathDiagnostic(
N->getLocationContext());
}
- PathDiagnosticCallPiece *C =
- PathDiagnosticCallPiece::construct(N, *CE, SM);
+ auto C = PathDiagnosticCallPiece::construct(N, *CE, SM);
LCM[&C->path] = CE->getCalleeContext();
EB.addEdge(C->callReturn, /*AlwaysAdd=*/true, /*IsPostJump=*/true);
EB.flushLocations();
- PD.getActivePath().push_front(C);
- PD.pushActivePath(&C->path);
- CallStack.push_back(StackDiagPair(C, N));
+ auto *P = C.get();
+ PD.getActivePath().push_front(std::move(C));
+ PD.pushActivePath(&P->path);
+ CallStack.push_back(StackDiagPair(P, N));
break;
}
@@ -1458,7 +1471,7 @@ static bool GenerateExtensivePathDiagnostic(
// a new PathDiagnosticCallPiece.
PathDiagnosticCallPiece *C;
if (VisitedEntireCall) {
- C = cast<PathDiagnosticCallPiece>(PD.getActivePath().front());
+ C = cast<PathDiagnosticCallPiece>(PD.getActivePath().front().get());
} else {
const Decl *Caller = CE->getLocationContext()->getDecl();
C = PathDiagnosticCallPiece::construct(PD.getActivePath(), Caller);
@@ -1505,13 +1518,12 @@ static bool GenerateExtensivePathDiagnostic(
else if (const WhileStmt *WS = dyn_cast<WhileStmt>(Loop))
CS = dyn_cast<CompoundStmt>(WS->getBody());
- PathDiagnosticEventPiece *p =
- new PathDiagnosticEventPiece(L,
- "Looping back to the head of the loop");
+ auto p = std::make_shared<PathDiagnosticEventPiece>(
+ L, "Looping back to the head of the loop");
p->setPrunable(true);
EB.addEdge(p->getLocation(), true);
- PD.getActivePath().push_front(p);
+ PD.getActivePath().push_front(std::move(p));
if (CS) {
PathDiagnosticLocation BL =
@@ -1533,12 +1545,12 @@ static bool GenerateExtensivePathDiagnostic(
N),
Term)) {
PathDiagnosticLocation L(Term, SM, PDB.LC);
- PathDiagnosticEventPiece *PE =
- new PathDiagnosticEventPiece(L, "Loop body executed 0 times");
+ auto PE = std::make_shared<PathDiagnosticEventPiece>(
+ L, "Loop body executed 0 times");
PE->setPrunable(true);
EB.addEdge(PE->getLocation(), true);
- PD.getActivePath().push_front(PE);
+ PD.getActivePath().push_front(std::move(PE));
}
// In any case, add the terminator as the current statement
@@ -1573,11 +1585,11 @@ static bool GenerateExtensivePathDiagnostic(
// Add pieces from custom visitors.
BugReport *R = PDB.getBugReport();
for (auto &V : visitors) {
- if (PathDiagnosticPiece *p = V->VisitNode(N, NextNode, PDB, *R)) {
+ if (auto p = V->VisitNode(N, NextNode, PDB, *R)) {
const PathDiagnosticLocation &Loc = p->getLocation();
EB.addEdge(Loc, true);
- PD.getActivePath().push_front(p);
- updateStackPiecesWithMessage(p, CallStack);
+ updateStackPiecesWithMessage(*p, CallStack);
+ PD.getActivePath().push_front(std::move(p));
if (const Stmt *S = Loc.asStmt())
EB.addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt());
@@ -1610,8 +1622,8 @@ static void addEdgeToPath(PathPieces &path,
if (NewLoc.asStmt() && NewLoc.asStmt() == PrevLoc.asStmt())
return;
- path.push_front(new PathDiagnosticControlFlowPiece(NewLoc,
- PrevLoc));
+ path.push_front(
+ std::make_shared<PathDiagnosticControlFlowPiece>(NewLoc, PrevLoc));
PrevLoc = NewLoc;
}
@@ -1678,7 +1690,7 @@ static bool GenerateAlternateExtensivePathDiagnostic(
// Since we just transferred the path over to the call piece,
// reset the mapping from active to location context.
assert(PD.getActivePath().size() == 1 &&
- PD.getActivePath().front() == C);
+ PD.getActivePath().front().get() == C);
LCM[&PD.getActivePath()] = nullptr;
// Record the location context mapping for the path within
@@ -1729,20 +1741,20 @@ static bool GenerateAlternateExtensivePathDiagnostic(
// We are descending into a call (backwards). Construct
// a new call piece to contain the path pieces for that call.
- PathDiagnosticCallPiece *C =
- PathDiagnosticCallPiece::construct(N, *CE, SM);
+ auto C = PathDiagnosticCallPiece::construct(N, *CE, SM);
// Record the location context for this call piece.
LCM[&C->path] = CE->getCalleeContext();
// Add the edge to the return site.
addEdgeToPath(PD.getActivePath(), PrevLoc, C->callReturn, PDB.LC);
- PD.getActivePath().push_front(C);
+ auto *P = C.get();
+ PD.getActivePath().push_front(std::move(C));
PrevLoc.invalidate();
// Make the contents of the call the active path for now.
- PD.pushActivePath(&C->path);
- CallStack.push_back(StackDiagPair(C, N));
+ PD.pushActivePath(&P->path);
+ CallStack.push_back(StackDiagPair(P, N));
break;
}
@@ -1797,13 +1809,13 @@ static bool GenerateAlternateExtensivePathDiagnostic(
}
// do-while statements are explicitly excluded here
- PathDiagnosticEventPiece *p =
- new PathDiagnosticEventPiece(L, "Looping back to the head "
- "of the loop");
+ auto p = std::make_shared<PathDiagnosticEventPiece>(
+ L, "Looping back to the head "
+ "of the loop");
p->setPrunable(true);
addEdgeToPath(PD.getActivePath(), PrevLoc, p->getLocation(), PDB.LC);
- PD.getActivePath().push_front(p);
+ PD.getActivePath().push_front(std::move(p));
if (const CompoundStmt *CS = dyn_cast_or_null<CompoundStmt>(Body)) {
addEdgeToPath(PD.getActivePath(), PrevLoc,
@@ -1841,12 +1853,11 @@ static bool GenerateAlternateExtensivePathDiagnostic(
if (str) {
PathDiagnosticLocation L(TermCond ? TermCond : Term, SM, PDB.LC);
- PathDiagnosticEventPiece *PE =
- new PathDiagnosticEventPiece(L, str);
+ auto PE = std::make_shared<PathDiagnosticEventPiece>(L, str);
PE->setPrunable(true);
addEdgeToPath(PD.getActivePath(), PrevLoc,
PE->getLocation(), PDB.LC);
- PD.getActivePath().push_front(PE);
+ PD.getActivePath().push_front(std::move(PE));
}
} else if (isa<BreakStmt>(Term) || isa<ContinueStmt>(Term) ||
isa<GotoStmt>(Term)) {
@@ -1863,10 +1874,10 @@ static bool GenerateAlternateExtensivePathDiagnostic(
// Add pieces from custom visitors.
for (auto &V : visitors) {
- if (PathDiagnosticPiece *p = V->VisitNode(N, NextNode, PDB, *report)) {
+ if (auto p = V->VisitNode(N, NextNode, PDB, *report)) {
addEdgeToPath(PD.getActivePath(), PrevLoc, p->getLocation(), PDB.LC);
- PD.getActivePath().push_front(p);
- updateStackPiecesWithMessage(p, CallStack);
+ updateStackPiecesWithMessage(*p, CallStack);
+ PD.getActivePath().push_front(std::move(p));
}
}
}
@@ -1973,7 +1984,7 @@ static void addContextEdges(PathPieces &pieces, SourceManager &SM,
for (PathPieces::iterator I = pieces.begin(), E = Prev; I != E;
Prev = I, ++I) {
PathDiagnosticControlFlowPiece *Piece =
- dyn_cast<PathDiagnosticControlFlowPiece>(*I);
+ dyn_cast<PathDiagnosticControlFlowPiece>(I->get());
if (!Piece)
continue;
@@ -2014,8 +2025,7 @@ static void addContextEdges(PathPieces &pieces, SourceManager &SM,
// Try to extend the previous edge if it's at the same level as the source
// context.
if (Prev != E) {
- PathDiagnosticControlFlowPiece *PrevPiece =
- dyn_cast<PathDiagnosticControlFlowPiece>(*Prev);
+ auto *PrevPiece = dyn_cast<PathDiagnosticControlFlowPiece>(Prev->get());
if (PrevPiece) {
if (const Stmt *PrevSrc = getLocStmt(PrevPiece->getStartLocation())) {
@@ -2031,8 +2041,10 @@ static void addContextEdges(PathPieces &pieces, SourceManager &SM,
// Otherwise, split the current edge into a context edge and a
// subexpression edge. Note that the context statement may itself have
// context.
- Piece = new PathDiagnosticControlFlowPiece(SrcLoc, DstContext);
- I = pieces.insert(I, Piece);
+ auto P =
+ std::make_shared<PathDiagnosticControlFlowPiece>(SrcLoc, DstContext);
+ Piece = P.get();
+ I = pieces.insert(I, std::move(P));
}
}
}
@@ -2051,8 +2063,7 @@ static void addContextEdges(PathPieces &pieces, SourceManager &SM,
static void simplifySimpleBranches(PathPieces &pieces) {
for (PathPieces::iterator I = pieces.begin(), E = pieces.end(); I != E; ++I) {
- PathDiagnosticControlFlowPiece *PieceI =
- dyn_cast<PathDiagnosticControlFlowPiece>(*I);
+ auto *PieceI = dyn_cast<PathDiagnosticControlFlowPiece>(I->get());
if (!PieceI)
continue;
@@ -2073,7 +2084,7 @@ static void simplifySimpleBranches(PathPieces &pieces) {
if (NextI == E)
break;
- PathDiagnosticEventPiece *EV = dyn_cast<PathDiagnosticEventPiece>(*NextI);
+ auto *EV = dyn_cast<PathDiagnosticEventPiece>(NextI->get());
if (EV) {
StringRef S = EV->getString();
if (S == StrEnteringLoop || S == StrLoopBodyZero ||
@@ -2084,7 +2095,7 @@ static void simplifySimpleBranches(PathPieces &pieces) {
break;
}
- PieceNextI = dyn_cast<PathDiagnosticControlFlowPiece>(*NextI);
+ PieceNextI = dyn_cast<PathDiagnosticControlFlowPiece>(NextI->get());
break;
}
@@ -2176,7 +2187,7 @@ static void removeContextCycles(PathPieces &Path, SourceManager &SM,
for (PathPieces::iterator I = Path.begin(), E = Path.end(); I != E; ) {
// Pattern match the current piece and its successor.
PathDiagnosticControlFlowPiece *PieceI =
- dyn_cast<PathDiagnosticControlFlowPiece>(*I);
+ dyn_cast<PathDiagnosticControlFlowPiece>(I->get());
if (!PieceI) {
++I;
@@ -2191,14 +2202,14 @@ static void removeContextCycles(PathPieces &Path, SourceManager &SM,
break;
PathDiagnosticControlFlowPiece *PieceNextI =
- dyn_cast<PathDiagnosticControlFlowPiece>(*NextI);
+ dyn_cast<PathDiagnosticControlFlowPiece>(NextI->get());
if (!PieceNextI) {
- if (isa<PathDiagnosticEventPiece>(*NextI)) {
+ if (isa<PathDiagnosticEventPiece>(NextI->get())) {
++NextI;
if (NextI == E)
break;
- PieceNextI = dyn_cast<PathDiagnosticControlFlowPiece>(*NextI);
+ PieceNextI = dyn_cast<PathDiagnosticControlFlowPiece>(NextI->get());
}
if (!PieceNextI) {
@@ -2251,8 +2262,7 @@ static void removePunyEdges(PathPieces &path,
erased = false;
- PathDiagnosticControlFlowPiece *PieceI =
- dyn_cast<PathDiagnosticControlFlowPiece>(*I);
+ auto *PieceI = dyn_cast<PathDiagnosticControlFlowPiece>(I->get());
if (!PieceI)
continue;
@@ -2299,8 +2309,7 @@ static void removePunyEdges(PathPieces &path,
static void removeIdenticalEvents(PathPieces &path) {
for (PathPieces::iterator I = path.begin(), E = path.end(); I != E; ++I) {
- PathDiagnosticEventPiece *PieceI =
- dyn_cast<PathDiagnosticEventPiece>(*I);
+ auto *PieceI = dyn_cast<PathDiagnosticEventPiece>(I->get());
if (!PieceI)
continue;
@@ -2309,8 +2318,7 @@ static void removeIdenticalEvents(PathPieces &path) {
if (NextI == E)
return;
- PathDiagnosticEventPiece *PieceNextI =
- dyn_cast<PathDiagnosticEventPiece>(*NextI);
+ auto *PieceNextI = dyn_cast<PathDiagnosticEventPiece>(NextI->get());
if (!PieceNextI)
continue;
@@ -2332,7 +2340,7 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
for (PathPieces::iterator I = path.begin(), E = path.end(); I != E; ) {
// Optimize subpaths.
- if (PathDiagnosticCallPiece *CallI = dyn_cast<PathDiagnosticCallPiece>(*I)){
+ if (auto *CallI = dyn_cast<PathDiagnosticCallPiece>(I->get())) {
// Record the fact that a call has been optimized so we only do the
// effort once.
if (!OCS.count(CallI)) {
@@ -2344,8 +2352,7 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
}
// Pattern match the current piece and its successor.
- PathDiagnosticControlFlowPiece *PieceI =
- dyn_cast<PathDiagnosticControlFlowPiece>(*I);
+ auto *PieceI = dyn_cast<PathDiagnosticControlFlowPiece>(I->get());
if (!PieceI) {
++I;
@@ -2361,8 +2368,7 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
if (NextI == E)
break;
- PathDiagnosticControlFlowPiece *PieceNextI =
- dyn_cast<PathDiagnosticControlFlowPiece>(*NextI);
+ auto *PieceNextI = dyn_cast<PathDiagnosticControlFlowPiece>(NextI->get());
if (!PieceNextI) {
++I;
@@ -2511,8 +2517,8 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
static void dropFunctionEntryEdge(PathPieces &Path,
LocationContextMap &LCM,
SourceManager &SM) {
- const PathDiagnosticControlFlowPiece *FirstEdge =
- dyn_cast<PathDiagnosticControlFlowPiece>(Path.front());
+ const auto *FirstEdge =
+ dyn_cast<PathDiagnosticControlFlowPiece>(Path.front().get());
if (!FirstEdge)
return;
@@ -2967,11 +2973,11 @@ bool TrimmedGraph::popNextReportGraph(ReportGraph &GraphWrapper) {
/// CompactPathDiagnostic - This function postprocesses a PathDiagnostic object
/// and collapses PathDiagosticPieces that are expanded by macros.
static void CompactPathDiagnostic(PathPieces &path, const SourceManager& SM) {
- typedef std::vector<std::pair<IntrusiveRefCntPtr<PathDiagnosticMacroPiece>,
- SourceLocation> > MacroStackTy;
+ typedef std::vector<
+ std::pair<std::shared_ptr<PathDiagnosticMacroPiece>, SourceLocation>>
+ MacroStackTy;
- typedef std::vector<IntrusiveRefCntPtr<PathDiagnosticPiece> >
- PiecesTy;
+ typedef std::vector<std::shared_ptr<PathDiagnosticPiece>> PiecesTy;
MacroStackTy MacroStack;
PiecesTy Pieces;
@@ -2979,10 +2985,10 @@ static void CompactPathDiagnostic(PathPieces &path, const SourceManager& SM) {
for (PathPieces::const_iterator I = path.begin(), E = path.end();
I!=E; ++I) {
- PathDiagnosticPiece *piece = I->get();
+ auto &piece = *I;
// Recursively compact calls.
- if (PathDiagnosticCallPiece *call=dyn_cast<PathDiagnosticCallPiece>(piece)){
+ if (auto *call = dyn_cast<PathDiagnosticCallPiece>(&*piece)) {
CompactPathDiagnostic(call->path, SM);
}
@@ -3011,7 +3017,7 @@ static void CompactPathDiagnostic(PathPieces &path, const SourceManager& SM) {
// We aren't in the same group. Are we descending into a new macro
// or are part of an old one?
- IntrusiveRefCntPtr<PathDiagnosticMacroPiece> MacroGroup;
+ std::shared_ptr<PathDiagnosticMacroPiece> MacroGroup;
SourceLocation ParentInstantiationLoc = InstantiationLoc.isMacroID() ?
SM.getExpansionLoc(Loc) :
@@ -3034,8 +3040,7 @@ static void CompactPathDiagnostic(PathPieces &path, const SourceManager& SM) {
if (!MacroGroup || ParentInstantiationLoc == MacroStack.back().second) {
// Create a new macro group and add it to the stack.
- PathDiagnosticMacroPiece *NewGroup =
- new PathDiagnosticMacroPiece(
+ auto NewGroup = std::make_shared<PathDiagnosticMacroPiece>(
PathDiagnosticLocation::createSingleLocation(piece->getLocation()));
if (MacroGroup)
@@ -3477,13 +3482,12 @@ void BugReporter::FlushReport(BugReport *exampleReport,
for (auto I = exampleReport->getNotes().rbegin(),
E = exampleReport->getNotes().rend(); I != E; ++I) {
PathDiagnosticNotePiece *Piece = I->get();
- PathDiagnosticEventPiece *ConvertedPiece =
- new PathDiagnosticEventPiece(Piece->getLocation(),
- Piece->getString());
+ auto ConvertedPiece = std::make_shared<PathDiagnosticEventPiece>(
+ Piece->getLocation(), Piece->getString());
for (const auto &R: Piece->getRanges())
ConvertedPiece->addRange(R);
- Pieces.push_front(ConvertedPiece);
+ Pieces.push_front(std::move(ConvertedPiece));
}
} else {
for (auto I = exampleReport->getNotes().rbegin(),