From: George Karpenkov Date: Fri, 30 Nov 2018 02:18:50 +0000 (+0000) Subject: [analyzer] Switch retain count checker for OSObject to use OS_* attributes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d72e681a0c38cf60710a2f7df30515f8712414c6;p=clang [analyzer] Switch retain count checker for OSObject to use OS_* attributes Instead of generalized reference counting annotations. Differential Revision: https://reviews.llvm.org/D55041 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347948 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp index 97ee9580c2..da47513e30 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp @@ -526,7 +526,8 @@ CFRefLeakReportVisitor::getEndPath(BugReporterContext &BRC, os << "that is annotated as CF_RETURNS_NOT_RETAINED"; } else if (D->hasAttr()) { os << "that is annotated as NS_RETURNS_NOT_RETAINED"; - // TODO: once the patch is ready, insert a case for OS_RETURNS_NOT_RETAINED + } else if (D->hasAttr()) { + os << "that is annotated as OS_RETURNS_NOT_RETAINED"; } else { if (const ObjCMethodDecl *MD = dyn_cast(D)) { if (BRC.getASTContext().getLangOpts().ObjCAutoRefCount) { diff --git a/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp b/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp index cbaee85beb..fc4544f843 100644 --- a/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp +++ b/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp @@ -664,15 +664,21 @@ RetainSummaryManager::getRetEffectFromAnnotations(QualType RetTy, return None; } - if (D->hasAttr()) + if (D->hasAttr()) { return RetEffect::MakeOwned(RetEffect::CF); - else if (hasRCAnnotation(D, "rc_ownership_returns_retained")) + } else if (D->hasAttr()) { + return RetEffect::MakeOwned(RetEffect::OS); + } else if (hasRCAnnotation(D, "rc_ownership_returns_retained")) { return RetEffect::MakeOwned(RetEffect::Generalized); + } - if (D->hasAttr()) + if (D->hasAttr()) { return RetEffect::MakeNotOwned(RetEffect::CF); - else if (hasRCAnnotation(D, "rc_ownership_returns_not_retained")) + } else if (D->hasAttr()) { + return RetEffect::MakeNotOwned(RetEffect::OS); + } else if (hasRCAnnotation(D, "rc_ownership_returns_not_retained")) { return RetEffect::MakeNotOwned(RetEffect::Generalized); + } return None; } @@ -688,15 +694,16 @@ RetainSummaryManager::updateSummaryFromAnnotations(const RetainSummary *&Summ, // Effects on the parameters. unsigned parm_idx = 0; - for (FunctionDecl::param_const_iterator pi = FD->param_begin(), + for (auto pi = FD->param_begin(), pe = FD->param_end(); pi != pe; ++pi, ++parm_idx) { const ParmVarDecl *pd = *pi; - if (pd->hasAttr()) + if (pd->hasAttr()) { Template->addArg(AF, parm_idx, DecRefMsg); - else if (pd->hasAttr() || - hasRCAnnotation(pd, "rc_ownership_consumed")) + } else if (pd->hasAttr() || + pd->hasAttr() || + hasRCAnnotation(pd, "rc_ownership_consumed")) { Template->addArg(AF, parm_idx, DecRef); - else if (pd->hasAttr() || + } else if (pd->hasAttr() || hasRCAnnotation(pd, "rc_ownership_returns_retained")) { QualType PointeeTy = pd->getType()->getPointeeType(); if (!PointeeTy.isNull()) @@ -734,9 +741,9 @@ RetainSummaryManager::updateSummaryFromAnnotations(const RetainSummary *&Summ, pi=MD->param_begin(), pe=MD->param_end(); pi != pe; ++pi, ++parm_idx) { const ParmVarDecl *pd = *pi; - if (pd->hasAttr()) + if (pd->hasAttr()) { Template->addArg(AF, parm_idx, DecRefMsg); - else if (pd->hasAttr()) { + } else if (pd->hasAttr() || pd->hasAttr()) { Template->addArg(AF, parm_idx, DecRef); } else if (pd->hasAttr()) { QualType PointeeTy = pd->getType()->getPointeeType(); diff --git a/test/Analysis/osobject-retain-release.cpp b/test/Analysis/osobject-retain-release.cpp index 46fc169965..ca5dfbf707 100644 --- a/test/Analysis/osobject-retain-release.cpp +++ b/test/Analysis/osobject-retain-release.cpp @@ -2,9 +2,9 @@ struct OSMetaClass; -#define OS_CONSUME __attribute__((annotate("rc_ownership_consumed"))) -#define OS_RETURNS_RETAINED __attribute__((annotate("rc_ownership_returns_retained"))) -#define OS_RETURNS_NOT_RETAINED __attribute__((annotate("rc_ownership_returns_not_retained"))) +#define OS_CONSUME __attribute__((os_consumed)) +#define OS_RETURNS_RETAINED __attribute__((os_returns_retained)) +#define OS_RETURNS_NOT_RETAINED __attribute__((os_returns_not_retained)) #define OSTypeID(type) (type::metaClass)