summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/CFRefCount.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-05-03 06:08:32 +0000
committerTed Kremenek <kremenek@apple.com>2009-05-03 06:08:32 +0000
commit4b59ccb563e074352cb8efd7d36462b6d7b162c5 (patch)
treecf3e447c98f4a6781e0ef5ba7f49cbc11f52b420 /clang/lib/Analysis/CFRefCount.cpp
parentc97d014a9a88fd2e7567120be3ca5fb2f9227432 (diff)
downloadbcm5719-llvm-4b59ccb563e074352cb8efd7d36462b6d7b162c5.tar.gz
bcm5719-llvm-4b59ccb563e074352cb8efd7d36462b6d7b162c5.zip
Fix: <rdar://problem/6850275> CF objects returned from methods with "new" or "copy" in their name should be treated as owned
For methods that follow the "fundamental rule" and return Core Foundation objects, treat those objects as owned by the caller. llvm-svn: 70665
Diffstat (limited to 'clang/lib/Analysis/CFRefCount.cpp')
-rw-r--r--clang/lib/Analysis/CFRefCount.cpp46
1 files changed, 33 insertions, 13 deletions
diff --git a/clang/lib/Analysis/CFRefCount.cpp b/clang/lib/Analysis/CFRefCount.cpp
index b9c9bb5923d..58f581aff83 100644
--- a/clang/lib/Analysis/CFRefCount.cpp
+++ b/clang/lib/Analysis/CFRefCount.cpp
@@ -621,6 +621,7 @@ public:
void InitializeMethodSummaries();
bool isTrackedObjCObjectType(QualType T);
+ bool isTrackedCFObjectType(QualType T);
private:
@@ -834,6 +835,14 @@ bool RetainSummaryManager::isTrackedObjCObjectType(QualType Ty) {
return false;
}
+bool RetainSummaryManager::isTrackedCFObjectType(QualType T) {
+ return isRefType(T, "CF") || // Core Foundation.
+ isRefType(T, "CG") || // Core Graphics.
+ isRefType(T, "DADisk") || // Disk Arbitration API.
+ isRefType(T, "DADissenter") ||
+ isRefType(T, "DASessionRef");
+}
+
//===----------------------------------------------------------------------===//
// Summary creation for functions (largely uses of Core Foundation).
//===----------------------------------------------------------------------===//
@@ -1170,26 +1179,37 @@ RetainSummaryManager::getCommonMethodSummary(const ObjCMethodDecl* MD,
assert(!str.empty());
if (CStrInCStrNoCase(&str[0], "delegate:")) ReceiverEff = StopTracking;
}
+
// Look for methods that return an owned object.
- if (!isTrackedObjCObjectType(RetTy)) {
- if (ScratchArgs.isEmpty() && ReceiverEff == DoNothing)
- return 0;
+ if (isTrackedObjCObjectType(RetTy)) {
+ // EXPERIMENTAL: Assume the Cocoa conventions for all objects returned
+ // by instance methods.
+
+ RetEffect E =
+ followsFundamentalRule(S.getIdentifierInfoForSlot(0)->getName())
+ ? (isGCEnabled() ? RetEffect::MakeGCNotOwned()
+ : RetEffect::MakeOwned(RetEffect::ObjC, true))
+ : RetEffect::MakeNotOwned(RetEffect::ObjC);
- return getPersistentSummary(RetEffect::MakeNoRet(), ReceiverEff,
- MayEscape);
+ return getPersistentSummary(E, ReceiverEff, MayEscape);
}
- // EXPERIMENTAL: Assume the Cocoa conventions for all objects returned
- // by instance methods.
+ // Look for methods that return an owned core foundation object.
+ if (isTrackedCFObjectType(RetTy)) {
+ RetEffect E =
+ followsFundamentalRule(S.getIdentifierInfoForSlot(0)->getName())
+ ? RetEffect::MakeOwned(RetEffect::CF, true)
+ : RetEffect::MakeNotOwned(RetEffect::CF);
+
+ return getPersistentSummary(E, ReceiverEff, MayEscape);
+ }
- RetEffect E =
- followsFundamentalRule(S.getIdentifierInfoForSlot(0)->getName())
- ? (isGCEnabled() ? RetEffect::MakeGCNotOwned()
- : RetEffect::MakeOwned(RetEffect::ObjC, true))
- : RetEffect::MakeNotOwned(RetEffect::ObjC);
+ if (ScratchArgs.isEmpty() && ReceiverEff == DoNothing)
+ return 0;
- return getPersistentSummary(E, ReceiverEff, MayEscape);
+ return getPersistentSummary(RetEffect::MakeNoRet(), ReceiverEff,
+ MayEscape);
}
RetainSummary*
OpenPOWER on IntegriCloud