summaryrefslogtreecommitdiffstats
path: root/test/Analysis
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-03-27 01:12:45 +0000
committerTed Kremenek <kremenek@apple.com>2012-03-27 01:12:45 +0000
commitde5b4fbe31e50641806234b3334eb9aa829673f8 (patch)
tree60226de9b49acb759fcd3d12cdce0ae939c55ff2 /test/Analysis
parent412e0cc52ea644d804dcfa87194800371f91a977 (diff)
Change RetainCountChecker to eagerly "escape" retained objects when they are
assigned to a struct. This is fallout from inlining results, which expose far more patterns where people stuff CF objects into structs and pass them around (and we can reason about it). The problem is that we don't have a general way to detect when values have escaped, so as an intermediate step we need to eagerly prune out such tracking. Fixes <rdar://problem/11104566>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153489 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/retain-release-region-store.m7
-rw-r--r--test/Analysis/retain-release.m23
2 files changed, 29 insertions, 1 deletions
diff --git a/test/Analysis/retain-release-region-store.m b/test/Analysis/retain-release-region-store.m
index 1ff31b710d..917381341a 100644
--- a/test/Analysis/retain-release-region-store.m
+++ b/test/Analysis/retain-release-region-store.m
@@ -100,6 +100,10 @@ struct foo {
NSDate* f;
};
+// FIXME: We should be warning about a use-after-free here, but we
+// temporarily "escape" retain counted objects stored to structs very eagerly
+// until we can properly tell whether they have escaped via a return value
+// or not.
CFAbsoluteTime f4() {
struct foo x;
@@ -110,7 +114,8 @@ CFAbsoluteTime f4() {
CFDateGetAbsoluteTime(date); // no-warning
x.f = (NSDate*) date;
[((NSDate*) date) release];
- t = CFDateGetAbsoluteTime(date); // expected-warning{{Reference-counted object is used after it is released}}
+ // FIXME: the following line should warn.
+ t = CFDateGetAbsoluteTime(date); // no-warning
return t;
}
diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m
index 8b0e7b83a7..fb02427eb4 100644
--- a/test/Analysis/retain-release.m
+++ b/test/Analysis/retain-release.m
@@ -1668,6 +1668,29 @@ void rdar_10824732() {
}
//===----------------------------------------------------------------------===//
+// Test returning allocated memory in a struct.
+//
+// We currently don't have a general way to track pointers that "escape".
+// Here we test that RetainCountChecker doesn't get excited about returning
+// allocated CF objects in struct fields.
+//===----------------------------------------------------------------------===//
+void *malloc(size_t);
+struct rdar11104566 { CFStringRef myStr; };
+struct rdar11104566 test_rdar11104566() {
+ CFStringRef cf = CFStringCreateWithCString( ((CFAllocatorRef)0), "test", kCFStringEncodingUTF8 ); // no-warning
+ struct rdar11104566 V;
+ V.myStr = cf;
+ return V; // no-warning
+}
+
+struct rdar11104566 *test_2_rdar11104566() {
+ CFStringRef cf = CFStringCreateWithCString( ((CFAllocatorRef)0), "test", kCFStringEncodingUTF8 ); // no-warning
+ struct rdar11104566 *V = (struct rdar11104566 *) malloc(sizeof(*V));
+ V->myStr = cf;
+ return V; // no-warning
+}
+
+//===----------------------------------------------------------------------===//
// ObjC literals support.
//===----------------------------------------------------------------------===//