diff --git a/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index 308ac8363bea1c6dd46caf981df3964d8057e284..57c73fd6eca16e29a1f8582d706c7b3dbb59dad9 100644 --- a/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -464,7 +464,7 @@ public: /// The reports are usually generated by the checkers. Further, they are /// folded based on the profile value, which is done to coalesce similar /// reports. - void emitReport(BugReport *R); + void emitReport(std::unique_ptr<BugReport> R); void EmitBasicReport(const Decl *DeclWithIssue, const CheckerBase *Checker, StringRef BugName, StringRef BugCategory, diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h index 68274f52a60c56cfe2e488fdf53d91c0bba78ceb..a4ff133b4b93208afff354c2d900ad64d54b5e2c 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h @@ -232,9 +232,9 @@ public: } /// \brief Emit the diagnostics report. - void emitReport(BugReport *R) { + void emitReport(std::unique_ptr<BugReport> R) { Changed = true; - Eng.getBugReporter().emitReport(R); + Eng.getBugReporter().emitReport(std::move(R)); } /// \brief Get the declaration of the called function (path-sensitive). diff --git a/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp b/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp index cb5b01009f1d9546c1f0b642831f6ecf529551bf..557439b288812a49c68d2e0c41429aa53fc149af 100644 --- a/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp @@ -76,11 +76,10 @@ void ArrayBoundChecker::checkLocation(SVal l, bool isLoad, const Stmt* LoadS, // reference is outside the range. // Generate a report for this bug. - BugReport *report = - new BugReport(*BT, BT->getDescription(), N); + auto report = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N); report->addRange(LoadS->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); return; } diff --git a/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp b/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp index e462e2b2f15e77fbc4985164d3ec15f4cc94307a..d8dc2aaa6363ee08ceec34876a3355e642a53f45 100644 --- a/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp +++ b/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp @@ -207,7 +207,8 @@ void ArrayBoundCheckerV2::reportOOB(CheckerContext &checkerContext, break; } - checkerContext.emitReport(new BugReport(*BT, os.str(), errorNode)); + checkerContext.emitReport( + llvm::make_unique<BugReport>(*BT, os.str(), errorNode)); } void RegionRawOffsetV2::dump() const { diff --git a/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp b/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp index 3fd55760bc5f52a6ae56b592f0cf97c9dfc4ac4a..f763284aa2c9fa14ba86460985d658e0c12ada02 100644 --- a/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp +++ b/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp @@ -207,10 +207,10 @@ void NilArgChecker::generateBugReport(ExplodedNode *N, if (!BT) BT.reset(new APIMisuse(this, "nil argument")); - BugReport *R = new BugReport(*BT, Msg, N); + auto R = llvm::make_unique<BugReport>(*BT, Msg, N); R->addRange(Range); bugreporter::trackNullOrUndefValue(N, E, *R); - C.emitReport(R); + C.emitReport(std::move(R)); } void NilArgChecker::checkPreObjCMessage(const ObjCMethodCall &msg, @@ -516,9 +516,9 @@ void CFNumberCreateChecker::checkPreStmt(const CallExpr *CE, if (!BT) BT.reset(new APIMisuse(this, "Bad use of CFNumberCreate")); - BugReport *report = new BugReport(*BT, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT, os.str(), N); report->addRange(CE->getArg(2)->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); } } @@ -605,10 +605,10 @@ void CFRetainReleaseChecker::checkPreStmt(const CallExpr *CE, else llvm_unreachable("impossible case"); - BugReport *report = new BugReport(*BT, description, N); + auto report = llvm::make_unique<BugReport>(*BT, description, N); report->addRange(Arg->getSourceRange()); bugreporter::trackNullOrUndefValue(N, Arg, *report); - C.emitReport(report); + C.emitReport(std::move(report)); return; } @@ -666,9 +666,9 @@ void ClassReleaseChecker::checkPreObjCMessage(const ObjCMethodCall &msg, "of class '" << Class->getName() << "' and not the class directly"; - BugReport *report = new BugReport(*BT, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT, os.str(), N); report->addRange(msg.getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); } } @@ -819,9 +819,9 @@ void VariadicMethodTypeChecker::checkPreObjCMessage(const ObjCMethodCall &msg, ArgTy.print(os, C.getLangOpts()); os << "'"; - BugReport *R = new BugReport(*BT, os.str(), errorNode.getValue()); + auto R = llvm::make_unique<BugReport>(*BT, os.str(), errorNode.getValue()); R->addRange(msg.getArgSourceRange(I)); - C.emitReport(R); + C.emitReport(std::move(R)); } } diff --git a/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp b/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp index 83a37c978c22c767201c9306f6989a4bdc954178..e945c38e77c7a07026a188bf0688ed2c235e9f78 100644 --- a/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp @@ -35,7 +35,7 @@ void BoolAssignmentChecker::emitReport(ProgramStateRef state, if (ExplodedNode *N = C.addTransition(state)) { if (!BT) BT.reset(new BuiltinBug(this, "Assignment of a non-Boolean value")); - C.emitReport(new BugReport(*BT, BT->getDescription(), N)); + C.emitReport(llvm::make_unique<BugReport>(*BT, BT->getDescription(), N)); } } diff --git a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp index 0f5741bf9e68ce7d3717daad6f3bd4ec5b12df52..54b12410aa56897d3eca5655cb6160d7fdc86c8c 100644 --- a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -245,11 +245,11 @@ ProgramStateRef CStringChecker::checkNonNull(CheckerContext &C, // Generate a report for this bug. BuiltinBug *BT = static_cast<BuiltinBug*>(BT_Null.get()); - BugReport *report = new BugReport(*BT, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT, os.str(), N); report->addRange(S->getSourceRange()); bugreporter::trackNullOrUndefValue(N, S, *report); - C.emitReport(report); + C.emitReport(std::move(report)); return nullptr; } @@ -304,9 +304,9 @@ ProgramStateRef CStringChecker::CheckLocation(CheckerContext &C, BuiltinBug *BT = static_cast<BuiltinBug*>(BT_Bounds.get()); // Generate a report for this bug. - BugReport *report; + std::unique_ptr<BugReport> report; if (warningMsg) { - report = new BugReport(*BT, warningMsg, N); + report = llvm::make_unique<BugReport>(*BT, warningMsg, N); } else { assert(CurrentFunctionDescription); assert(CurrentFunctionDescription[0] != '\0'); @@ -316,7 +316,7 @@ ProgramStateRef CStringChecker::CheckLocation(CheckerContext &C, os << toUppercase(CurrentFunctionDescription[0]) << &CurrentFunctionDescription[1] << " accesses out-of-bound array element"; - report = new BugReport(*BT, os.str(), N); + report = llvm::make_unique<BugReport>(*BT, os.str(), N); } // FIXME: It would be nice to eventually make this diagnostic more clear, @@ -324,7 +324,7 @@ ProgramStateRef CStringChecker::CheckLocation(CheckerContext &C, // reference is outside the range. report->addRange(S->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); return nullptr; } @@ -534,13 +534,12 @@ void CStringChecker::emitOverlapBug(CheckerContext &C, ProgramStateRef state, categories::UnixAPI, "Improper arguments")); // Generate a report for this bug. - BugReport *report = - new BugReport(*BT_Overlap, - "Arguments must not be overlapping buffers", N); + auto report = llvm::make_unique<BugReport>( + *BT_Overlap, "Arguments must not be overlapping buffers", N); report->addRange(First->getSourceRange()); report->addRange(Second->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); } ProgramStateRef CStringChecker::checkAdditionOverflow(CheckerContext &C, @@ -603,8 +602,8 @@ ProgramStateRef CStringChecker::checkAdditionOverflow(CheckerContext &C, "be represented as a size_t"; // Generate a report for this bug. - BugReport *report = new BugReport(*BT_AdditionOverflow, warning, N); - C.emitReport(report); + C.emitReport( + llvm::make_unique<BugReport>(*BT_AdditionOverflow, warning, N)); return nullptr; } @@ -721,10 +720,10 @@ SVal CStringChecker::getCStringLength(CheckerContext &C, ProgramStateRef &state, << "', which is not a null-terminated string"; // Generate a report for this bug. - BugReport *report = new BugReport(*BT_NotCString, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT_NotCString, os.str(), N); report->addRange(Ex->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); } return UndefinedVal(); @@ -785,11 +784,10 @@ SVal CStringChecker::getCStringLength(CheckerContext &C, ProgramStateRef &state, os << "not a null-terminated string"; // Generate a report for this bug. - BugReport *report = new BugReport(*BT_NotCString, - os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT_NotCString, os.str(), N); report->addRange(Ex->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); } return UndefinedVal(); diff --git a/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp b/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp index adb7a54900e0b01d5108cedde7786b4db63fe279..26423b7368efe95a643073a511b707d437a3d439 100644 --- a/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp @@ -94,14 +94,14 @@ void CallAndMessageChecker::emitBadCall(BugType *BT, CheckerContext &C, if (!N) return; - BugReport *R = new BugReport(*BT, BT->getName(), N); + auto R = llvm::make_unique<BugReport>(*BT, BT->getName(), N); if (BadE) { R->addRange(BadE->getSourceRange()); if (BadE->isGLValue()) BadE = bugreporter::getDerefExpr(BadE); bugreporter::trackNullOrUndefValue(N, BadE, *R); } - C.emitReport(R); + C.emitReport(std::move(R)); } static StringRef describeUninitializedArgumentInCall(const CallEvent &Call, @@ -164,12 +164,12 @@ bool CallAndMessageChecker::uninitRefOrPointer(CheckerContext &C, if (PSV.isUndef()) { if (ExplodedNode *N = C.generateSink()) { LazyInit_BT(BD, BT); - BugReport *R = new BugReport(*BT, Message, N); + auto R = llvm::make_unique<BugReport>(*BT, Message, N); R->addRange(ArgRange); if (ArgEx) { bugreporter::trackNullOrUndefValue(N, ArgEx, *R); } - C.emitReport(R); + C.emitReport(std::move(R)); } return true; } @@ -199,11 +199,11 @@ bool CallAndMessageChecker::PreVisitProcessArg(CheckerContext &C, // Generate a report for this bug. StringRef Desc = describeUninitializedArgumentInCall(Call, IsFirstArgument); - BugReport *R = new BugReport(*BT, Desc, N); + auto R = llvm::make_unique<BugReport>(*BT, Desc, N); R->addRange(ArgRange); if (ArgEx) bugreporter::trackNullOrUndefValue(N, ArgEx, *R); - C.emitReport(R); + C.emitReport(std::move(R)); } return true; } @@ -281,12 +281,12 @@ bool CallAndMessageChecker::PreVisitProcessArg(CheckerContext &C, } // Generate a report for this bug. - BugReport *R = new BugReport(*BT, os.str(), N); + auto R = llvm::make_unique<BugReport>(*BT, os.str(), N); R->addRange(ArgRange); // FIXME: enhance track back for uninitialized value for arbitrary // memregions - C.emitReport(R); + C.emitReport(std::move(R)); } return true; } @@ -342,9 +342,9 @@ void CallAndMessageChecker::checkPreStmt(const CXXDeleteExpr *DE, else Desc = "Argument to 'delete' is uninitialized"; BugType *BT = BT_cxx_delete_undef.get(); - BugReport *R = new BugReport(*BT, Desc, N); + auto R = llvm::make_unique<BugReport>(*BT, Desc, N); bugreporter::trackNullOrUndefValue(N, DE, *R); - C.emitReport(R); + C.emitReport(std::move(R)); return; } } @@ -400,8 +400,8 @@ void CallAndMessageChecker::checkPreCall(const CallEvent &Call, << (Params == 1 ? "" : "s") << " is called with less (" << Call.getNumArgs() << ")"; - BugReport *R = new BugReport(*BT_call_few_args, os.str(), N); - C.emitReport(R); + C.emitReport( + llvm::make_unique<BugReport>(*BT_call_few_args, os.str(), N)); } } @@ -461,14 +461,14 @@ void CallAndMessageChecker::checkPreObjCMessage(const ObjCMethodCall &msg, } assert(BT && "Unknown message kind."); - BugReport *R = new BugReport(*BT, BT->getName(), N); + auto R = llvm::make_unique<BugReport>(*BT, BT->getName(), N); const ObjCMessageExpr *ME = msg.getOriginExpr(); R->addRange(ME->getReceiverRange()); // FIXME: getTrackNullOrUndefValueVisitor can't handle "super" yet. if (const Expr *ReceiverE = ME->getInstanceReceiver()) bugreporter::trackNullOrUndefValue(N, ReceiverE, *R); - C.emitReport(R); + C.emitReport(std::move(R)); } return; } else { @@ -512,13 +512,13 @@ void CallAndMessageChecker::emitNilReceiverBug(CheckerContext &C, os << "' that will be garbage"; } - BugReport *report = new BugReport(*BT_msg_ret, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT_msg_ret, os.str(), N); report->addRange(ME->getReceiverRange()); // FIXME: This won't track "self" in messages to super. if (const Expr *receiver = ME->getInstanceReceiver()) { bugreporter::trackNullOrUndefValue(N, receiver, *report); } - C.emitReport(report); + C.emitReport(std::move(report)); } static bool supportsNilWithFloatRet(const llvm::Triple &triple) { diff --git a/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp b/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp index 3ba063ddc82125899117f23859f671ad2b9865b4..0d683f96df081180743e4197077f45590cad0ec1 100644 --- a/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp @@ -136,9 +136,9 @@ void CastSizeChecker::checkPreStmt(const CastExpr *CE,CheckerContext &C) const { BT.reset(new BuiltinBug(this, "Cast region with wrong size.", "Cast a region whose size is not a multiple" " of the destination type size.")); - BugReport *R = new BugReport(*BT, BT->getDescription(), errorNode); + auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), errorNode); R->addRange(CE->getSourceRange()); - C.emitReport(R); + C.emitReport(std::move(R)); } } diff --git a/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp b/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp index d765315bb57bc9b2e84f4b4a87c9f1858e240042..ba3024d78a19f339bee403b2562079237d44263e 100644 --- a/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp @@ -63,9 +63,9 @@ void CastToStructChecker::checkPreStmt(const CastExpr *CE, "Casting a non-structure type to a structure type " "and accessing a field can lead to memory access " "errors or data corruption.")); - BugReport *R = new BugReport(*BT,BT->getDescription(), N); + auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N); R->addRange(CE->getSourceRange()); - C.emitReport(R); + C.emitReport(std::move(R)); } } } diff --git a/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp b/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp index ad415770e5e5c818a60635634172d11deca9f3dc..804e83c0fb2a054a357b44e0ac3955487fcf6ffb 100644 --- a/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp @@ -145,11 +145,10 @@ void ChrootChecker::checkPreStmt(const CallExpr *CE, CheckerContext &C) const { BT_BreakJail.reset(new BuiltinBug( this, "Break out of jail", "No call of chdir(\"/\") immediately " "after chroot")); - BugReport *R = new BugReport(*BT_BreakJail, - BT_BreakJail->getDescription(), N); - C.emitReport(R); + C.emitReport(llvm::make_unique<BugReport>( + *BT_BreakJail, BT_BreakJail->getDescription(), N)); } - + return; } diff --git a/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp b/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp index 2e442c7d875c24fcb2468caa29ded10c7057ec45..2ba7ea4a4e4d34268f6fab6b3c465e025741dfbc 100644 --- a/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp @@ -160,10 +160,8 @@ void DereferenceChecker::reportBug(ProgramStateRef State, const Stmt *S, } os.flush(); - BugReport *report = - new BugReport(*BT_null, - buf.empty() ? BT_null->getDescription() : StringRef(buf), - N); + auto report = llvm::make_unique<BugReport>( + *BT_null, buf.empty() ? BT_null->getDescription() : StringRef(buf), N); bugreporter::trackNullOrUndefValue(N, bugreporter::getDerefExpr(S), *report); @@ -171,7 +169,7 @@ void DereferenceChecker::reportBug(ProgramStateRef State, const Stmt *S, I = Ranges.begin(), E = Ranges.end(); I!=E; ++I) report->addRange(*I); - C.emitReport(report); + C.emitReport(std::move(report)); } void DereferenceChecker::checkLocation(SVal l, bool isLoad, const Stmt* S, @@ -183,11 +181,11 @@ void DereferenceChecker::checkLocation(SVal l, bool isLoad, const Stmt* S, BT_undef.reset( new BuiltinBug(this, "Dereference of undefined pointer value")); - BugReport *report = - new BugReport(*BT_undef, BT_undef->getDescription(), N); + auto report = + llvm::make_unique<BugReport>(*BT_undef, BT_undef->getDescription(), N); bugreporter::trackNullOrUndefValue(N, bugreporter::getDerefExpr(S), *report); - C.emitReport(report); + C.emitReport(std::move(report)); } return; } diff --git a/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp b/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp index e060c36184c4a8d7f017fa999c4a47b923a8e254..79f9479b144806ece34fdd05fd28aa2647103788 100644 --- a/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp @@ -39,9 +39,9 @@ void DivZeroChecker::reportBug(const char *Msg, if (!BT) BT.reset(new BuiltinBug(this, "Division by zero")); - BugReport *R = new BugReport(*BT, Msg, N); + auto R = llvm::make_unique<BugReport>(*BT, Msg, N); bugreporter::trackNullOrUndefValue(N, bugreporter::GetDenomExpr(N), *R); - C.emitReport(R); + C.emitReport(std::move(R)); } } diff --git a/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp b/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp index f36ec2c687f5b3f3d1d3b8573583c1993a0915f1..7dc0a8745958c9f8e41e26b93b7f5392e93fca53 100644 --- a/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp @@ -97,8 +97,8 @@ void ExprInspectionChecker::analyzerEval(const CallExpr *CE, if (!BT) BT.reset(new BugType(this, "Checking analyzer assumptions", "debug")); - BugReport *R = new BugReport(*BT, getArgumentValueString(CE, C), N); - C.emitReport(R); + C.emitReport( + llvm::make_unique<BugReport>(*BT, getArgumentValueString(CE, C), N)); } void ExprInspectionChecker::analyzerWarnIfReached(const CallExpr *CE, @@ -108,8 +108,7 @@ void ExprInspectionChecker::analyzerWarnIfReached(const CallExpr *CE, if (!BT) BT.reset(new BugType(this, "Checking analyzer assumptions", "debug")); - BugReport *R = new BugReport(*BT, "REACHABLE", N); - C.emitReport(R); + C.emitReport(llvm::make_unique<BugReport>(*BT, "REACHABLE", N)); } void ExprInspectionChecker::analyzerCheckInlined(const CallExpr *CE, @@ -128,8 +127,8 @@ void ExprInspectionChecker::analyzerCheckInlined(const CallExpr *CE, if (!BT) BT.reset(new BugType(this, "Checking analyzer assumptions", "debug")); - BugReport *R = new BugReport(*BT, getArgumentValueString(CE, C), N); - C.emitReport(R); + C.emitReport( + llvm::make_unique<BugReport>(*BT, getArgumentValueString(CE, C), N)); } void ExprInspectionChecker::analyzerCrash(const CallExpr *CE, diff --git a/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp b/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp index 60bb03654f5dcfc02ee1a771d5f01d9ef0e134c5..48d6bd4b37e64527d757b912caadfa71c3034053 100644 --- a/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp @@ -57,9 +57,9 @@ void FixedAddressChecker::checkPreStmt(const BinaryOperator *B, "Using a fixed address is not portable because that " "address will probably not be valid in all " "environments or platforms.")); - BugReport *R = new BugReport(*BT, BT->getDescription(), N); + auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N); R->addRange(B->getRHS()->getSourceRange()); - C.emitReport(R); + C.emitReport(std::move(R)); } } diff --git a/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp b/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp index 275481f9e46cb8bd6141da92ef90e514100436e1..2cf508ff086c800db81cd3e4e10392297b4085b0 100644 --- a/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp @@ -642,9 +642,9 @@ bool GenericTaintChecker::generateReportIfTainted(const Expr *E, // Generate diagnostic. if (ExplodedNode *N = C.addTransition()) { initBugType(); - BugReport *report = new BugReport(*BT, Msg, N); + auto report = llvm::make_unique<BugReport>(*BT, Msg, N); report->addRange(E->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); return true; } return false; diff --git a/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp b/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp index 52e29368cea380e180b89e440c3b2c625a8daa10..783890135ea3b1b4cf97d5741bc701dc60c242c3 100644 --- a/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp @@ -103,9 +103,8 @@ private: const ExplodedNode *getAllocationNode(const ExplodedNode *N, SymbolRef Sym, CheckerContext &C) const; - BugReport *generateAllocatedDataNotReleasedReport(const AllocationPair &AP, - ExplodedNode *N, - CheckerContext &C) const; + std::unique_ptr<BugReport> generateAllocatedDataNotReleasedReport( + const AllocationPair &AP, ExplodedNode *N, CheckerContext &C) const; /// Check if RetSym evaluates to an error value in the current state. bool definitelyReturnedError(SymbolRef RetSym, @@ -269,11 +268,11 @@ void MacOSKeychainAPIChecker:: os << "Deallocator doesn't match the allocator: '" << FunctionsToTrack[PDeallocIdx].Name << "' should be used."; - BugReport *Report = new BugReport(*BT, os.str(), N); + auto Report = llvm::make_unique<BugReport>(*BT, os.str(), N); Report->addVisitor(llvm::make_unique<SecKeychainBugVisitor>(AP.first)); Report->addRange(ArgExpr->getSourceRange()); - markInteresting(Report, AP); - C.emitReport(Report); + markInteresting(Report.get(), AP); + C.emitReport(std::move(Report)); } void MacOSKeychainAPIChecker::checkPreStmt(const CallExpr *CE, @@ -314,11 +313,11 @@ void MacOSKeychainAPIChecker::checkPreStmt(const CallExpr *CE, << "the allocator: missing a call to '" << FunctionsToTrack[DIdx].Name << "'."; - BugReport *Report = new BugReport(*BT, os.str(), N); + auto Report = llvm::make_unique<BugReport>(*BT, os.str(), N); Report->addVisitor(llvm::make_unique<SecKeychainBugVisitor>(V)); Report->addRange(ArgExpr->getSourceRange()); Report->markInteresting(AS->Region); - C.emitReport(Report); + C.emitReport(std::move(Report)); } } return; @@ -370,12 +369,12 @@ void MacOSKeychainAPIChecker::checkPreStmt(const CallExpr *CE, if (!N) return; initBugType(); - BugReport *Report = new BugReport(*BT, - "Trying to free data which has not been allocated.", N); + auto Report = llvm::make_unique<BugReport>( + *BT, "Trying to free data which has not been allocated.", N); Report->addRange(ArgExpr->getSourceRange()); if (AS) Report->markInteresting(AS->Region); - C.emitReport(Report); + C.emitReport(std::move(Report)); return; } @@ -436,12 +435,12 @@ void MacOSKeychainAPIChecker::checkPreStmt(const CallExpr *CE, if (!N) return; initBugType(); - BugReport *Report = new BugReport(*BT, - "Only call free if a valid (non-NULL) buffer was returned.", N); + auto Report = llvm::make_unique<BugReport>( + *BT, "Only call free if a valid (non-NULL) buffer was returned.", N); Report->addVisitor(llvm::make_unique<SecKeychainBugVisitor>(ArgSM)); Report->addRange(ArgExpr->getSourceRange()); Report->markInteresting(AS->Region); - C.emitReport(Report); + C.emitReport(std::move(Report)); return; } @@ -519,10 +518,9 @@ MacOSKeychainAPIChecker::getAllocationNode(const ExplodedNode *N, return AllocNode; } -BugReport *MacOSKeychainAPIChecker:: - generateAllocatedDataNotReleasedReport(const AllocationPair &AP, - ExplodedNode *N, - CheckerContext &C) const { +std::unique_ptr<BugReport> +MacOSKeychainAPIChecker::generateAllocatedDataNotReleasedReport( + const AllocationPair &AP, ExplodedNode *N, CheckerContext &C) const { const ADFunctionInfo &FI = FunctionsToTrack[AP.second->AllocatorIdx]; initBugType(); SmallString<70> sbuf; @@ -547,11 +545,12 @@ BugReport *MacOSKeychainAPIChecker:: C.getSourceManager(), AllocNode->getLocationContext()); - BugReport *Report = new BugReport(*BT, os.str(), N, LocUsedForUniqueing, - AllocNode->getLocationContext()->getDecl()); + auto Report = + llvm::make_unique<BugReport>(*BT, os.str(), N, LocUsedForUniqueing, + AllocNode->getLocationContext()->getDecl()); Report->addVisitor(llvm::make_unique<SecKeychainBugVisitor>(AP.first)); - markInteresting(Report, AP); + markInteresting(Report.get(), AP); return Report; } @@ -589,10 +588,8 @@ void MacOSKeychainAPIChecker::checkDeadSymbols(SymbolReaper &SR, ExplodedNode *N = C.addTransition(C.getState(), C.getPredecessor(), &Tag); // Generate the error reports. - for (AllocationPairVec::iterator I = Errors.begin(), E = Errors.end(); - I != E; ++I) { - C.emitReport(generateAllocatedDataNotReleasedReport(*I, N, C)); - } + for (const auto P : Errors) + C.emitReport(generateAllocatedDataNotReleasedReport(P, N, C)); // Generate the new, cleaned up state. C.addTransition(State, N); diff --git a/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp b/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp index 13a401d1e675d2d5b36521eb856fac4c8e4a68f3..11ba6096e2dcb4088f25c2c90a2beb87c30b63e4 100644 --- a/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp @@ -92,9 +92,9 @@ void MacOSXAPIChecker::CheckDispatchOnce(CheckerContext &C, const CallExpr *CE, if (isa<VarRegion>(R) && isa<StackLocalsSpaceRegion>(R->getMemorySpace())) os << " Perhaps you intended to declare the variable as 'static'?"; - BugReport *report = new BugReport(*BT_dispatchOnce, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT_dispatchOnce, os.str(), N); report->addRange(CE->getArg(0)->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); } //===----------------------------------------------------------------------===// diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 0cf00940734968864614e3c53f11660a0fbbc117..a9e08653b24198697e1f8b375b0ea4020f53c438 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1619,10 +1619,10 @@ void MallocChecker::ReportBadFree(CheckerContext &C, SVal ArgVal, printExpectedAllocName(os, C, DeallocExpr); - BugReport *R = new BugReport(*BT_BadFree[*CheckKind], os.str(), N); + auto R = llvm::make_unique<BugReport>(*BT_BadFree[*CheckKind], os.str(), N); R->markInteresting(MR); R->addRange(Range); - C.emitReport(R); + C.emitReport(std::move(R)); } } @@ -1643,11 +1643,12 @@ void MallocChecker::ReportFreeAlloca(CheckerContext &C, SVal ArgVal, BT_FreeAlloca[*CheckKind].reset( new BugType(CheckNames[*CheckKind], "Free alloca()", "Memory Error")); - BugReport *R = new BugReport(*BT_FreeAlloca[*CheckKind], - "Memory allocated by alloca() should not be deallocated", N); + auto R = llvm::make_unique<BugReport>( + *BT_FreeAlloca[*CheckKind], + "Memory allocated by alloca() should not be deallocated", N); R->markInteresting(ArgVal.getAsRegion()); R->addRange(Range); - C.emitReport(R); + C.emitReport(std::move(R)); } } @@ -1698,11 +1699,11 @@ void MallocChecker::ReportMismatchedDealloc(CheckerContext &C, os << ", not " << DeallocOs.str(); } - BugReport *R = new BugReport(*BT_MismatchedDealloc, os.str(), N); + auto R = llvm::make_unique<BugReport>(*BT_MismatchedDealloc, os.str(), N); R->markInteresting(Sym); R->addRange(Range); R->addVisitor(llvm::make_unique<MallocBugVisitor>(Sym)); - C.emitReport(R); + C.emitReport(std::move(R)); } } @@ -1757,10 +1758,10 @@ void MallocChecker::ReportOffsetFree(CheckerContext &C, SVal ArgVal, else os << "allocated memory"; - BugReport *R = new BugReport(*BT_OffsetFree[*CheckKind], os.str(), N); + auto R = llvm::make_unique<BugReport>(*BT_OffsetFree[*CheckKind], os.str(), N); R->markInteresting(MR->getBaseRegion()); R->addRange(Range); - C.emitReport(R); + C.emitReport(std::move(R)); } void MallocChecker::ReportUseAfterFree(CheckerContext &C, SourceRange Range, @@ -1779,13 +1780,13 @@ void MallocChecker::ReportUseAfterFree(CheckerContext &C, SourceRange Range, BT_UseFree[*CheckKind].reset(new BugType( CheckNames[*CheckKind], "Use-after-free", "Memory Error")); - BugReport *R = new BugReport(*BT_UseFree[*CheckKind], - "Use of memory after it is freed", N); + auto R = llvm::make_unique<BugReport>(*BT_UseFree[*CheckKind], + "Use of memory after it is freed", N); R->markInteresting(Sym); R->addRange(Range); R->addVisitor(llvm::make_unique<MallocBugVisitor>(Sym)); - C.emitReport(R); + C.emitReport(std::move(R)); } } @@ -1806,17 +1807,17 @@ void MallocChecker::ReportDoubleFree(CheckerContext &C, SourceRange Range, BT_DoubleFree[*CheckKind].reset( new BugType(CheckNames[*CheckKind], "Double free", "Memory Error")); - BugReport *R = - new BugReport(*BT_DoubleFree[*CheckKind], - (Released ? "Attempt to free released memory" - : "Attempt to free non-owned memory"), - N); + auto R = llvm::make_unique<BugReport>( + *BT_DoubleFree[*CheckKind], + (Released ? "Attempt to free released memory" + : "Attempt to free non-owned memory"), + N); R->addRange(Range); R->markInteresting(Sym); if (PrevSym) R->markInteresting(PrevSym); R->addVisitor(llvm::make_unique<MallocBugVisitor>(Sym)); - C.emitReport(R); + C.emitReport(std::move(R)); } } @@ -1834,12 +1835,12 @@ void MallocChecker::ReportDoubleDelete(CheckerContext &C, SymbolRef Sym) const { BT_DoubleDelete.reset(new BugType(CheckNames[CK_NewDeleteChecker], "Double delete", "Memory Error")); - BugReport *R = new BugReport(*BT_DoubleDelete, - "Attempt to delete released memory", N); + auto R = llvm::make_unique<BugReport>( + *BT_DoubleDelete, "Attempt to delete released memory", N); R->markInteresting(Sym); R->addVisitor(llvm::make_unique<MallocBugVisitor>(Sym)); - C.emitReport(R); + C.emitReport(std::move(R)); } } @@ -1861,15 +1862,15 @@ void MallocChecker::ReportUseZeroAllocated(CheckerContext &C, BT_UseZerroAllocated[*CheckKind].reset(new BugType( CheckNames[*CheckKind], "Use of zero allocated", "Memory Error")); - BugReport *R = new BugReport(*BT_UseZerroAllocated[*CheckKind], - "Use of zero-allocated memory", N); + auto R = llvm::make_unique<BugReport>(*BT_UseZerroAllocated[*CheckKind], + "Use of zero-allocated memory", N); R->addRange(Range); if (Sym) { R->markInteresting(Sym); R->addVisitor(llvm::make_unique<MallocBugVisitor>(Sym)); } - C.emitReport(R); + C.emitReport(std::move(R)); } } @@ -2099,12 +2100,12 @@ void MallocChecker::reportLeak(SymbolRef Sym, ExplodedNode *N, os << "Potential memory leak"; } - BugReport *R = - new BugReport(*BT_Leak[*CheckKind], os.str(), N, LocUsedForUniqueing, - AllocNode->getLocationContext()->getDecl()); + auto R = llvm::make_unique<BugReport>( + *BT_Leak[*CheckKind], os.str(), N, LocUsedForUniqueing, + AllocNode->getLocationContext()->getDecl()); R->markInteresting(Sym); R->addVisitor(llvm::make_unique<MallocBugVisitor>(Sym, true)); - C.emitReport(R); + C.emitReport(std::move(R)); } void MallocChecker::checkDeadSymbols(SymbolReaper &SymReaper, diff --git a/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp b/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp index b180c03f0871e82485479d03ba5e032c5779b1b6..d23708ecbd97575126134796bfa7d65101907d36 100644 --- a/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp @@ -68,10 +68,11 @@ void NSAutoreleasePoolChecker::checkPreObjCMessage(const ObjCMethodCall &msg, return; } - BugReport *Report = new BugReport(*BT, "Use -drain instead of -release when " - "using NSAutoreleasePool and garbage collection", N); + auto Report = llvm::make_unique<BugReport>( + *BT, "Use -drain instead of -release when using NSAutoreleasePool and " + "garbage collection", N); Report->addRange(msg.getSourceRange()); - C.emitReport(Report); + C.emitReport(std::move(Report)); } void ento::registerNSAutoreleasePoolChecker(CheckerManager &mgr) { diff --git a/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp b/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp index 2be7f1d4ab8c74acea82ab4865a80536eb82564d..c351c6e9e08b4e6a25cfa9027c58ec560fbde948 100644 --- a/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp @@ -275,8 +275,7 @@ void NSOrCFErrorDerefChecker::checkEvent(ImplicitNullDerefEvent event) const { CFBT.reset(new CFErrorDerefBug(this)); bug = CFBT.get(); } - BugReport *report = new BugReport(*bug, os.str(), event.SinkNode); - BR.emitReport(report); + BR.emitReport(llvm::make_unique<BugReport>(*bug, os.str(), event.SinkNode)); } static bool IsNSError(QualType T, IdentifierInfo *II) { diff --git a/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp b/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp index cb2d46b58310af8f155a8b1b8e13bf9350fec558..73f8087fd3c01de1358daf85d3401e1fba0ee315 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) diff --git a/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp index fbf2d73dd86c4d8e646d61f717586a60dc73dd09..a7b92b4c67f2704881435c528e7c02cb0f95e16a 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp @@ -47,10 +47,10 @@ void ObjCAtSyncChecker::checkPreStmt(const ObjCAtSynchronizedStmt *S, if (!BT_undef) BT_undef.reset(new BuiltinBug(this, "Uninitialized value used as mutex " "for @synchronized")); - BugReport *report = - new BugReport(*BT_undef, BT_undef->getDescription(), N); + auto report = + llvm::make_unique<BugReport>(*BT_undef, BT_undef->getDescription(), N); bugreporter::trackNullOrUndefValue(N, Ex, *report); - C.emitReport(report); + C.emitReport(std::move(report)); } return; } @@ -71,11 +71,11 @@ void ObjCAtSyncChecker::checkPreStmt(const ObjCAtSynchronizedStmt *S, BT_null.reset(new BuiltinBug( this, "Nil value used as mutex for @synchronized() " "(no synchronization will occur)")); - BugReport *report = - new BugReport(*BT_null, BT_null->getDescription(), N); + auto report = + llvm::make_unique<BugReport>(*BT_null, BT_null->getDescription(), N); bugreporter::trackNullOrUndefValue(N, Ex, *report); - C.emitReport(report); + C.emitReport(std::move(report)); return; } } diff --git a/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp index 4f0b7e51da109ecc7743b2fa617418d8f057f2f3..53e159879eb2ca569f80ff80f67f690ca6202835 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp @@ -143,9 +143,9 @@ void ObjCContainersChecker::checkPreStmt(const CallExpr *CE, if (!N) return; initBugType(); - BugReport *R = new BugReport(*BT, "Index is out of bounds", N); + auto R = llvm::make_unique<BugReport>(*BT, "Index is out of bounds", N); R->addRange(IdxExpr->getSourceRange()); - C.emitReport(R); + C.emitReport(std::move(R)); return; } } diff --git a/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp index 51bc7e66dce2d9c7c4d653bce19bf1d19cd8b788..93b0553b3b7283d12e586e1f0011b3ca66a0f2db 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp @@ -160,8 +160,7 @@ void ObjCSelfInitChecker::checkForInvalidSelf(const Expr *E, CheckerContext &C, if (!BT) BT.reset(new BugType(this, "Missing \"self = [(super or self) init...]\"", categories::CoreFoundationObjectiveC)); - BugReport *report = new BugReport(*BT, errorStr, N); - C.emitReport(report); + C.emitReport(llvm::make_unique<BugReport>(*BT, errorStr, N)); } void ObjCSelfInitChecker::checkPostObjCMessage(const ObjCMethodCall &Msg, diff --git a/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp b/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp index 00480e4abf12c88bdc236a6ea3245afdbc63c511..806312468beb6b43e8a921bded303fcca637ec2a 100644 --- a/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp @@ -58,9 +58,9 @@ void PointerArithChecker::checkPreStmt(const BinaryOperator *B, "Pointer arithmetic done on non-array variables " "means reliance on memory layout, which is " "dangerous.")); - BugReport *R = new BugReport(*BT, BT->getDescription(), N); + auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N); R->addRange(B->getSourceRange()); - C.emitReport(R); + C.emitReport(std::move(R)); } } } diff --git a/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp b/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp index fbb2628a9ce5336e2046d7c8f58def0bba6b7482..cf1f88a2851b14e3b1f1db3387d6c598c783fb29 100644 --- a/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp @@ -66,9 +66,9 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator *B, new BuiltinBug(this, "Pointer subtraction", "Subtraction of two pointers that do not point to " "the same memory chunk may cause incorrect result.")); - BugReport *R = new BugReport(*BT, BT->getDescription(), N); + auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N); R->addRange(B->getSourceRange()); - C.emitReport(R); + C.emitReport(std::move(R)); } } diff --git a/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp b/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp index 1ede3a2a512637c2052f364b35db797fd512cfa4..4209017a58d5766140f8f52ca4a3042853c258bc 100644 --- a/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp @@ -145,11 +145,10 @@ void PthreadLockChecker::AcquireLock(CheckerContext &C, const CallExpr *CE, ExplodedNode *N = C.generateSink(); if (!N) return; - BugReport *report = new BugReport(*BT_doublelock, - "This lock has already been acquired", - N); + auto report = llvm::make_unique<BugReport>( + *BT_doublelock, "This lock has already been acquired", N); report->addRange(CE->getArg(0)->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); return; } else if (LState->isDestroyed()) { reportUseDestroyedBug(C, CE); @@ -208,11 +207,10 @@ void PthreadLockChecker::ReleaseLock(CheckerContext &C, const CallExpr *CE, ExplodedNode *N = C.generateSink(); if (!N) return; - BugReport *Report = new BugReport(*BT_doubleunlock, - "This lock has already been unlocked", - N); + auto Report = llvm::make_unique<BugReport>( + *BT_doubleunlock, "This lock has already been unlocked", N); Report->addRange(CE->getArg(0)->getSourceRange()); - C.emitReport(Report); + C.emitReport(std::move(Report)); return; } else if (LState->isDestroyed()) { reportUseDestroyedBug(C, CE); @@ -232,13 +230,11 @@ void PthreadLockChecker::ReleaseLock(CheckerContext &C, const CallExpr *CE, ExplodedNode *N = C.generateSink(); if (!N) return; - BugReport *report = new BugReport(*BT_lor, - "This was not the most recently " - "acquired lock. Possible lock order " - "reversal", - N); + auto report = llvm::make_unique<BugReport>( + *BT_lor, "This was not the most recently acquired lock. Possible " + "lock order reversal", N); report->addRange(CE->getArg(0)->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); return; } // Record that the lock was released. @@ -279,9 +275,9 @@ void PthreadLockChecker::DestroyLock(CheckerContext &C, const CallExpr *CE, ExplodedNode *N = C.generateSink(); if (!N) return; - BugReport *Report = new BugReport(*BT_destroylock, Message, N); + auto Report = llvm::make_unique<BugReport>(*BT_destroylock, Message, N); Report->addRange(CE->getArg(0)->getSourceRange()); - C.emitReport(Report); + C.emitReport(std::move(Report)); } void PthreadLockChecker::InitLock(CheckerContext &C, const CallExpr *CE, @@ -314,9 +310,9 @@ void PthreadLockChecker::InitLock(CheckerContext &C, const CallExpr *CE, ExplodedNode *N = C.generateSink(); if (!N) return; - BugReport *Report = new BugReport(*BT_initlock, Message, N); + auto Report = llvm::make_unique<BugReport>(*BT_initlock, Message, N); Report->addRange(CE->getArg(0)->getSourceRange()); - C.emitReport(Report); + C.emitReport(std::move(Report)); } void PthreadLockChecker::reportUseDestroyedBug(CheckerContext &C, @@ -327,11 +323,10 @@ void PthreadLockChecker::reportUseDestroyedBug(CheckerContext &C, ExplodedNode *N = C.generateSink(); if (!N) return; - BugReport *Report = new BugReport(*BT_destroylock, - "This lock has already been destroyed", - N); + auto Report = llvm::make_unique<BugReport>( + *BT_destroylock, "This lock has already been destroyed", N); Report->addRange(CE->getArg(0)->getSourceRange()); - C.emitReport(Report); + C.emitReport(std::move(Report)); } void ento::registerPthreadLockChecker(CheckerManager &mgr) { diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 71ae09c035a7ae316d0de42c7d057633160d96fd..9fa2bb19b426684e6dde6e7024b3bdf2e5ca4d93 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -3340,11 +3340,11 @@ void RetainCountChecker::processNonLeakError(ProgramStateRef St, } assert(BT); - CFRefReport *report = new CFRefReport(*BT, C.getASTContext().getLangOpts(), - C.isObjCGCEnabled(), SummaryLog, - N, Sym); + auto report = std::unique_ptr<BugReport>( + new CFRefReport(*BT, C.getASTContext().getLangOpts(), C.isObjCGCEnabled(), + SummaryLog, N, Sym)); report->addRange(ErrorRange); - C.emitReport(report); + C.emitReport(std::move(report)); } //===----------------------------------------------------------------------===// @@ -3573,12 +3573,9 @@ void RetainCountChecker::checkReturnWithRetEffect(const ReturnStmt *S, if (N) { const LangOptions &LOpts = C.getASTContext().getLangOpts(); bool GCEnabled = C.isObjCGCEnabled(); - CFRefReport *report = - new CFRefLeakReport(*getLeakAtReturnBug(LOpts, GCEnabled), - LOpts, GCEnabled, SummaryLog, - N, Sym, C, IncludeAllocationLine); - - C.emitReport(report); + C.emitReport(std::unique_ptr<BugReport>(new CFRefLeakReport( + *getLeakAtReturnBug(LOpts, GCEnabled), LOpts, GCEnabled, + SummaryLog, N, Sym, C, IncludeAllocationLine))); } } } @@ -3603,11 +3600,9 @@ void RetainCountChecker::checkReturnWithRetEffect(const ReturnStmt *S, if (!returnNotOwnedForOwned) returnNotOwnedForOwned.reset(new ReturnedNotOwnedForOwned(this)); - CFRefReport *report = - new CFRefReport(*returnNotOwnedForOwned, - C.getASTContext().getLangOpts(), - C.isObjCGCEnabled(), SummaryLog, N, Sym); - C.emitReport(report); + C.emitReport(std::unique_ptr<BugReport>(new CFRefReport( + *returnNotOwnedForOwned, C.getASTContext().getLangOpts(), + C.isObjCGCEnabled(), SummaryLog, N, Sym))); } } } @@ -3810,10 +3805,9 @@ RetainCountChecker::handleAutoreleaseCounts(ProgramStateRef state, overAutorelease.reset(new OverAutorelease(this)); const LangOptions &LOpts = Ctx.getASTContext().getLangOpts(); - CFRefReport *report = - new CFRefReport(*overAutorelease, LOpts, /* GCEnabled = */ false, - SummaryLog, N, Sym, os.str()); - Ctx.emitReport(report); + Ctx.emitReport(std::unique_ptr<BugReport>( + new CFRefReport(*overAutorelease, LOpts, /* GCEnabled = */ false, + SummaryLog, N, Sym, os.str()))); } return nullptr; @@ -3865,10 +3859,9 @@ RetainCountChecker::processLeaks(ProgramStateRef state, : getLeakAtReturnBug(LOpts, GCEnabled); assert(BT && "BugType not initialized."); - CFRefLeakReport *report = new CFRefLeakReport(*BT, LOpts, GCEnabled, - SummaryLog, N, *I, Ctx, - IncludeAllocationLine); - Ctx.emitReport(report); + Ctx.emitReport(std::unique_ptr<BugReport>( + new CFRefLeakReport(*BT, LOpts, GCEnabled, SummaryLog, N, *I, Ctx, + IncludeAllocationLine))); } } diff --git a/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp b/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp index b1cde6b897cb66c54a6d11532fcae084160548d9..acbd0d95d07b74f1adf156d6c03e801450644468 100644 --- a/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp @@ -80,11 +80,10 @@ void ReturnPointerRangeChecker::checkPreStmt(const ReturnStmt *RS, // reference is outside the range. // Generate a report for this bug. - BugReport *report = - new BugReport(*BT, BT->getDescription(), N); + auto report = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N); report->addRange(RetE->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); } } diff --git a/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp b/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp index 6622313c991f6a5c252e7bb13056f4266c32431b..2668ac1e1eca0658435de998b359b5d7589cb0ff 100644 --- a/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp @@ -84,12 +84,12 @@ static void emitBug(CheckerContext &C, BuiltinBug &BT, const Expr *RetE, if (!N) return; - BugReport *Report = new BugReport(BT, BT.getDescription(), N); + auto Report = llvm::make_unique<BugReport>(BT, BT.getDescription(), N); Report->addRange(RetE->getSourceRange()); bugreporter::trackNullOrUndefValue(N, TrackingE ? TrackingE : RetE, *Report); - C.emitReport(Report); + C.emitReport(std::move(Report)); } void ReturnUndefChecker::emitUndef(CheckerContext &C, const Expr *RetE) const { diff --git a/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp b/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp index ccf816c80c1e4ac6b399dc4b02624c01492320d2..c22e78b7eb62a189e04d1017224185f4ac1d6dfd 100644 --- a/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp @@ -214,11 +214,11 @@ void SimpleStreamChecker::reportDoubleClose(SymbolRef FileDescSym, return; // Generate the report. - BugReport *R = new BugReport(*DoubleCloseBugType, + auto R = llvm::make_unique<BugReport>(*DoubleCloseBugType, "Closing a previously closed file stream", ErrNode); R->addRange(Call.getSourceRange()); R->markInteresting(FileDescSym); - C.emitReport(R); + C.emitReport(std::move(R)); } void SimpleStreamChecker::reportLeaks(ArrayRef<SymbolRef> LeakedStreams, @@ -227,10 +227,10 @@ void SimpleStreamChecker::reportLeaks(ArrayRef<SymbolRef> LeakedStreams, // Attach bug reports to the leak node. // TODO: Identify the leaked file descriptor. for (SymbolRef LeakedStream : LeakedStreams) { - BugReport *R = new BugReport(*LeakBugType, + auto R = llvm::make_unique<BugReport>(*LeakBugType, "Opened file is never closed; potential resource leak", ErrNode); R->markInteresting(LeakedStream); - C.emitReport(R); + C.emitReport(std::move(R)); } } diff --git a/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp index 327a9e0ac435ae2442efb4f2a7c9e287d88f6a59..813c811ef15f3aba259ee4447df756ac58b00b18 100644 --- a/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp @@ -108,12 +108,12 @@ void StackAddrEscapeChecker::EmitStackError(CheckerContext &C, const MemRegion * llvm::raw_svector_ostream os(buf); SourceRange range = genName(os, R, C.getASTContext()); os << " returned to caller"; - BugReport *report = new BugReport(*BT_returnstack, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT_returnstack, os.str(), N); report->addRange(RetE->getSourceRange()); if (range.isValid()) report->addRange(range); - C.emitReport(report); + C.emitReport(std::move(report)); } void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS, @@ -231,11 +231,11 @@ void StackAddrEscapeChecker::checkEndFunction(CheckerContext &Ctx) const { const VarRegion *VR = cast<VarRegion>(cb.V[i].first->getBaseRegion()); os << *VR->getDecl() << "' upon returning to the caller. This will be a dangling reference"; - BugReport *report = new BugReport(*BT_stackleak, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT_stackleak, os.str(), N); if (range.isValid()) report->addRange(range); - Ctx.emitReport(report); + Ctx.emitReport(std::move(report)); } } diff --git a/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 894765a785ea8a1e91a2a3317a1ab45e6c85e332..2109a75b1fb6553c149b65669fd6632113ee318c 100644 --- a/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -277,9 +277,8 @@ void StreamChecker::Fseek(CheckerContext &C, const CallExpr *CE) const { new BuiltinBug(this, "Illegal whence argument", "The whence argument to fseek() should be " "SEEK_SET, SEEK_END, or SEEK_CUR.")); - BugReport *R = new BugReport(*BT_illegalwhence, - BT_illegalwhence->getDescription(), N); - C.emitReport(R); + C.emitReport(llvm::make_unique<BugReport>( + *BT_illegalwhence, BT_illegalwhence->getDescription(), N)); } } @@ -354,8 +353,8 @@ ProgramStateRef StreamChecker::CheckNullStream(SVal SV, ProgramStateRef state, if (!BT_nullfp) BT_nullfp.reset(new BuiltinBug(this, "NULL stream pointer", "Stream pointer might be NULL.")); - BugReport *R =new BugReport(*BT_nullfp, BT_nullfp->getDescription(), N); - C.emitReport(R); + C.emitReport(llvm::make_unique<BugReport>( + *BT_nullfp, BT_nullfp->getDescription(), N)); } return nullptr; } @@ -385,9 +384,8 @@ ProgramStateRef StreamChecker::CheckDoubleClose(const CallExpr *CE, BT_doubleclose.reset(new BuiltinBug( this, "Double fclose", "Try to close a file Descriptor already" " closed. Cause undefined behaviour.")); - BugReport *R = new BugReport(*BT_doubleclose, - BT_doubleclose->getDescription(), N); - C.emitReport(R); + C.emitReport(llvm::make_unique<BugReport>( + *BT_doubleclose, BT_doubleclose->getDescription(), N)); } return nullptr; } @@ -414,9 +412,8 @@ void StreamChecker::checkDeadSymbols(SymbolReaper &SymReaper, BT_ResourceLeak.reset(new BuiltinBug( this, "Resource Leak", "Opened File never closed. Potential Resource leak.")); - BugReport *R = new BugReport(*BT_ResourceLeak, - BT_ResourceLeak->getDescription(), N); - C.emitReport(R); + C.emitReport(llvm::make_unique<BugReport>( + *BT_ResourceLeak, BT_ResourceLeak->getDescription(), N)); } } } diff --git a/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp b/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp index d33c977826a5bc507a1d0be14543f95b7916b1f3..6e2477579f552411c49be1efa9ad4f4f785145b4 100644 --- a/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp @@ -50,9 +50,9 @@ void TaintTesterChecker::checkPostStmt(const Expr *E, if (State->isTainted(E, C.getLocationContext())) { if (ExplodedNode *N = C.addTransition()) { initBugType(); - BugReport *report = new BugReport(*BT, "tainted",N); + auto report = llvm::make_unique<BugReport>(*BT, "tainted",N); report->addRange(E->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); } } } diff --git a/lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp b/lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp index 083075db8fb9e792d929f59a063cea5b662b592e..638701da8a01e773674823358b78d8d1af5c8a0f 100644 --- a/lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp @@ -171,14 +171,14 @@ void TestAfterDivZeroChecker::reportBug(SVal Val, CheckerContext &C) const { if (!DivZeroBug) DivZeroBug.reset(new BuiltinBug(this, "Division by zero")); - BugReport *R = - new BugReport(*DivZeroBug, "Value being compared against zero has " - "already been used for division", - N); + auto R = llvm::make_unique<BugReport>( + *DivZeroBug, "Value being compared against zero has already been used " + "for division", + N); R->addVisitor(llvm::make_unique<DivisionBRVisitor>(Val.getAsSymbol(), C.getStackFrame())); - C.emitReport(R); + C.emitReport(std::move(R)); } } diff --git a/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp b/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp index fc49a46eae58d0eec9f4952f4c5d4391b32aef33..12c1e9f0671d1939583edebe6a359f963af33d86 100644 --- a/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp @@ -98,11 +98,11 @@ void UndefBranchChecker::checkBranchCondition(const Stmt *Condition, Ex = FindIt.FindExpr(Ex); // Emit the bug report. - BugReport *R = new BugReport(*BT, BT->getDescription(), N); + auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N); bugreporter::trackNullOrUndefValue(N, Ex, *R); R->addRange(Ex->getSourceRange()); - Ctx.emitReport(R); + Ctx.emitReport(std::move(R)); } } } diff --git a/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp b/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp index 8976e0a699ec9346662ff313b756b4f77be72953..c42a2b2984fac72642d110252749e7b4d6f86369 100644 --- a/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp @@ -89,14 +89,14 @@ UndefCapturedBlockVarChecker::checkPostStmt(const BlockExpr *BE, os << "Variable '" << VD->getName() << "' is uninitialized when captured by block"; - BugReport *R = new BugReport(*BT, os.str(), N); + auto R = llvm::make_unique<BugReport>(*BT, os.str(), N); if (const Expr *Ex = FindBlockDeclRefExpr(BE->getBody(), VD)) R->addRange(Ex->getSourceRange()); R->addVisitor(llvm::make_unique<FindLastStoreBRVisitor>( *V, VR, /*EnableNullFPSuppression*/ false)); R->disablePathPruning(); // need location of block - C.emitReport(R); + C.emitReport(std::move(R)); } } } diff --git a/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp b/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp index f3f4dce8b17d242182fb3469cd53b3e06407adf3..5353310e6d5a950e9540b5b4e882dea4934779ab 100644 --- a/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp @@ -84,7 +84,7 @@ void UndefResultChecker::checkPostStmt(const BinaryOperator *B, << BinaryOperator::getOpcodeStr(B->getOpcode()) << "' expression is undefined"; } - BugReport *report = new BugReport(*BT, OS.str(), N); + auto report = llvm::make_unique<BugReport>(*BT, OS.str(), N); if (Ex) { report->addRange(Ex->getSourceRange()); bugreporter::trackNullOrUndefValue(N, Ex, *report); @@ -92,7 +92,7 @@ void UndefResultChecker::checkPostStmt(const BinaryOperator *B, else bugreporter::trackNullOrUndefValue(N, B, *report); - C.emitReport(report); + C.emitReport(std::move(report)); } } diff --git a/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp b/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp index e952671efffcac8d3c131556f28c31a21756ceb7..ba4daf835148b1b3cc1da5135275de965a0d3187 100644 --- a/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp @@ -53,10 +53,10 @@ UndefinedArraySubscriptChecker::checkPreStmt(const ArraySubscriptExpr *A, BT.reset(new BuiltinBug(this, "Array subscript is undefined")); // Generate a report for this bug. - BugReport *R = new BugReport(*BT, BT->getName(), N); + auto R = llvm::make_unique<BugReport>(*BT, BT->getName(), N); R->addRange(A->getIdx()->getSourceRange()); bugreporter::trackNullOrUndefValue(N, A->getIdx(), *R); - C.emitReport(R); + C.emitReport(std::move(R)); } void ento::registerUndefinedArraySubscriptChecker(CheckerManager &mgr) { diff --git a/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp b/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp index bd4493d556056ba6f21a6fdeb3e837f67fe9b200..81c96c4860bc9c6d91199038097581466642490d 100644 --- a/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp @@ -83,12 +83,12 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val, break; } - BugReport *R = new BugReport(*BT, str, N); + auto R = llvm::make_unique<BugReport>(*BT, str, N); if (ex) { R->addRange(ex->getSourceRange()); bugreporter::trackNullOrUndefValue(N, ex, *R); } - C.emitReport(R); + C.emitReport(std::move(R)); } void ento::registerUndefinedAssignmentChecker(CheckerManager &mgr) { diff --git a/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp b/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp index 4bfed8504f985bd538090a0ed92d3aae23938dd6..a799b4c2198283310c85e7e3eb61ab369031090d 100644 --- a/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp @@ -83,9 +83,9 @@ void UnixAPIChecker::ReportOpenBug(CheckerContext &C, LazyInitialize(BT_open, "Improper use of 'open'"); - BugReport *Report = new BugReport(*BT_open, Msg, N); + auto Report = llvm::make_unique<BugReport>(*BT_open, Msg, N); Report->addRange(SR); - C.emitReport(Report); + C.emitReport(std::move(Report)); } void UnixAPIChecker::CheckOpen(CheckerContext &C, const CallExpr *CE) const { @@ -200,9 +200,9 @@ void UnixAPIChecker::CheckPthreadOnce(CheckerContext &C, LazyInitialize(BT_pthreadOnce, "Improper use of 'pthread_once'"); - BugReport *report = new BugReport(*BT_pthreadOnce, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT_pthreadOnce, os.str(), N); report->addRange(CE->getArg(0)->getSourceRange()); - C.emitReport(report); + C.emitReport(std::move(report)); } //===----------------------------------------------------------------------===// @@ -241,11 +241,11 @@ bool UnixAPIChecker::ReportZeroByteAllocation(CheckerContext &C, SmallString<256> S; llvm::raw_svector_ostream os(S); os << "Call to '" << fn_name << "' has an allocation size of 0 bytes"; - BugReport *report = new BugReport(*BT_mallocZero, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT_mallocZero, os.str(), N); report->addRange(arg->getSourceRange()); bugreporter::trackNullOrUndefValue(N, arg, *report); - C.emitReport(report); + C.emitReport(std::move(report)); return true; } diff --git a/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp b/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp index cceffef82b36e879ca24fb4bf6082e51a54f8587..80384bbfdb3098a85965431da44d338004a6f1a5 100644 --- a/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp @@ -72,10 +72,10 @@ void VLASizeChecker::reportBug(VLASize_Kind Kind, break; } - BugReport *report = new BugReport(*BT, os.str(), N); + auto report = llvm::make_unique<BugReport>(*BT, os.str(), N); report->addRange(SizeE->getSourceRange()); bugreporter::trackNullOrUndefValue(N, SizeE, *report); - C.emitReport(report); + C.emitReport(std::move(report)); return; } diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp index 97e97ef8c4d68aeabb5922dab57a9f99da6f6d1e..a42b4ef2dbe5a5c6f844b48c8d9de5601c6b4759 100644 --- a/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -3224,10 +3224,7 @@ void BugReporter::Register(BugType *BT) { BugTypes = F.add(BugTypes, BT); } -void BugReporter::emitReport(BugReport* R) { - // To guarantee memory release. - std::unique_ptr<BugReport> UniqueR(R); - +void BugReporter::emitReport(std::unique_ptr<BugReport> R) { if (const ExplodedNode *E = R->getErrorNode()) { const AnalysisDeclContext *DeclCtx = E->getLocationContext()->getAnalysisDeclContext(); @@ -3258,11 +3255,11 @@ void BugReporter::emitReport(BugReport* R) { BugReportEquivClass* EQ = EQClasses.FindNodeOrInsertPos(ID, InsertPos); if (!EQ) { - EQ = new BugReportEquivClass(std::move(UniqueR)); + EQ = new BugReportEquivClass(std::move(R)); EQClasses.InsertNode(EQ, InsertPos); EQClassesVector.push_back(EQ); } else - EQ->AddReport(std::move(UniqueR)); + EQ->AddReport(std::move(R)); } @@ -3462,12 +3459,12 @@ void BugReporter::EmitBasicReport(const Decl *DeclWithIssue, // 'BT' is owned by BugReporter. BugType *BT = getBugTypeForName(CheckName, name, category); - BugReport *R = new BugReport(*BT, str, Loc); + auto R = llvm::make_unique<BugReport>(*BT, str, Loc); R->setDeclWithIssue(DeclWithIssue); for (ArrayRef<SourceRange>::iterator I = Ranges.begin(), E = Ranges.end(); I != E; ++I) R->addRange(*I); - emitReport(R); + emitReport(std::move(R)); } BugType *BugReporter::getBugTypeForName(CheckName CheckName, StringRef name,