aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-06-19 05:10:32 +0000
committerAnna Zaks <ganna@apple.com>2012-06-19 05:10:32 +0000
commit5f75768579b9b1d70d01903ab4766aede65defcc (patch)
tree2e69b3c0da50cdc99f5abcefb6e897f34bf1a0e1 /test
parentbfcb037a3479de4a453a8275c64ae441c22d43f9 (diff)
[analyzer] Allow pointers to escape into NSPointerArray.
(Fixes radar://11691035 PR13140) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158703 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Analysis/malloc.mm23
-rw-r--r--test/Analysis/system-header-simulator-objc.h8
2 files changed, 31 insertions, 0 deletions
diff --git a/test/Analysis/malloc.mm b/test/Analysis/malloc.mm
index ef1adda5a1..855892da2b 100644
--- a/test/Analysis/malloc.mm
+++ b/test/Analysis/malloc.mm
@@ -178,4 +178,27 @@ void testCallWithBlockCallback() {
void testCallWithBlockCallbackInSystem() {
void *l = malloc(12);
SystemHeaderFunctionWithBlockParam(l, ^(void *i) { free(i); }, sizeof(char *));
+}
+
+// Test escape into NSPointerArray. radar://11691035, PR13140
+void foo(NSPointerArray* pointerArray) {
+
+ void* p1 = malloc (1024);
+ if (p1) {
+ [pointerArray addPointer:p1];
+ }
+
+ void* p2 = malloc (1024);
+ if (p2) {
+ [pointerArray insertPointer:p2 atIndex:1];
+ }
+
+ void* p3 = malloc (1024);
+ if (p3) {
+ [pointerArray replacePointerAtIndex:1 withPointer:p3];
+ }
+
+ // Freeing the buffer is allowed.
+ void* buffer = [pointerArray pointerAtIndex:0];
+ free(buffer);
} \ No newline at end of file
diff --git a/test/Analysis/system-header-simulator-objc.h b/test/Analysis/system-header-simulator-objc.h
index 4626a4ec4f..20a26cdbaa 100644
--- a/test/Analysis/system-header-simulator-objc.h
+++ b/test/Analysis/system-header-simulator-objc.h
@@ -114,3 +114,11 @@ extern CFStringRef CFStringCreateWithCStringNoCopy(CFAllocatorRef alloc, const c
extern void CFStringAppend(CFMutableStringRef theString, CFStringRef appendedString);
void SystemHeaderFunctionWithBlockParam(void *, void (^block)(void *), unsigned);
+
+@interface NSPointerArray : NSObject <NSFastEnumeration, NSCopying, NSCoding>
+- (void)addPointer:(void *)pointer;
+- (void)insertPointer:(void *)item atIndex:(NSUInteger)index;
+- (void)replacePointerAtIndex:(NSUInteger)index withPointer:(void *)item;
+- (void *)pointerAtIndex:(NSUInteger)index;
+@end
+