r347948 - [analyzer] Switch retain count checker for OSObject to use OS_* attributes
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 29 18:18:50 PST 2018
Author: george.karpenkov
Date: Thu Nov 29 18:18:50 2018
New Revision: 347948
URL: http://llvm.org/viewvc/llvm-project?rev=347948&view=rev
Log:
[analyzer] Switch retain count checker for OSObject to use OS_* attributes
Instead of generalized reference counting annotations.
Differential Revision: https://reviews.llvm.org/D55041
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
cfe/trunk/test/Analysis/osobject-retain-release.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp?rev=347948&r1=347947&r2=347948&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp Thu Nov 29 18:18:50 2018
@@ -526,7 +526,8 @@ CFRefLeakReportVisitor::getEndPath(BugRe
os << "that is annotated as CF_RETURNS_NOT_RETAINED";
} else if (D->hasAttr<NSReturnsNotRetainedAttr>()) {
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<OSReturnsNotRetainedAttr>()) {
+ os << "that is annotated as OS_RETURNS_NOT_RETAINED";
} else {
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
if (BRC.getASTContext().getLangOpts().ObjCAutoRefCount) {
Modified: cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp?rev=347948&r1=347947&r2=347948&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp Thu Nov 29 18:18:50 2018
@@ -664,15 +664,21 @@ RetainSummaryManager::getRetEffectFromAn
return None;
}
- if (D->hasAttr<CFReturnsRetainedAttr>())
+ if (D->hasAttr<CFReturnsRetainedAttr>()) {
return RetEffect::MakeOwned(RetEffect::CF);
- else if (hasRCAnnotation(D, "rc_ownership_returns_retained"))
+ } else if (D->hasAttr<OSReturnsRetainedAttr>()) {
+ return RetEffect::MakeOwned(RetEffect::OS);
+ } else if (hasRCAnnotation(D, "rc_ownership_returns_retained")) {
return RetEffect::MakeOwned(RetEffect::Generalized);
+ }
- if (D->hasAttr<CFReturnsNotRetainedAttr>())
+ if (D->hasAttr<CFReturnsNotRetainedAttr>()) {
return RetEffect::MakeNotOwned(RetEffect::CF);
- else if (hasRCAnnotation(D, "rc_ownership_returns_not_retained"))
+ } else if (D->hasAttr<OSReturnsNotRetainedAttr>()) {
+ 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::updateSummaryFromA
// 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<NSConsumedAttr>())
+ if (pd->hasAttr<NSConsumedAttr>()) {
Template->addArg(AF, parm_idx, DecRefMsg);
- else if (pd->hasAttr<CFConsumedAttr>() ||
- hasRCAnnotation(pd, "rc_ownership_consumed"))
+ } else if (pd->hasAttr<CFConsumedAttr>() ||
+ pd->hasAttr<OSConsumedAttr>() ||
+ hasRCAnnotation(pd, "rc_ownership_consumed")) {
Template->addArg(AF, parm_idx, DecRef);
- else if (pd->hasAttr<CFReturnsRetainedAttr>() ||
+ } else if (pd->hasAttr<CFReturnsRetainedAttr>() ||
hasRCAnnotation(pd, "rc_ownership_returns_retained")) {
QualType PointeeTy = pd->getType()->getPointeeType();
if (!PointeeTy.isNull())
@@ -734,9 +741,9 @@ RetainSummaryManager::updateSummaryFromA
pi=MD->param_begin(), pe=MD->param_end();
pi != pe; ++pi, ++parm_idx) {
const ParmVarDecl *pd = *pi;
- if (pd->hasAttr<NSConsumedAttr>())
+ if (pd->hasAttr<NSConsumedAttr>()) {
Template->addArg(AF, parm_idx, DecRefMsg);
- else if (pd->hasAttr<CFConsumedAttr>()) {
+ } else if (pd->hasAttr<CFConsumedAttr>() || pd->hasAttr<OSConsumedAttr>()) {
Template->addArg(AF, parm_idx, DecRef);
} else if (pd->hasAttr<CFReturnsRetainedAttr>()) {
QualType PointeeTy = pd->getType()->getPointeeType();
Modified: cfe/trunk/test/Analysis/osobject-retain-release.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/osobject-retain-release.cpp?rev=347948&r1=347947&r2=347948&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp (original)
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp Thu Nov 29 18:18:50 2018
@@ -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)
More information about the cfe-commits
mailing list