Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -1894,6 +1894,22 @@ return SFC->getAnalysisDeclContext()->isBodyAutosynthesized(); } +bool +isAnnotatedToSkipDiagnostics(const LocationContext *LCtx) { + while (LCtx) { + if (const StackFrameContext *SFC = dyn_cast(LCtx)) { + const Decl *D = SFC->getDecl(); + for (const auto *Ann : D->specific_attrs()){ + if (Ann->getAnnotation() == "rc_ownership_trusted_implementation") { + return true; + } + } + } + LCtx = LCtx->getParent(); + } + return false; +} + std::shared_ptr CFRefReportVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN, BugReporterContext &BRC, BugReport &BR) { @@ -3345,11 +3361,13 @@ } assert(BT); - auto report = std::unique_ptr( - new CFRefReport(*BT, C.getASTContext().getLangOpts(), C.isObjCGCEnabled(), - SummaryLog, N, Sym)); - report->addRange(ErrorRange); - C.emitReport(std::move(report)); + if (!isAnnotatedToSkipDiagnostics(N->getLocationContext())){ + auto report = std::unique_ptr( + new CFRefReport(*BT, C.getASTContext().getLangOpts(), C.isObjCGCEnabled(), + SummaryLog, N, Sym)); + report->addRange(ErrorRange); + C.emitReport(std::move(report)); + } } //===----------------------------------------------------------------------===// @@ -3579,9 +3597,10 @@ if (N) { const LangOptions &LOpts = C.getASTContext().getLangOpts(); bool GCEnabled = C.isObjCGCEnabled(); - C.emitReport(std::unique_ptr(new CFRefLeakReport( - *getLeakAtReturnBug(LOpts, GCEnabled), LOpts, GCEnabled, - SummaryLog, N, Sym, C, IncludeAllocationLine))); + if (!isAnnotatedToSkipDiagnostics(N->getLocationContext())) + C.emitReport(std::unique_ptr(new CFRefLeakReport( + *getLeakAtReturnBug(LOpts, GCEnabled), LOpts, GCEnabled, + SummaryLog, N, Sym, C, IncludeAllocationLine))); } } } @@ -3606,9 +3625,10 @@ if (!returnNotOwnedForOwned) returnNotOwnedForOwned.reset(new ReturnedNotOwnedForOwned(this)); - C.emitReport(std::unique_ptr(new CFRefReport( - *returnNotOwnedForOwned, C.getASTContext().getLangOpts(), - C.isObjCGCEnabled(), SummaryLog, N, Sym))); + if (!isAnnotatedToSkipDiagnostics(N->getLocationContext())) + C.emitReport(std::unique_ptr(new CFRefReport( + *returnNotOwnedForOwned, C.getASTContext().getLangOpts(), + C.isObjCGCEnabled(), SummaryLog, N, Sym))); } } } @@ -3811,9 +3831,10 @@ overAutorelease.reset(new OverAutorelease(this)); const LangOptions &LOpts = Ctx.getASTContext().getLangOpts(); - Ctx.emitReport(std::unique_ptr( - new CFRefReport(*overAutorelease, LOpts, /* GCEnabled = */ false, - SummaryLog, N, Sym, os.str()))); + if (!isAnnotatedToSkipDiagnostics(N->getLocationContext())) + Ctx.emitReport(std::unique_ptr( + new CFRefReport(*overAutorelease, LOpts, /* GCEnabled = */ false, + SummaryLog, N, Sym, os.str()))); } return nullptr; @@ -3865,9 +3886,10 @@ : getLeakAtReturnBug(LOpts, GCEnabled); assert(BT && "BugType not initialized."); - Ctx.emitReport(std::unique_ptr( - new CFRefLeakReport(*BT, LOpts, GCEnabled, SummaryLog, N, *I, Ctx, - IncludeAllocationLine))); + if (!isAnnotatedToSkipDiagnostics(N->getLocationContext())) + Ctx.emitReport(std::unique_ptr( + new CFRefLeakReport(*BT, LOpts, GCEnabled, SummaryLog, N, *I, Ctx, + IncludeAllocationLine))); } }