diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers')
52 files changed, 287 insertions, 322 deletions
diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp index cb5b010..557439b 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp index e462e2b..d8dc2aa 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp index 3fd5576..f763284 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp index 83a37c9..e945c38 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp index 0f5741b..54b1241 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp index abfb971d..3db1994 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp @@ -168,10 +168,9 @@ void WalkAST::VisitCallExpr(CallExpr *CE) { } void WalkAST::VisitChildren(Stmt *S) { - for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I != E; - ++I) - if (Stmt *child = *I) - Visit(child); + for (Stmt *Child : S->children()) + if (Child) + Visit(Child); } namespace { diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp index adb7a54..26423b7 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp index 3ba063d..0d683f9 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp index d765315..ba3024d 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp index 339af8f..12eb0bd 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp @@ -69,8 +69,8 @@ static bool scan_ivar_release(Stmt *S, ObjCIvarDecl *ID, } // Recurse to children. - for (Stmt::child_iterator I = S->child_begin(), E= S->child_end(); I!=E; ++I) - if (*I && scan_ivar_release(*I, ID, PD, Release, SelfII, Ctx)) + for (Stmt *SubStmt : S->children()) + if (SubStmt && scan_ivar_release(SubStmt, ID, PD, Release, SelfII, Ctx)) return true; return false; diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp index 0beb917..e0c113c 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp @@ -109,9 +109,9 @@ public: //===----------------------------------------------------------------------===// void WalkAST::VisitChildren(Stmt *S) { - for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I) - if (Stmt *child = *I) - Visit(child); + for (Stmt *Child : S->children()) + if (Child) + Visit(Child); } void WalkAST::VisitCallExpr(CallExpr *CE) { @@ -162,11 +162,11 @@ void WalkAST::VisitCallExpr(CallExpr *CE) { } void WalkAST::VisitCompoundStmt(CompoundStmt *S) { - for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I) - if (Stmt *child = *I) { - if (CallExpr *CE = dyn_cast<CallExpr>(child)) + for (Stmt *Child : S->children()) + if (Child) { + if (CallExpr *CE = dyn_cast<CallExpr>(Child)) checkUncheckedReturnValue(CE); - Visit(child); + Visit(Child); } } diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp index a61e658..81a2006 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp @@ -37,9 +37,9 @@ public: } void WalkAST::VisitChildren(Stmt *S) { - for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I) - if (Stmt *child = *I) - Visit(child); + for (Stmt *Child : S->children()) + if (Child) + Visit(Child); } // CWE-467: Use of sizeof() on a Pointer Type diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp index ad41577..804e83c 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp index 2e442c7..2ba7ea4 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp index 0bcebf6..a71def2 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp @@ -78,9 +78,9 @@ class DirectIvarAssignment : void VisitBinaryOperator(const BinaryOperator *BO); void VisitChildren(const Stmt *S) { - for (Stmt::const_child_range I = S->children(); I; ++I) - if (*I) - this->Visit(*I); + for (const Stmt *Child : S->children()) + if (Child) + this->Visit(Child); } }; diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp index e060c36..79f9479b 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp index f36ec2c..7dc0a87 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp index 60bb036..48d6bd4 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp index 275481f..2cf508f 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp index 02c1209..3df5fa0 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -167,9 +167,9 @@ class IvarInvalidationCheckerImpl { void VisitObjCMessageExpr(const ObjCMessageExpr *ME); void VisitChildren(const Stmt *S) { - for (Stmt::const_child_range I = S->children(); I; ++I) { - if (*I) - this->Visit(*I); + for (const Stmt *Child : S->children()) { + if (Child) + this->Visit(Child); if (CalledAnotherInvalidationMethod) return; } diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp index 0b7375a..4e3f9b7 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp @@ -124,10 +124,9 @@ public: const CheckerBase *checker) : DeclWithIssue(declWithIssue), BR(br), Checker(checker) {} void VisitChildren(Stmt *S) { - for (Stmt::child_iterator I = S->child_begin(), E = S->child_end() ; - I != E; ++I) - if (Stmt *child = *I) - Visit(child); + for (Stmt *Child : S->children()) + if (Child) + Visit(Child); } void VisitStmt(Stmt *S) { VisitChildren(S); } void VisitDeclStmt(DeclStmt *DS); diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp index 52e2936..7838901 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp index 13a401d..11ba609 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 0cf0094..a9e0865 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp index 296aec6..fb07484 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp @@ -65,10 +65,9 @@ public: } void VisitChildren(const Stmt *S) { - for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end(); - I!=E; ++I) - if (const Stmt *child = *I) - VisitChild(S, child); + for (const Stmt *Child : S->children()) + if (Child) + VisitChild(S, Child); } TypeCallPair VisitCastExpr(const CastExpr *E) { diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp index b180c03..d23708e 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/NSAutoreleasePoolChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp index 2be7f1d..c351c6e 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp index cb2d46b..73f8087 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp +++ b/contrib/llvm/tools/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) diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp index fbf2d73..a7b92b4 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp index e3fc611..224251b 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp @@ -153,9 +153,9 @@ void WalkAST::VisitCallExpr(CallExpr *CE) { } void WalkAST::VisitChildren(Stmt *S) { - for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I) - if (Stmt *child = *I) - Visit(child); + for (Stmt *Child : S->children()) + if (Child) + Visit(Child); } namespace { diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp index 4f0b7e5..53e1598 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp index 51bc7e6..93b0553 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp index d3b1753..c6da37e 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp @@ -57,8 +57,8 @@ static void Scan(IvarUsageMap& M, const Stmt *S) { Scan(M, sub); } - for (Stmt::const_child_iterator I=S->child_begin(),E=S->child_end(); I!=E;++I) - Scan(M, *I); + for (const Stmt *SubStmt : S->children()) + Scan(M, SubStmt); } static void Scan(IvarUsageMap& M, const ObjCPropertyImplDecl *D) { diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp index 00480e4..8063124 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp index fbb2628..cf1f88a 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp index 1ede3a2..4209017 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 49eef23..6ee87a5 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -2182,9 +2182,8 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N, // Add the range by scanning the children of the statement for any bindings // to Sym. - for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end(); - I!=E; ++I) - if (const Expr *Exp = dyn_cast_or_null<Expr>(*I)) + for (const Stmt *Child : S->children()) + if (const Expr *Exp = dyn_cast_or_null<Expr>(Child)) if (CurrSt->getSValAsScalarOrLoc(Exp, LCtx).getAsLocSymbol() == Sym) { P->addRange(Exp->getSourceRange()); break; @@ -2779,16 +2778,14 @@ void RetainCountChecker::processObjCLiterals(CheckerContext &C, const Expr *Ex) const { ProgramStateRef state = C.getState(); const ExplodedNode *pred = C.getPredecessor(); - for (Stmt::const_child_iterator it = Ex->child_begin(), et = Ex->child_end() ; - it != et ; ++it) { - const Stmt *child = *it; - SVal V = state->getSVal(child, pred->getLocationContext()); + for (const Stmt *Child : Ex->children()) { + SVal V = state->getSVal(Child, pred->getLocationContext()); if (SymbolRef sym = V.getAsSymbol()) if (const RefVal* T = getRefBinding(state, sym)) { RefVal::Kind hasErr = (RefVal::Kind) 0; state = updateSymbol(state, sym, *T, MayEscape, hasErr, C); if (hasErr) { - processNonLeakError(state, child->getSourceRange(), hasErr, sym, C); + processNonLeakError(state, Child->getSourceRange(), hasErr, sym, C); return; } } @@ -3320,31 +3317,31 @@ void RetainCountChecker::processNonLeakError(ProgramStateRef St, case RefVal::ErrorUseAfterRelease: if (!useAfterRelease) useAfterRelease.reset(new UseAfterRelease(this)); - BT = &*useAfterRelease; + BT = useAfterRelease.get(); break; case RefVal::ErrorReleaseNotOwned: if (!releaseNotOwned) releaseNotOwned.reset(new BadRelease(this)); - BT = &*releaseNotOwned; + BT = releaseNotOwned.get(); break; case RefVal::ErrorDeallocGC: if (!deallocGC) deallocGC.reset(new DeallocGC(this)); - BT = &*deallocGC; + BT = deallocGC.get(); break; case RefVal::ErrorDeallocNotOwned: if (!deallocNotOwned) deallocNotOwned.reset(new DeallocNotOwned(this)); - BT = &*deallocNotOwned; + BT = deallocNotOwned.get(); break; } 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 +3570,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 +3597,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 +3802,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 +3856,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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp index b1cde6b..acbd0d9 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp index 6622313..2668ac1 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/ReturnUndefChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp index ccf816c..c22e78b 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp index 327a9e0..813c811 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 894765a..2109a75 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp index d33c977..6e24775 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/TaintTesterChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp index 083075d..638701d 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp index fc49a46..1d8ef99 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp @@ -37,12 +37,10 @@ class UndefBranchChecker : public Checker<check::BranchCondition> { if (!MatchesCriteria(Ex)) return nullptr; - for (Stmt::const_child_iterator I = Ex->child_begin(), - E = Ex->child_end();I!=E;++I) - if (const Expr *ExI = dyn_cast_or_null<Expr>(*I)) { - const Expr *E2 = FindExpr(ExI); - if (E2) return E2; - } + for (const Stmt *SubStmt : Ex->children()) + if (const Expr *ExI = dyn_cast_or_null<Expr>(SubStmt)) + if (const Expr *E2 = FindExpr(ExI)) + return E2; return Ex; } @@ -98,11 +96,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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp index 8976e0a..53fd069 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp @@ -40,13 +40,10 @@ static const DeclRefExpr *FindBlockDeclRefExpr(const Stmt *S, if (BR->getDecl() == VD) return BR; - for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end(); - I!=E; ++I) - if (const Stmt *child = *I) { - const DeclRefExpr *BR = FindBlockDeclRefExpr(child, VD); - if (BR) + for (const Stmt *Child : S->children()) + if (Child) + if (const DeclRefExpr *BR = FindBlockDeclRefExpr(Child, VD)) return BR; - } return nullptr; } @@ -89,14 +86,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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp index f3f4dce..5353310 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp index e952671..ba4daf8 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp index bd4493d..81c96c4 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp index 4bfed85..a799b4c 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp index cceffef..80384bb 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp +++ b/contrib/llvm/tools/clang/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/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp index 7e1fc1e..f6ef4ae 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp @@ -125,9 +125,9 @@ public: //===----------------------------------------------------------------------===// void WalkAST::VisitChildren(Stmt *S) { - for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I) - if (Stmt *child = *I) - Visit(child); + for (Stmt *Child : S->children()) + if (Child) + Visit(Child); } void WalkAST::VisitCallExpr(CallExpr *CE) { |