
We have a new policy in place making links to private resources something we try to avoid in source and test files. Normally, we'd organically switch to the new policy rather than make a sweeping change across a project. However, Clang is in a somewhat special circumstance currently: recently, I've had several new contributors run into rdar links around test code which their patch was changing the behavior of. This turns out to be a surprisingly bad experience, especially for newer folks, for a handful of reasons: not understanding what the link is and feeling intimidated by it, wondering whether their changes are actually breaking something important to a downstream in some way, having to hunt down strangers not involved with the patch to impose on them for help, accidental pressure from asking for potentially private IP to be made public, etc. Because folks run into these links entirely by chance (through fixing bugs or working on new features), there's not really a set of problematic links to focus on -- all of the links have basically the same potential for causing these problems. As a result, this is an omnibus patch to remove all such links. This was not a mechanical change; it was done by manually searching for rdar, radar, radr, and other variants to find all the various problematic links. From there, I tried to retain or reword the surrounding comments so that we would lose as little context as possible. However, because most links were just a plain link with no supporting context, the majority of the changes are simple removals. Differential Review: https://reviews.llvm.org/D158071
127 lines
3.0 KiB
Objective-C
127 lines
3.0 KiB
Objective-C
// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount -analyzer-config ipa=dynamic-bifurcate -verify %s
|
|
|
|
typedef signed char BOOL;
|
|
typedef struct objc_class *Class;
|
|
typedef struct objc_object {
|
|
Class isa;
|
|
} *id;
|
|
@protocol NSObject - (BOOL)isEqual:(id)object; @end
|
|
@interface NSObject <NSObject> {}
|
|
+(id)alloc;
|
|
+(id)new;
|
|
- (oneway void)release;
|
|
-(id)init;
|
|
-(id)autorelease;
|
|
-(id)copy;
|
|
- (Class)class;
|
|
-(id)retain;
|
|
- (oneway void)release;
|
|
@end
|
|
|
|
@interface SelfStaysLive : NSObject
|
|
- (id)init;
|
|
@end
|
|
|
|
@implementation SelfStaysLive
|
|
- (id)init {
|
|
return [super init];
|
|
}
|
|
@end
|
|
|
|
void selfStaysLive(void) {
|
|
SelfStaysLive *foo = [[SelfStaysLive alloc] init];
|
|
[foo release];
|
|
}
|
|
|
|
// Test that retain release checker warns on leaks and use-after-frees when
|
|
// self init is not enabled.
|
|
@interface ParentOfCell : NSObject
|
|
- (id)initWithInt: (int)inInt;
|
|
@end
|
|
@interface Cell : ParentOfCell{
|
|
int x;
|
|
}
|
|
- (id)initWithInt: (int)inInt;
|
|
+ (void)testOverRelease;
|
|
+ (void)testLeak;
|
|
@property int x;
|
|
@end
|
|
@implementation Cell
|
|
@synthesize x;
|
|
- (id) initWithInt: (int)inInt {
|
|
[super initWithInt: inInt];
|
|
self.x = inInt; // no-warning
|
|
return self; // Self Init checker would produce a warning here.
|
|
}
|
|
+ (void) testOverRelease {
|
|
Cell *sharedCell3 = [[Cell alloc] initWithInt: 3];
|
|
[sharedCell3 release];
|
|
[sharedCell3 release]; // expected-warning {{Reference-counted object is used after it is released}}
|
|
}
|
|
+ (void) testLeak {
|
|
Cell *sharedCell4 = [[Cell alloc] initWithInt: 3]; // expected-warning {{leak}}
|
|
}
|
|
@end
|
|
|
|
// We should stop tracking some objects even when we inline the call.
|
|
// Specialically, the objects passed into calls with delegate and callback
|
|
// parameters.
|
|
@class DelegateTest;
|
|
typedef void (*ReleaseCallbackTy) (DelegateTest *c);
|
|
|
|
@interface Delegate : NSObject
|
|
@end
|
|
|
|
@interface DelegateTest : NSObject {
|
|
Delegate *myDel;
|
|
}
|
|
// Object initialized with a delagate which could potentially release it.
|
|
- (id)initWithDelegate: (id) d;
|
|
|
|
- (void) setDelegate: (id) d;
|
|
|
|
// Releases object through callback.
|
|
+ (void)updateObject:(DelegateTest*)obj WithCallback:(ReleaseCallbackTy)rc;
|
|
|
|
+ (void)test: (Delegate *)d;
|
|
|
|
@property (assign) Delegate* myDel;
|
|
@end
|
|
|
|
void releaseObj(DelegateTest *c);
|
|
|
|
// Releases object through callback.
|
|
void updateObject(DelegateTest *c, ReleaseCallbackTy rel) {
|
|
rel(c);
|
|
}
|
|
|
|
@implementation DelegateTest
|
|
@synthesize myDel;
|
|
|
|
- (id) initWithDelegate: (id) d {
|
|
if ((self = [super init]))
|
|
myDel = d;
|
|
return self;
|
|
}
|
|
|
|
- (void) setDelegate: (id) d {
|
|
myDel = d;
|
|
}
|
|
|
|
+ (void)updateObject:(DelegateTest*)obj WithCallback:(ReleaseCallbackTy)rc {
|
|
rc(obj);
|
|
}
|
|
|
|
+ (void) test: (Delegate *)d {
|
|
DelegateTest *obj1 = [[DelegateTest alloc] initWithDelegate: d]; // no-warning
|
|
DelegateTest *obj2 = [[DelegateTest alloc] init]; // no-warning
|
|
DelegateTest *obj3 = [[DelegateTest alloc] init]; // no-warning
|
|
updateObject(obj2, releaseObj);
|
|
[DelegateTest updateObject: obj3
|
|
WithCallback: releaseObj];
|
|
DelegateTest *obj4 = [[DelegateTest alloc] init]; // no-warning
|
|
[obj4 setDelegate: d];
|
|
}
|
|
@end
|
|
|