summaryrefslogtreecommitdiffstats
path: root/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2015-06-23 13:15:32 +0000
committerAaron Ballman <aaron@aaronballman.com>2015-06-23 13:15:32 +0000
commite1c2ad65ca21f0115bec365138fead6dea0dfc61 (patch)
tree19a4c8a37714139cb584cf2ea6cd9812c68d4b2e /lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
parentb76ba4e2b681c3b6028c37946684f659b280cb7e (diff)
Clarify pointer ownership semantics by hoisting the std::unique_ptr creation to the caller instead of hiding it in emitReport. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240400 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp')
-rw-r--r--lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp b/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
index cb2d46b583..73f8087fd3 100644
--- a/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
@@ -36,10 +36,11 @@ public:
void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
- BugReport *genReportNullAttrNonNull(const ExplodedNode *ErrorN,
- const Expr *ArgE) const;
- BugReport *genReportReferenceToNullPointer(const ExplodedNode *ErrorN,
- const Expr *ArgE) const;
+ std::unique_ptr<BugReport>
+ genReportNullAttrNonNull(const ExplodedNode *ErrorN, const Expr *ArgE) const;
+ std::unique_ptr<BugReport>
+ genReportReferenceToNullPointer(const ExplodedNode *ErrorN,
+ const Expr *ArgE) const;
};
} // end anonymous namespace
@@ -143,7 +144,7 @@ void NonNullParamChecker::checkPreCall(const CallEvent &Call,
// we cache out.
if (ExplodedNode *errorNode = C.generateSink(stateNull)) {
- BugReport *R = nullptr;
+ std::unique_ptr<BugReport> R;
if (haveAttrNonNull)
R = genReportNullAttrNonNull(errorNode, ArgE);
else if (haveRefTypeParam)
@@ -153,7 +154,7 @@ void NonNullParamChecker::checkPreCall(const CallEvent &Call,
R->addRange(Call.getArgSourceRange(idx));
// Emit the bug report.
- C.emitReport(R);
+ C.emitReport(std::move(R));
}
// Always return. Either we cached out or we just emitted an error.
@@ -171,8 +172,9 @@ void NonNullParamChecker::checkPreCall(const CallEvent &Call,
C.addTransition(state);
}
-BugReport *NonNullParamChecker::genReportNullAttrNonNull(
- const ExplodedNode *ErrorNode, const Expr *ArgE) const {
+std::unique_ptr<BugReport>
+NonNullParamChecker::genReportNullAttrNonNull(const ExplodedNode *ErrorNode,
+ const Expr *ArgE) const {
// Lazily allocate the BugType object if it hasn't already been
// created. Ownership is transferred to the BugReporter object once
// the BugReport is passed to 'EmitWarning'.
@@ -180,23 +182,22 @@ BugReport *NonNullParamChecker::genReportNullAttrNonNull(
BTAttrNonNull.reset(new BugType(
this, "Argument with 'nonnull' attribute passed null", "API"));
- BugReport *R = new BugReport(*BTAttrNonNull,
- "Null pointer passed as an argument to a 'nonnull' parameter",
- ErrorNode);
+ auto R = llvm::make_unique<BugReport>(
+ *BTAttrNonNull,
+ "Null pointer passed as an argument to a 'nonnull' parameter", ErrorNode);
if (ArgE)
bugreporter::trackNullOrUndefValue(ErrorNode, ArgE, *R);
return R;
}
-BugReport *NonNullParamChecker::genReportReferenceToNullPointer(
- const ExplodedNode *ErrorNode, const Expr *ArgE) const {
+std::unique_ptr<BugReport> NonNullParamChecker::genReportReferenceToNullPointer(
+ const ExplodedNode *ErrorNode, const Expr *ArgE) const {
if (!BTNullRefArg)
BTNullRefArg.reset(new BuiltinBug(this, "Dereference of null pointer"));
- BugReport *R = new BugReport(*BTNullRefArg,
- "Forming reference to null pointer",
- ErrorNode);
+ auto R = llvm::make_unique<BugReport>(
+ *BTNullRefArg, "Forming reference to null pointer", ErrorNode);
if (ArgE) {
const Expr *ArgEDeref = bugreporter::getDerefExpr(ArgE);
if (!ArgEDeref)