mirror of
https://github.com/intel/llvm.git
synced 2026-01-27 06:06:34 +08:00
Fix <rdar://problem/6859457> [NSData dataWithBytesNoCopy] does not return a retained object.
llvm-svn: 71797
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
Reference in New Issue
Block a user