summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/malloc.mm
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-03-30 05:48:16 +0000
committerAnna Zaks <ganna@apple.com>2012-03-30 05:48:16 +0000
commit90ab9bfa111fcf567a089ec35f232708466df647 (patch)
treec64b8a97c2673daffe987b2bba10b76b07af40f9 /clang/test/Analysis/malloc.mm
parent54fd4a076695a480ca55f2c35444fc82842a5bc7 (diff)
downloadbcm5719-llvm-90ab9bfa111fcf567a089ec35f232708466df647.tar.gz
bcm5719-llvm-90ab9bfa111fcf567a089ec35f232708466df647.zip
[analyzer]Malloc,RetainRelease: Allow pointer to escape via NSMapInsert.
Fixes a false positive (radar://11152419). The current solution of adding the info into 3 places is quite ugly. Pending a generic pointer escapes callback. llvm-svn: 153731
Diffstat (limited to 'clang/test/Analysis/malloc.mm')
-rw-r--r--clang/test/Analysis/malloc.mm19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/test/Analysis/malloc.mm b/clang/test/Analysis/malloc.mm
index fe14edeedd1..d2409ac1609 100644
--- a/clang/test/Analysis/malloc.mm
+++ b/clang/test/Analysis/malloc.mm
@@ -106,6 +106,25 @@ void testBlocks() {
myBlock(3);
}
+// Test NSMapInsert.
+@interface NSMapTable : NSObject <NSCopying, NSCoding, NSFastEnumeration>
+@end
+extern void *NSMapGet(NSMapTable *table, const void *key);
+extern void NSMapInsert(NSMapTable *table, const void *key, const void *value);
+extern void NSMapInsertKnownAbsent(NSMapTable *table, const void *key, const void *value);
+char *strdup(const char *s);
+
+NSString * radar11152419(NSString *string1, NSMapTable *map) {
+ const char *strkey = "key";
+ NSString *string = ( NSString *)NSMapGet(map, strkey);
+ if (!string) {
+ string = [string1 copy];
+ NSMapInsert(map, strdup(strkey), (void*)string); // no warning
+ NSMapInsertKnownAbsent(map, strdup(strkey), (void*)string); // no warning
+ }
+ return string;
+}
+
// Test that we handle pointer escaping through OSAtomicEnqueue.
typedef volatile struct {
void *opaque1;
OpenPOWER on IntegriCloud