Fix <rdar://problem/6859457> [NSData dataWithBytesNoCopy] does not return a retained object.

llvm-svn: 71797
This commit is contained in:
Ted Kremenek
2009-05-14 21:29:16 +00:00
parent 5c46602d30
commit f9fa3cb78a
2 changed files with 35 additions and 0 deletions

View File

@@ -1338,6 +1338,15 @@ void RetainSummaryManager::InitializeClassMethodSummaries() {
"withObject", "waitUntilDone", "modes", NULL);
addClsMethSummary(NSObjectII, Summ, "performSelectorInBackground",
"withObject", NULL);
// Specially handle NSData.
RetainSummary *dataWithBytesNoCopySumm =
getPersistentSummary(RetEffect::MakeNotOwned(RetEffect::ObjC), DoNothing,
DoNothing);
addClsMethSummary("NSData", dataWithBytesNoCopySumm,
"dataWithBytesNoCopy", "length", NULL);
addClsMethSummary("NSData", dataWithBytesNoCopySumm,
"dataWithBytesNoCopy", "length", "freeWhenDone", NULL);
}
void RetainSummaryManager::InitializeMethodSummaries() {

View File

@@ -140,6 +140,11 @@ extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn stat
- (void)drain;
@end
@interface NSData : NSObject {}
+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length;
+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b;
@end
//===----------------------------------------------------------------------===//
// Test cases.
//===----------------------------------------------------------------------===//
@@ -592,6 +597,27 @@ int RDar6320065_test() {
return 0;
}
//===----------------------------------------------------------------------===//
// <rdar://problem/6859457> [NSData dataWithBytesNoCopy] does not return a retained object
//===----------------------------------------------------------------------===//
@interface RDar6859457 : NSObject {}
- (NSString*) NoCopyString;
- (NSString*) noCopyString;
@end
@implementation RDar6859457
- (NSString*) NoCopyString { return [[NSString alloc] init]; } // no-warning
- (NSString*) noCopyString { return [[NSString alloc] init]; } // no-warning
@end
void test_RDar6859457(RDar6859457 *x, void *bytes, NSUInteger dataLength) {
[x NoCopyString]; // expected-warning{{leak}}
[x noCopyString]; // expected-warning{{leak}}
[NSData dataWithBytesNoCopy:bytes length:dataLength]; // no-warning
[NSData dataWithBytesNoCopy:bytes length:dataLength freeWhenDone:1]; // no-warning
}
//===----------------------------------------------------------------------===//
// Tests of ownership attributes.
//===----------------------------------------------------------------------===//