MissingDealloc.m revision 7909fc8833e734aac521d7d6945bd823d75150ac
1// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-missing-dealloc '-DIBOutlet=__attribute__((iboutlet))' %s -verify 2typedef signed char BOOL; 3@protocol NSObject 4- (BOOL)isEqual:(id)object; 5- (Class)class; 6@end 7 8@interface NSObject <NSObject> {} 9- (void)dealloc; 10- (id)init; 11@end 12 13typedef struct objc_selector *SEL; 14 15// <rdar://problem/6380411>: 'myproperty' has kind 'assign' and thus the 16// assignment through the setter does not perform a release. 17 18@interface MyObject : NSObject { 19 id _myproperty; 20} 21@property(assign) id myproperty; 22@end 23 24@implementation MyObject 25@synthesize myproperty=_myproperty; // no-warning 26- (void)dealloc { 27 self.myproperty = 0; 28 [super dealloc]; 29} 30@end 31 32//===------------------------------------------------------------------------=== 33// Don't warn about iVars that are selectors. 34 35@interface TestSELs : NSObject { 36 SEL a; 37 SEL b; 38} 39 40@end 41 42@implementation TestSELs 43- (id)init { 44 if( (self = [super init]) ) { 45 a = @selector(a); 46 b = @selector(b); 47 } 48 49 return self; 50} 51@end 52 53//===------------------------------------------------------------------------=== 54// Don't warn about iVars that are IBOutlets. 55 56#ifndef IBOutlet 57#define IBOutlet 58#endif 59 60@class NSWindow; 61 62@interface HasOutlet : NSObject { 63IBOutlet NSWindow *window; 64} 65@end 66 67@implementation HasOutlet // no-warning 68@end 69 70//===------------------------------------------------------------------------=== 71// <rdar://problem/6380411> 72// Was bogus warning: "The '_myproperty' instance variable was not retained by a 73// synthesized property but was released in 'dealloc'" 74 75@interface MyObject_rdar6380411 : NSObject { 76 id _myproperty; 77} 78@property(assign) id myproperty; 79@end 80 81@implementation MyObject_rdar6380411 82@synthesize myproperty=_myproperty; 83- (void)dealloc { 84 // Don't claim that myproperty is released since it the property 85 // has the 'assign' attribute. 86 self.myproperty = 0; // no-warning 87 [super dealloc]; 88} 89@end 90 91//===------------------------------------------------------------------------=== 92// PR 3187: http://llvm.org/bugs/show_bug.cgi?id=3187 93// - Disable the missing -dealloc check for classes that subclass SenTestCase 94 95@class NSString; 96 97@interface SenTestCase : NSObject {} 98@end 99 100@interface MyClassTest : SenTestCase { 101 NSString *resourcePath; 102} 103@end 104 105@interface NSBundle : NSObject {} 106+ (NSBundle *)bundleForClass:(Class)aClass; 107- (NSString *)resourcePath; 108@end 109 110@implementation MyClassTest 111- (void)setUp { 112 resourcePath = [[NSBundle bundleForClass:[self class]] resourcePath]; 113} 114- (void)testXXX { 115 // do something which uses resourcepath 116} 117@end 118