Patrick Beard | b2f6820 | 2012-04-06 18:12:22 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fblocks -analyze -analyzer-checker=osx.cocoa.UnusedIvars -verify -Wno-objc-root-class %s |
Ted Kremenek | cc87ba2 | 2008-07-23 18:21:36 +0000 | [diff] [blame] | 2 | |
Ted Kremenek | 35ffcf3 | 2009-08-07 21:13:23 +0000 | [diff] [blame] | 3 | //===--- BEGIN: Delta-debugging reduced headers. --------------------------===// |
| 4 | |
| 5 | @protocol NSObject |
| 6 | - (id)retain; |
| 7 | - (oneway void)release; |
| 8 | @end |
| 9 | @interface NSObject <NSObject> {} |
| 10 | - (id)init; |
| 11 | + (id)alloc; |
Ted Kremenek | cc87ba2 | 2008-07-23 18:21:36 +0000 | [diff] [blame] | 12 | @end |
| 13 | |
Ted Kremenek | 35ffcf3 | 2009-08-07 21:13:23 +0000 | [diff] [blame] | 14 | //===--- END: Delta-debugging reduced headers. ----------------------------===// |
Ted Kremenek | cc87ba2 | 2008-07-23 18:21:36 +0000 | [diff] [blame] | 15 | |
Ted Kremenek | 35ffcf3 | 2009-08-07 21:13:23 +0000 | [diff] [blame] | 16 | // This test case tests the basic functionality of the unused ivar test. |
| 17 | @interface TestA { |
| 18 | @private |
| 19 | int x; // expected-warning {{Instance variable 'x' in class 'TestA' is never used}} |
| 20 | } |
| 21 | @end |
| 22 | @implementation TestA @end |
| 23 | |
| 24 | // This test case tests whether the unused ivar check handles blocks that |
| 25 | // reference an instance variable. (<rdar://problem/7075531>) |
| 26 | @interface TestB : NSObject { |
| 27 | @private |
| 28 | id _ivar; // no-warning |
| 29 | } |
| 30 | @property (readwrite,retain) id ivar; |
| 31 | @end |
| 32 | |
| 33 | @implementation TestB |
| 34 | - (id)ivar { |
| 35 | __attribute__((__blocks__(byref))) id value = ((void*)0); |
| 36 | void (^b)() = ^{ value = _ivar; }; |
| 37 | b(); |
| 38 | return value; |
| 39 | } |
| 40 | |
| 41 | - (void)setIvar:(id)newValue { |
| 42 | void (^b)() = ^{ [_ivar release]; _ivar = [newValue retain]; }; |
| 43 | b(); |
| 44 | } |
| 45 | @end |
Ted Kremenek | e8ec699 | 2009-10-28 22:18:22 +0000 | [diff] [blame] | 46 | |
| 47 | //===----------------------------------------------------------------------===// |
| 48 | // <rdar://problem/6260004> Detect that ivar is in use, if used in category |
| 49 | // in the same file as the implementation |
| 50 | //===----------------------------------------------------------------------===// |
| 51 | |
| 52 | @protocol Protocol6260004 |
| 53 | - (id) getId; |
| 54 | @end |
| 55 | |
| 56 | @interface RDar6260004 { |
| 57 | @private |
| 58 | id x; // no-warning |
| 59 | } |
| 60 | @end |
| 61 | @implementation RDar6260004 @end |
| 62 | @implementation RDar6260004 (Protocol6260004) |
| 63 | - (id) getId { |
| 64 | return x; |
| 65 | } |
| 66 | @end |
| 67 | |
Ted Kremenek | b221e4f | 2009-11-20 04:31:57 +0000 | [diff] [blame] | 68 | //===----------------------------------------------------------------------===// |
| 69 | // <rdar://problem/7254495> - ivars referenced by lexically nested functions |
| 70 | // should not be flagged as unused |
| 71 | //===----------------------------------------------------------------------===// |
| 72 | |
| 73 | @interface RDar7254495 { |
| 74 | @private |
| 75 | int x; // no-warning |
| 76 | } |
| 77 | @end |
| 78 | |
| 79 | @implementation RDar7254495 |
| 80 | int radar_7254495(RDar7254495 *a) { |
| 81 | return a->x; |
| 82 | } |
| 83 | @end |
Ted Kremenek | e3972a9 | 2010-02-25 03:26:55 +0000 | [diff] [blame] | 84 | |
| 85 | //===----------------------------------------------------------------------===// |
| 86 | // <rdar://problem/7353683> - consult attribute((unused)) to silence warnings |
| 87 | // about unused instance variables |
| 88 | //===----------------------------------------------------------------------===// |
| 89 | |
| 90 | @interface RDar7353683 { |
| 91 | @private |
| 92 | id x __attribute__((unused)); |
| 93 | } |
| 94 | @end |
| 95 | |
| 96 | @implementation RDar7353683 |
| 97 | @end |
Ted Kremenek | ed50a8a | 2010-10-28 02:16:22 +0000 | [diff] [blame] | 98 | //===----------------------------------------------------------------------===// |
| 99 | // <rdar://problem/8481311> Unused bitfield ivars trigger cause weird |
NAKAMURA Takumi | ddddd48 | 2011-08-12 05:49:51 +0000 | [diff] [blame] | 100 | // diagnostic: "Instance variable '' in class..." |
Ted Kremenek | ed50a8a | 2010-10-28 02:16:22 +0000 | [diff] [blame] | 101 | //===----------------------------------------------------------------------===// |
Ted Kremenek | e3972a9 | 2010-02-25 03:26:55 +0000 | [diff] [blame] | 102 | |
Ted Kremenek | ed50a8a | 2010-10-28 02:16:22 +0000 | [diff] [blame] | 103 | @interface RDar8481311 { |
| 104 | @private |
| 105 | unsigned bitfield:1; // expected-warning {{Instance variable 'bitfield' in class 'RDar8481311' is never used}} |
| 106 | } |
| 107 | @end |
| 108 | |
| 109 | @implementation RDar8481311 |
| 110 | @end |
Anna Zaks | 5ec351c | 2012-05-15 22:31:56 +0000 | [diff] [blame] | 111 | |
| 112 | @class NSString; |
| 113 | @interface Radar11059352_1 { |
| 114 | @private |
| 115 | NSString *_pathString; |
| 116 | } |
| 117 | @property (readonly, strong) NSString *pathString; |
| 118 | @end |
| 119 | |
| 120 | @interface Radar11059352 { |
| 121 | @private |
| 122 | Radar11059352_1 *_workspacePath; |
| 123 | } |
| 124 | @end |
| 125 | |
| 126 | @implementation Radar11059352 |
| 127 | |
| 128 | - (void)useWorkspace { |
| 129 | NSString *workspacePathString = _workspacePath.pathString; |
| 130 | } |
| 131 | @end |