diff options
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 49eef236e9064..6ee87a561e020 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/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))); } } |