unique_ptr-ify PathDiagnosticPiece ownership

llvm-svn: 216751
This commit is contained in:
David Blaikie 2014-08-29 18:18:43 +00:00
parent f6ee7a7cdd
commit d15481ccea
5 changed files with 39 additions and 46 deletions

View File

@ -66,17 +66,15 @@ public:
/// If returns NULL the default implementation will be used. /// If returns NULL the default implementation will be used.
/// Also note that at most one visitor of a BugReport should generate a /// Also note that at most one visitor of a BugReport should generate a
/// non-NULL end of path diagnostic piece. /// non-NULL end of path diagnostic piece.
virtual PathDiagnosticPiece *getEndPath(BugReporterContext &BRC, virtual std::unique_ptr<PathDiagnosticPiece>
const ExplodedNode *N, getEndPath(BugReporterContext &BRC, const ExplodedNode *N, BugReport &BR);
BugReport &BR);
virtual void Profile(llvm::FoldingSetNodeID &ID) const = 0; virtual void Profile(llvm::FoldingSetNodeID &ID) const = 0;
/// \brief Generates the default final diagnostic piece. /// \brief Generates the default final diagnostic piece.
static PathDiagnosticPiece *getDefaultEndPath(BugReporterContext &BRC, static std::unique_ptr<PathDiagnosticPiece>
const ExplodedNode *N, getDefaultEndPath(BugReporterContext &BRC, const ExplodedNode *N,
BugReport &BR); BugReport &BR);
}; };
/// This class provides a convenience implementation for clone() using the /// This class provides a convenience implementation for clone() using the
@ -268,7 +266,7 @@ public:
return nullptr; return nullptr;
} }
PathDiagnosticPiece *getEndPath(BugReporterContext &BRC, std::unique_ptr<PathDiagnosticPiece> getEndPath(BugReporterContext &BRC,
const ExplodedNode *N, const ExplodedNode *N,
BugReport &BR) override; BugReport &BR) override;
}; };

View File

@ -420,8 +420,8 @@ private:
BugReporterContext &BRC, BugReporterContext &BRC,
BugReport &BR) override; BugReport &BR) override;
PathDiagnosticPiece* getEndPath(BugReporterContext &BRC, std::unique_ptr<PathDiagnosticPiece>
const ExplodedNode *EndPathNode, getEndPath(BugReporterContext &BRC, const ExplodedNode *EndPathNode,
BugReport &BR) override { BugReport &BR) override {
if (!IsLeak) if (!IsLeak)
return nullptr; return nullptr;
@ -430,7 +430,8 @@ private:
PathDiagnosticLocation::createEndOfPath(EndPathNode, PathDiagnosticLocation::createEndOfPath(EndPathNode,
BRC.getSourceManager()); BRC.getSourceManager());
// Do not add the statement itself as a range in case of leak. // Do not add the statement itself as a range in case of leak.
return new PathDiagnosticEventPiece(L, BR.getDescription(), false); return llvm::make_unique<PathDiagnosticEventPiece>(L, BR.getDescription(),
false);
} }
private: private:

View File

@ -1717,7 +1717,7 @@ namespace {
BugReporterContext &BRC, BugReporterContext &BRC,
BugReport &BR) override; BugReport &BR) override;
PathDiagnosticPiece *getEndPath(BugReporterContext &BRC, std::unique_ptr<PathDiagnosticPiece> getEndPath(BugReporterContext &BRC,
const ExplodedNode *N, const ExplodedNode *N,
BugReport &BR) override; BugReport &BR) override;
}; };
@ -1728,7 +1728,7 @@ namespace {
const SummaryLogTy &log) const SummaryLogTy &log)
: CFRefReportVisitor(sym, GCEnabled, log) {} : CFRefReportVisitor(sym, GCEnabled, log) {}
PathDiagnosticPiece *getEndPath(BugReporterContext &BRC, std::unique_ptr<PathDiagnosticPiece> getEndPath(BugReporterContext &BRC,
const ExplodedNode *N, const ExplodedNode *N,
BugReport &BR) override; BugReport &BR) override;
@ -2219,18 +2219,16 @@ GetAllocationSite(ProgramStateManager& StateMgr, const ExplodedNode *N,
InterestingMethodContext); InterestingMethodContext);
} }
PathDiagnosticPiece* std::unique_ptr<PathDiagnosticPiece>
CFRefReportVisitor::getEndPath(BugReporterContext &BRC, CFRefReportVisitor::getEndPath(BugReporterContext &BRC,
const ExplodedNode *EndN, const ExplodedNode *EndN, BugReport &BR) {
BugReport &BR) {
BR.markInteresting(Sym); BR.markInteresting(Sym);
return BugReporterVisitor::getDefaultEndPath(BRC, EndN, BR); return BugReporterVisitor::getDefaultEndPath(BRC, EndN, BR);
} }
PathDiagnosticPiece* std::unique_ptr<PathDiagnosticPiece>
CFRefLeakReportVisitor::getEndPath(BugReporterContext &BRC, CFRefLeakReportVisitor::getEndPath(BugReporterContext &BRC,
const ExplodedNode *EndN, const ExplodedNode *EndN, BugReport &BR) {
BugReport &BR) {
// Tell the BugReporterContext to report cases when the tracked symbol is // Tell the BugReporterContext to report cases when the tracked symbol is
// assigned to different variables, etc. // assigned to different variables, etc.
@ -2310,7 +2308,7 @@ CFRefLeakReportVisitor::getEndPath(BugReporterContext &BRC,
os << " is not referenced later in this execution path and has a retain " os << " is not referenced later in this execution path and has a retain "
"count of +" << RV->getCount(); "count of +" << RV->getCount();
return new PathDiagnosticEventPiece(L, os.str()); return llvm::make_unique<PathDiagnosticEventPiece>(L, os.str());
} }
CFRefLeakReport::CFRefLeakReport(CFRefBug &D, const LangOptions &LOpts, CFRefLeakReport::CFRefLeakReport(CFRefBug &D, const LangOptions &LOpts,

View File

@ -3153,16 +3153,17 @@ bool GRBugReporter::generatePathDiagnostic(PathDiagnostic& PD,
std::unique_ptr<PathDiagnosticPiece> LastPiece; std::unique_ptr<PathDiagnosticPiece> LastPiece;
for (BugReport::visitor_iterator I = visitors.begin(), E = visitors.end(); for (BugReport::visitor_iterator I = visitors.begin(), E = visitors.end();
I != E; ++I) { I != E; ++I) {
if (PathDiagnosticPiece *Piece = (*I)->getEndPath(PDB, N, *R)) { if (std::unique_ptr<PathDiagnosticPiece> Piece =
(*I)->getEndPath(PDB, N, *R)) {
assert (!LastPiece && assert (!LastPiece &&
"There can only be one final piece in a diagnostic."); "There can only be one final piece in a diagnostic.");
LastPiece.reset(Piece); LastPiece = std::move(Piece);
} }
} }
if (ActiveScheme != PathDiagnosticConsumer::None) { if (ActiveScheme != PathDiagnosticConsumer::None) {
if (!LastPiece) if (!LastPiece)
LastPiece.reset(BugReporterVisitor::getDefaultEndPath(PDB, N, *R)); LastPiece = BugReporterVisitor::getDefaultEndPath(PDB, N, *R);
assert(LastPiece); assert(LastPiece);
PD.setEndOfPath(LastPiece.release()); PD.setEndOfPath(LastPiece.release());
} }

View File

@ -100,17 +100,14 @@ const Stmt *bugreporter::GetRetValExpr(const ExplodedNode *N) {
// Definitions for bug reporter visitors. // Definitions for bug reporter visitors.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
PathDiagnosticPiece* std::unique_ptr<PathDiagnosticPiece>
BugReporterVisitor::getEndPath(BugReporterContext &BRC, BugReporterVisitor::getEndPath(BugReporterContext &BRC,
const ExplodedNode *EndPathNode, const ExplodedNode *EndPathNode, BugReport &BR) {
BugReport &BR) {
return nullptr; return nullptr;
} }
PathDiagnosticPiece* std::unique_ptr<PathDiagnosticPiece> BugReporterVisitor::getDefaultEndPath(
BugReporterVisitor::getDefaultEndPath(BugReporterContext &BRC, BugReporterContext &BRC, const ExplodedNode *EndPathNode, BugReport &BR) {
const ExplodedNode *EndPathNode,
BugReport &BR) {
PathDiagnosticLocation L = PathDiagnosticLocation L =
PathDiagnosticLocation::createEndOfPath(EndPathNode,BRC.getSourceManager()); PathDiagnosticLocation::createEndOfPath(EndPathNode,BRC.getSourceManager());
@ -119,13 +116,12 @@ BugReporterVisitor::getDefaultEndPath(BugReporterContext &BRC,
// Only add the statement itself as a range if we didn't specify any // Only add the statement itself as a range if we didn't specify any
// special ranges for this report. // special ranges for this report.
PathDiagnosticPiece *P = new PathDiagnosticEventPiece(L, auto P = llvm::make_unique<PathDiagnosticEventPiece>(L, BR.getDescription(),
BR.getDescription(),
Beg == End); Beg == End);
for (; Beg != End; ++Beg) for (; Beg != End; ++Beg)
P->addRange(*Beg); P->addRange(*Beg);
return P; return std::move(P);
} }
@ -399,7 +395,7 @@ public:
llvm_unreachable("Invalid visit mode!"); llvm_unreachable("Invalid visit mode!");
} }
PathDiagnosticPiece *getEndPath(BugReporterContext &BRC, std::unique_ptr<PathDiagnosticPiece> getEndPath(BugReporterContext &BRC,
const ExplodedNode *N, const ExplodedNode *N,
BugReport &BR) override { BugReport &BR) override {
if (EnableNullFPSuppression) if (EnableNullFPSuppression)
@ -1517,8 +1513,7 @@ static bool isInStdNamespace(const Decl *D) {
return ND->isStdNamespace(); return ND->isStdNamespace();
} }
std::unique_ptr<PathDiagnosticPiece>
PathDiagnosticPiece *
LikelyFalsePositiveSuppressionBRVisitor::getEndPath(BugReporterContext &BRC, LikelyFalsePositiveSuppressionBRVisitor::getEndPath(BugReporterContext &BRC,
const ExplodedNode *N, const ExplodedNode *N,
BugReport &BR) { BugReport &BR) {