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