[cfe-commits] r70235 - 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-gc-only.m test/Analysis/retain-release.m
Ted Kremenek
kremenek at apple.com
Mon Apr 27 12:37:09 PDT 2009
Author: kremenek
Date: Mon Apr 27 14:36:56 2009
New Revision: 70235
URL: http://llvm.org/viewvc/llvm-project?rev=70235&view=rev
Log:
Add two new checker-specific attributes: 'objc_ownership_release' and
'objc_ownership_cfrelease'. These are the 'release' equivalents of
'objc_ownership_retain' and 'objc_ownership_cfretain' respectively.
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-gc-only.m
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=70235&r1=70234&r2=70235&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Mon Apr 27 14:36:56 2009
@@ -51,9 +51,11 @@
NonNull,
ObjCException,
ObjCNSObject,
- ObjCOwnershipRetain, // Clang/Checker-specific.
- ObjCOwnershipCFRetain, // Clang/Checker-specific.
- ObjCOwnershipReturns, // Clang/Checker-specific.
+ ObjCOwnershipCFRelease, // Clang/Checker-specific.
+ ObjCOwnershipCFRetain, // Clang/Checker-specific.
+ ObjCOwnershipRelease, // Clang/Checker-specific.
+ ObjCOwnershipRetain, // Clang/Checker-specific.
+ ObjCOwnershipReturns, // Clang/Checker-specific.
Overloadable, // Clang-specific
Packed,
Pure,
@@ -601,6 +603,8 @@
};
// Checker-specific attributes.
+DEF_SIMPLE_ATTR(ObjCOwnershipCFRelease)
+DEF_SIMPLE_ATTR(ObjCOwnershipRelease)
DEF_SIMPLE_ATTR(ObjCOwnershipCFRetain)
DEF_SIMPLE_ATTR(ObjCOwnershipRetain)
DEF_SIMPLE_ATTR(ObjCOwnershipReturns)
Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=70235&r1=70234&r2=70235&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Mon Apr 27 14:36:56 2009
@@ -76,9 +76,11 @@
AT_nothrow,
AT_nsobject,
AT_objc_exception,
- AT_objc_ownership_cfretain, // Clang-specific.
- AT_objc_ownership_retain, // Clang-specific.
- AT_objc_ownership_returns, // Clang-specific.
+ AT_objc_ownership_cfrelease, // Clang-specific.
+ AT_objc_ownership_cfretain, // Clang-specific.
+ AT_objc_ownership_release, // Clang-specific.
+ AT_objc_ownership_retain, // Clang-specific.
+ AT_objc_ownership_returns, // Clang-specific.
AT_objc_gc,
AT_overloadable, // Clang-specific.
AT_packed,
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=70235&r1=70234&r2=70235&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Mon Apr 27 14:36:56 2009
@@ -1112,7 +1112,15 @@
else if ((*I)->getAttr<ObjCOwnershipCFRetainAttr>()) {
ScratchArgs.push_back(std::make_pair(i, IncRef));
hasArgEffect = true;
- }
+ }
+ else if ((*I)->getAttr<ObjCOwnershipReleaseAttr>()) {
+ ScratchArgs.push_back(std::make_pair(i, DecRefMsg));
+ hasArgEffect = true;
+ }
+ else if ((*I)->getAttr<ObjCOwnershipCFReleaseAttr>()) {
+ ScratchArgs.push_back(std::make_pair(i, DecRef));
+ hasArgEffect = true;
+ }
}
if (!hasRetEffect && !hasArgEffect)
Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=70235&r1=70234&r2=70235&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Mon Apr 27 14:36:56 2009
@@ -475,6 +475,8 @@
SIMPLE_ATTR(ObjCException);
SIMPLE_ATTR(ObjCNSObject);
+ SIMPLE_ATTR(ObjCOwnershipCFRelease);
+ SIMPLE_ATTR(ObjCOwnershipRelease);
SIMPLE_ATTR(ObjCOwnershipCFRetain);
SIMPLE_ATTR(ObjCOwnershipRetain);
SIMPLE_ATTR(ObjCOwnershipReturns);
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=70235&r1=70234&r2=70235&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Mon Apr 27 14:36:56 2009
@@ -1539,6 +1539,8 @@
case Attr::ObjCException:
case Attr::ObjCNSObject:
+ case Attr::ObjCOwnershipCFRelease:
+ case Attr::ObjCOwnershipRelease:
case Attr::ObjCOwnershipCFRetain:
case Attr::ObjCOwnershipRetain:
case Attr::ObjCOwnershipReturns:
Modified: cfe/trunk/lib/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AttributeList.cpp?rev=70235&r1=70234&r2=70235&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/AttributeList.cpp (original)
+++ cfe/trunk/lib/Parse/AttributeList.cpp Mon Apr 27 14:36:56 2009
@@ -140,6 +140,8 @@
case 22:
if (!memcmp(Str, "objc_ownership_returns", 22))
return AT_objc_ownership_returns;
+ if (!memcmp(Str, "objc_ownership_release", 22))
+ return AT_objc_ownership_release;
if (!memcmp(Str, "no_instrument_function", 22))
return AT_no_instrument_function;
break;
@@ -147,6 +149,10 @@
if (!memcmp(Str, "objc_ownership_cfretain", 23))
return AT_objc_ownership_cfretain;
break;
- }
+ case 24:
+ if (!memcmp(Str, "objc_ownership_cfrelease", 24))
+ return AT_objc_ownership_cfrelease;
+ break;
+ }
return UnknownAttribute;
}
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=70235&r1=70234&r2=70235&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Apr 27 14:36:56 2009
@@ -1543,6 +1543,10 @@
default:
assert(0 && "invalid ownership attribute");
return;
+ case AttributeList::AT_objc_ownership_release:
+ name = "objc_ownership_release"; break;
+ case AttributeList::AT_objc_ownership_cfrelease:
+ name = "objc_ownership_cfrelease"; break;
case AttributeList::AT_objc_ownership_retain:
name = "objc_ownership_retain"; break;
case AttributeList::AT_objc_ownership_cfretain:
@@ -1558,6 +1562,10 @@
default:
assert(0 && "invalid ownership attribute");
return;
+ case AttributeList::AT_objc_ownership_release:
+ d->addAttr(::new (S.Context) ObjCOwnershipReleaseAttr()); return;
+ case AttributeList::AT_objc_ownership_cfrelease:
+ d->addAttr(::new (S.Context) ObjCOwnershipCFReleaseAttr()); return;
case AttributeList::AT_objc_ownership_retain:
d->addAttr(::new (S.Context) ObjCOwnershipRetainAttr()); return;
case AttributeList::AT_objc_ownership_cfretain:
@@ -1603,6 +1611,8 @@
case AttributeList::AT_nothrow: HandleNothrowAttr (D, Attr, S); break;
// Checker-specific.
+ case AttributeList::AT_objc_ownership_release:
+ case AttributeList::AT_objc_ownership_cfrelease:
case AttributeList::AT_objc_ownership_retain:
case AttributeList::AT_objc_ownership_cfretain:
HandleObjCOwnershipParmAttr(D, Attr, S); break;
Modified: cfe/trunk/test/Analysis/retain-release-gc-only.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release-gc-only.m?rev=70235&r1=70234&r2=70235&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release-gc-only.m (original)
+++ cfe/trunk/test/Analysis/retain-release-gc-only.m Mon Apr 27 14:36:56 2009
@@ -132,6 +132,8 @@
- (NSString*) returnsAnOwnedString __attribute__((objc_ownership_returns));
- (void) myRetain:(id)__attribute__((objc_ownership_retain))obj;
- (void) myCFRetain:(id)__attribute__((objc_ownership_cfretain))obj;
+- (void) myRelease:(id)__attribute__((objc_ownership_release))obj;
+- (void) myCFRelease:(id)__attribute__((objc_ownership_cfrelease))obj;
@end
void test_attr_1(TestOwnershipAttr *X) {
@@ -149,3 +151,15 @@
[X myCFRetain:str];
[str release];
}
+
+void test_attr_4(TestOwnershipAttr *X) {
+ NSString *str = [X returnsAnOwnedString]; // no-warning
+ [X myRetain:str];
+ [X myRelease:str];
+}
+
+void test_attr_5(TestOwnershipAttr *X) {
+ NSString *str = [X returnsAnOwnedString]; // no-warning
+ [X myCFRetain:str];
+ [X myCFRelease:str];
+}
Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=70235&r1=70234&r2=70235&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Mon Apr 27 14:36:56 2009
@@ -413,6 +413,8 @@
- (NSString*) returnsAnOwnedString __attribute__((objc_ownership_returns));
- (void) myRetain:(id)__attribute__((objc_ownership_retain))obj;
- (void) myCFRetain:(id)__attribute__((objc_ownership_cfretain))obj;
+- (void) myRelease:(id)__attribute__((objc_ownership_release))obj;
+- (void) myCFRelease:(id)__attribute__((objc_ownership_cfrelease))obj;
@end
void test_attr_1(TestOwnershipAttr *X) {
@@ -431,3 +433,15 @@
[str release];
}
+void test_attr_4(TestOwnershipAttr *X) {
+ NSString *str = [X returnsAnOwnedString]; // expected-warning{{leak}}
+ [X myRetain:str];
+ [X myRelease:str];
+}
+
+void test_attr_5(TestOwnershipAttr *X) {
+ NSString *str = [X returnsAnOwnedString]; // expected-warning{{leak}}
+ [X myCFRetain:str];
+ [X myCFRelease:str];
+}
+
More information about the cfe-commits
mailing list