[cfe-commits] r70507 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis/retain-release.m
Ted Kremenek
kremenek at apple.com
Thu Apr 30 13:00:31 PDT 2009
Author: kremenek
Date: Thu Apr 30 15:00:31 2009
New Revision: 70507
URL: http://llvm.org/viewvc/llvm-project?rev=70507&view=rev
Log:
retain/release checker: Hook up attributes 'objc_ownership_retain' and
'objc_ownership_release' to the effects on receivers.
Modified:
cfe/trunk/lib/Analysis/CFRefCount.cpp
cfe/trunk/test/Analysis/retain-release.m
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=70507&r1=70506&r2=70507&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Thu Apr 30 15:00:31 2009
@@ -1139,14 +1139,14 @@
assert(ScratchArgs.empty());
// Determine if there is a special return effect for this method.
- bool hasRetEffect = false;
+ bool hasEffect = false;
RetEffect RE = RetEffect::MakeNoRet();
if (isTrackedObjectType(MD->getResultType())) {
if (MD->getAttr<ObjCOwnershipReturnsAttr>()) {
RE = isGCEnabled() ? RetEffect::MakeGCNotOwned()
: RetEffect::MakeOwned(RetEffect::ObjC, true);
- hasRetEffect = true;
+ hasEffect = true;
}
else {
// Default to 'not owned'.
@@ -1155,36 +1155,46 @@
}
// Determine if there are any arguments with a specific ArgEffect.
- bool hasArgEffect = false;
unsigned i = 0;
for (ObjCMethodDecl::param_iterator I = MD->param_begin(),
E = MD->param_end(); I != E; ++I, ++i) {
if ((*I)->getAttr<ObjCOwnershipRetainAttr>()) {
ScratchArgs.push_back(std::make_pair(i, IncRefMsg));
- hasArgEffect = true;
+ hasEffect = true;
}
else if ((*I)->getAttr<ObjCOwnershipCFRetainAttr>()) {
ScratchArgs.push_back(std::make_pair(i, IncRef));
- hasArgEffect = true;
+ hasEffect = true;
}
else if ((*I)->getAttr<ObjCOwnershipReleaseAttr>()) {
ScratchArgs.push_back(std::make_pair(i, DecRefMsg));
- hasArgEffect = true;
+ hasEffect = true;
}
else if ((*I)->getAttr<ObjCOwnershipCFReleaseAttr>()) {
ScratchArgs.push_back(std::make_pair(i, DecRef));
- hasArgEffect = true;
+ hasEffect = true;
}
else if ((*I)->getAttr<ObjCOwnershipMakeCollectableAttr>()) {
ScratchArgs.push_back(std::make_pair(i, MakeCollectable));
- hasArgEffect = true;
+ hasEffect = true;
}
}
- if (!hasRetEffect && !hasArgEffect)
+ // Determine any effects on the receiver.
+ ArgEffect ReceiverEff = DoNothing;
+ if (MD->getAttr<ObjCOwnershipRetainAttr>()) {
+ ReceiverEff = IncRefMsg;
+ hasEffect = true;
+ }
+ else if (MD->getAttr<ObjCOwnershipReleaseAttr>()) {
+ ReceiverEff = DecRefMsg;
+ hasEffect = true;
+ }
+
+ if (!hasEffect)
return 0;
- return getPersistentSummary(RE);
+ return getPersistentSummary(RE, ReceiverEff);
}
RetainSummary*
Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=70507&r1=70506&r2=70507&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Thu Apr 30 15:00:31 2009
@@ -511,6 +511,21 @@
[X myCFRelease:str];
}
+void test_attr_6a() {
+ TestOwnershipAttr *X = [TestOwnershipAttr alloc]; // expected-warning{{leak}}
+}
+
+void test_attr_6b() {
+ TestOwnershipAttr *X = [TestOwnershipAttr alloc]; // no-warning
+ [X myRelease];
+}
+
+void test_attr_6c() {
+ TestOwnershipAttr *X = [TestOwnershipAttr alloc]; // expected-warning{{leak}}
+ [X myRetain];
+ [X myRelease];
+}
+
//===----------------------------------------------------------------------===//
// <rdar://problem/6833332>
// One build of the analyzer accidentally stopped tracking the allocated
More information about the cfe-commits
mailing list