[cfe-commits] r70990 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/Parse/AttributeList.h lib/Analysis/CFRefCount.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriter.cpp lib/Parse/AttributeList.cpp lib/Sema/SemaDeclAttr.cpp test/Analysis/retain-release.m
Ted Kremenek
kremenek at apple.com
Tue May 5 11:44:24 PDT 2009
Author: kremenek
Date: Tue May 5 13:44:20 2009
New Revision: 70990
URL: http://llvm.org/viewvc/llvm-project?rev=70990&view=rev
Log:
Implement attribute 'ns_autorelease'.
Modified:
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/Parse/AttributeList.h
cfe/trunk/lib/Analysis/CFRefCount.cpp
cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/lib/Parse/AttributeList.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Analysis/retain-release.m
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=70990&r1=70989&r2=70990&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Tue May 5 13:44:20 2009
@@ -62,6 +62,7 @@
CFOwnershipRelease, // Clang/Checker-specific.
CFOwnershipRetain, // Clang/Checker-specific.
CFOwnershipReturns, // Clang/Checker-specific.
+ NSOwnershipAutorelease, // Clang/Checker-specific.
NSOwnershipRelease, // Clang/Checker-specific.
NSOwnershipRetain, // Clang/Checker-specific.
NSOwnershipReturns, // Clang/Checker-specific.
@@ -471,6 +472,7 @@
DEF_SIMPLE_ATTR(CFOwnershipReturns);
DEF_SIMPLE_ATTR(NSOwnershipRelease);
DEF_SIMPLE_ATTR(NSOwnershipRetain);
+DEF_SIMPLE_ATTR(NSOwnershipAutorelease);
DEF_SIMPLE_ATTR(NSOwnershipReturns);
#undef DEF_SIMPLE_ATTR
Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=70990&r1=70989&r2=70990&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Tue May 5 13:44:20 2009
@@ -79,6 +79,7 @@
AT_cf_releases, // Clang-specific.
AT_cf_retains, // Clang-specific.
AT_cf_returns_owned, // Clang-specific.
+ AT_ns_autoreleases, // Clang-specific.
AT_ns_releases, // Clang-specific.
AT_ns_retains, // Clang-specific.
AT_ns_returns_owned, // Clang-specific.
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=70990&r1=70989&r2=70990&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Tue May 5 13:44:20 2009
@@ -779,8 +779,8 @@
RetainSummary* getCommonMethodSummary(const ObjCMethodDecl* MD,
Selector S, QualType RetTy);
- void updateSummaryArgEffFromAnnotations(RetainSummary &Summ, unsigned i,
- const ParmVarDecl *PD);
+ void updateSummaryArgEffFromAnnotations(RetainSummary &Summ, const Decl *D,
+ unsigned argIdx = 0);
void updateSummaryFromAnnotations(RetainSummary &Summ,
const ObjCMethodDecl *MD);
@@ -1097,22 +1097,32 @@
// 'init' methods only return an alias if the return type is a location type.
return getPersistentSummary(Loc::IsLocType(RetTy)
? RetEffect::MakeReceiverAlias()
- : RetEffect::MakeNoRet());
+ : RetEffect::MakeNoRet());
}
-
void
RetainSummaryManager::updateSummaryArgEffFromAnnotations(RetainSummary &Summ,
- unsigned i,
- const ParmVarDecl *PD){
- if (PD->getAttr<NSOwnershipRetainAttr>())
- Summ.setArgEffect(AF, i, IncRefMsg);
- else if (PD->getAttr<CFOwnershipRetainAttr>())
- Summ.setArgEffect(AF, i, IncRef);
- else if (PD->getAttr<NSOwnershipReleaseAttr>())
- Summ.setArgEffect(AF, i, DecRefMsg);
- else if (PD->getAttr<CFOwnershipReleaseAttr>())
- Summ.setArgEffect(AF, i, DecRef);
+ const Decl *D,
+ unsigned i) {
+ ArgEffect E = DoNothing;
+
+ if (D->getAttr<NSOwnershipRetainAttr>())
+ E = IncRefMsg;
+ else if (D->getAttr<CFOwnershipRetainAttr>())
+ E = IncRef;
+ else if (D->getAttr<NSOwnershipReleaseAttr>())
+ E = DecRefMsg;
+ else if (D->getAttr<CFOwnershipReleaseAttr>())
+ E = DecRef;
+ else if (D->getAttr<NSOwnershipAutoreleaseAttr>())
+ E = Autorelease;
+ else
+ return;
+
+ if (isa<ParmVarDecl>(D))
+ Summ.setArgEffect(AF, i, E);
+ else
+ Summ.setReceiverEffect(E);
}
void
@@ -1137,7 +1147,7 @@
unsigned i = 0;
for (FunctionDecl::param_const_iterator I = FD->param_begin(),
E = FD->param_end(); I != E; ++I, ++i)
- updateSummaryArgEffFromAnnotations(Summ, i, *I);
+ updateSummaryArgEffFromAnnotations(Summ, *I, i);
}
void
@@ -1162,13 +1172,10 @@
unsigned i = 0;
for (ObjCMethodDecl::param_iterator I = MD->param_begin(),
E = MD->param_end(); I != E; ++I, ++i)
- updateSummaryArgEffFromAnnotations(Summ, i, *I);
+ updateSummaryArgEffFromAnnotations(Summ, *I, i);
// Determine any effects on the receiver.
- if (MD->getAttr<NSOwnershipRetainAttr>())
- Summ.setReceiverEffect(IncRefMsg);
- else if (MD->getAttr<NSOwnershipReleaseAttr>())
- Summ.setReceiverEffect(DecRefMsg);
+ updateSummaryArgEffFromAnnotations(Summ, MD);
}
RetainSummary*
Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=70990&r1=70989&r2=70990&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Tue May 5 13:44:20 2009
@@ -478,6 +478,7 @@
SIMPLE_ATTR(CFOwnershipRelease);
SIMPLE_ATTR(CFOwnershipRetain);
SIMPLE_ATTR(CFOwnershipReturns);
+ SIMPLE_ATTR(NSOwnershipAutorelease);
SIMPLE_ATTR(NSOwnershipRelease);
SIMPLE_ATTR(NSOwnershipRetain);
SIMPLE_ATTR(NSOwnershipReturns);
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=70990&r1=70989&r2=70990&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Tue May 5 13:44:20 2009
@@ -1552,6 +1552,7 @@
case Attr::CFOwnershipRelease:
case Attr::CFOwnershipRetain:
case Attr::CFOwnershipReturns:
+ case Attr::NSOwnershipAutorelease:
case Attr::NSOwnershipRelease:
case Attr::NSOwnershipRetain:
case Attr::NSOwnershipReturns:
Modified: cfe/trunk/lib/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AttributeList.cpp?rev=70990&r1=70989&r2=70990&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/AttributeList.cpp (original)
+++ cfe/trunk/lib/Parse/AttributeList.cpp Tue May 5 13:44:20 2009
@@ -129,6 +129,7 @@
break;
case 15:
if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type;
+ if (!memcmp(Str, "ns_autoreleases", 15)) return AT_ns_autoreleases;
break;
case 16:
if (!memcmp(Str, "ns_returns_owned", 16)) return AT_ns_returns_owned;
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=70990&r1=70989&r2=70990&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue May 5 13:44:20 2009
@@ -1595,6 +1595,8 @@
name = "cf_releases"; break;
case AttributeList::AT_cf_retains:
name = "cf_retains"; break;
+ case AttributeList::AT_ns_autoreleases:
+ name = "ns_autoreleases"; break;
case AttributeList::AT_ns_releases:
name = "ns_releases"; break;
case AttributeList::AT_ns_retains:
@@ -1617,6 +1619,9 @@
case AttributeList::AT_cf_retains:
d->addAttr(::new (S.Context) CFOwnershipRetainAttr());
return;
+ case AttributeList::AT_ns_autoreleases:
+ d->addAttr(::new (S.Context) NSOwnershipAutoreleaseAttr());
+ return;
case AttributeList::AT_ns_releases:
d->addAttr(::new (S.Context) NSOwnershipReleaseAttr());
return;
@@ -1667,6 +1672,7 @@
case AttributeList::AT_cf_releases:
case AttributeList::AT_cf_retains:
HandleNSOwnershipAttr(D, Attr, S); break;
+ case AttributeList::AT_ns_autoreleases:
case AttributeList::AT_ns_releases:
case AttributeList::AT_ns_retains:
HandleNSOwnershipAttr(D, Attr, S, true); break;
Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=70990&r1=70989&r2=70990&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Tue May 5 13:44:20 2009
@@ -439,6 +439,8 @@
- (void) myCFRelease:(id)__attribute__((cf_releases))obj;
- (void) myRetain __attribute__((ns_retains));
- (void) myRelease __attribute__((ns_releases));
+- (void) myAutorelease __attribute__((ns_autoreleases));
+- (void) myAutorelease:(id)__attribute__((ns_autoreleases))obj;
@end
@interface TestAttrHelper : NSObject
@@ -478,6 +480,10 @@
return str;
}
+void test_attr_1e(TestOwnershipAttr *X) {
+ NSString *str = [X returnsAnOwnedString]; // no-warning
+ [X myAutorelease:str];
+}
void test_attr_2(TestOwnershipAttr *X) {
NSString *str = [X returnsAnOwnedString]; // expected-warning{{leak}}
@@ -548,6 +554,11 @@
[X myRelease];
}
+void test_attr_6d() {
+ TestOwnershipAttr *X = [TestOwnershipAttr alloc]; // no-warning
+ [X myAutorelease];
+}
+
//===----------------------------------------------------------------------===//
// <rdar://problem/6833332>
// One build of the analyzer accidentally stopped tracking the allocated
More information about the cfe-commits
mailing list