diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2015-06-23 13:15:32 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2015-06-23 13:15:32 +0000 |
commit | 8d3a7a56a944f6b8452cb8e21ba68a293c7f5202 (patch) | |
tree | e7f2906cae208f6db629b25f46559dddb46ff5a1 /clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp | |
parent | 91d35a5e225c592a885ca993ce5628228ff26a49 (diff) | |
download | bcm5719-llvm-8d3a7a56a944f6b8452cb8e21ba68a293c7f5202.tar.gz bcm5719-llvm-8d3a7a56a944f6b8452cb8e21ba68a293c7f5202.zip |
Clarify pointer ownership semantics by hoisting the std::unique_ptr creation to the caller instead of hiding it in emitReport. NFC.
llvm-svn: 240400
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp index cb2d46b5831..73f8087fd3c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp +++ b/clang/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) |