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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70665 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Analysis/NSString.m b/test/Analysis/NSString.m
index 2f6d591..702551b 100644
--- a/test/Analysis/NSString.m
+++ b/test/Analysis/NSString.m
@@ -262,7 +262,7 @@
[string release]; // expected-warning{{Incorrect decrement of the reference count}}
}
-// Test isTrackedObjectType()
+// Test isTrackedObjectType().
typedef NSString* WonkyTypedef;
@interface TestIsTracked
+ (WonkyTypedef)newString;
@@ -272,6 +272,22 @@
NSString *str = [TestIsTracked newString]; // expected-warning{{Potential leak}}
}
+// Test isTrackedCFObjectType().
+@interface TestIsCFTracked
++ (CFStringRef) badNewCFString;
++ (CFStringRef) newCFString;
+@end
+
+@implementation TestIsCFTracked
++ (CFStringRef) newCFString {
+ return CFStringCreateWithFormat(kCFAllocatorDefault, ((void*)0), ((CFStringRef) __builtin___CFStringMakeConstantString ("" "%d" "")), 100); // no-warning
+}
++ (CFStringRef) badNewCFString {
+ return CFStringCreateWithFormat(kCFAllocatorDefault, ((void*)0), ((CFStringRef) __builtin___CFStringMakeConstantString ("" "%d" "")), 100); // expected-warning{{leak}}
+}
+
+
+
// Test @synchronized
void test_synchronized(id x) {
@synchronized(x) {
@@ -279,3 +295,4 @@
}
}
+// Test return from method starting with 'new' or 'copy'