Ted Kremenek | 8382cf5 | 2009-11-13 18:46:29 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -analyze -analyzer-experimental-internal-checks -warn-objc-missing-dealloc '-DIBOutlet=__attribute__((iboutlet))' %s --verify |
Ted Kremenek | e0bb804 | 2008-12-08 21:59:21 +0000 | [diff] [blame] | 2 | typedef signed char BOOL; |
Ted Kremenek | dd06e09 | 2009-02-13 22:26:30 +0000 | [diff] [blame] | 3 | @protocol NSObject |
| 4 | - (BOOL)isEqual:(id)object; |
| 5 | - (Class)class; |
| 6 | @end |
| 7 | |
Ted Kremenek | e0bb804 | 2008-12-08 21:59:21 +0000 | [diff] [blame] | 8 | @interface NSObject <NSObject> {} |
| 9 | - (void)dealloc; |
Ted Kremenek | 63de736 | 2008-12-08 22:01:50 +0000 | [diff] [blame] | 10 | - (id)init; |
Ted Kremenek | e0bb804 | 2008-12-08 21:59:21 +0000 | [diff] [blame] | 11 | @end |
| 12 | |
Ted Kremenek | 63de736 | 2008-12-08 22:01:50 +0000 | [diff] [blame] | 13 | typedef struct objc_selector *SEL; |
| 14 | |
Ted Kremenek | e0bb804 | 2008-12-08 21:59:21 +0000 | [diff] [blame] | 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 |
Ted Kremenek | 63de736 | 2008-12-08 22:01:50 +0000 | [diff] [blame] | 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 // no-warning |
| 43 | - (id)init { |
| 44 | if( (self = [super init]) ) { |
| 45 | a = @selector(a); |
| 46 | b = @selector(b); |
| 47 | } |
| 48 | |
| 49 | return self; |
| 50 | } |
| 51 | @end |
Ted Kremenek | 26b58cd | 2008-12-08 22:05:43 +0000 | [diff] [blame] | 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 { |
| 63 | IBOutlet NSWindow *window; |
| 64 | } |
| 65 | @end |
| 66 | |
| 67 | @implementation HasOutlet // no-warning |
| 68 | @end |
| 69 | |
Ted Kremenek | 183c6f2 | 2009-02-10 23:41:52 +0000 | [diff] [blame] | 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 |
Ted Kremenek | dd06e09 | 2009-02-13 22:26:30 +0000 | [diff] [blame] | 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 |