Ted Kremenek | cdc3a89 | 2012-08-24 20:39:55 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-checker=alpha.deadcode.IdempotentOperations,osx.cocoa.RetainCount -verify %s |
Andy Gibbs | 8e8fb3b | 2012-10-19 12:44:48 +0000 | [diff] [blame] | 2 | // expected-no-diagnostics |
Ted Kremenek | 148849a | 2011-02-12 01:01:31 +0000 | [diff] [blame] | 3 | |
| 4 | typedef signed char BOOL; |
| 5 | typedef unsigned long NSUInteger; |
| 6 | typedef struct _NSZone NSZone; |
| 7 | @protocol NSObject - (BOOL)isEqual:(id)object; |
Ted Kremenek | 148849a | 2011-02-12 01:01:31 +0000 | [diff] [blame] | 8 | @end |
| 9 | |
Ted Kremenek | 020c374 | 2011-02-12 18:50:03 +0000 | [diff] [blame] | 10 | @interface NSObject {} |
| 11 | @property int locked; |
| 12 | @property(nonatomic, readonly) NSObject *media; |
| 13 | @end |
Ted Kremenek | 148849a | 2011-02-12 01:01:31 +0000 | [diff] [blame] | 14 | |
| 15 | // <rdar://problem/8725041> - Don't flag idempotent operation warnings when |
| 16 | // a method may invalidate an instance variable. |
| 17 | @interface Rdar8725041 : NSObject { |
| 18 | id _attribute; |
| 19 | } |
| 20 | - (void) method2; |
| 21 | @end |
| 22 | |
| 23 | @implementation Rdar8725041 |
| 24 | - (BOOL) method1 { |
| 25 | BOOL needsUpdate = (BOOL)0; |
| 26 | id oldAttribute = _attribute; |
| 27 | [self method2]; |
| 28 | needsUpdate |= (_attribute != oldAttribute); // no-warning |
| 29 | return needsUpdate; |
| 30 | } |
| 31 | |
| 32 | - (void) method2 |
| 33 | { |
| 34 | _attribute = ((void*)0); |
| 35 | } |
| 36 | @end |
| 37 | |
Ted Kremenek | 020c374 | 2011-02-12 18:50:03 +0000 | [diff] [blame] | 38 | // Test that the idempotent operations checker works in the prescence |
| 39 | // of property expressions. |
| 40 | void pr9116(NSObject *placeholder) { |
| 41 | int x = placeholder.media.locked = placeholder ? 1 : 0; |
| 42 | } |
| 43 | |
Ted Kremenek | cf995d3 | 2011-03-15 19:27:57 +0000 | [diff] [blame] | 44 | // <rdar://problem/9130239>: Test that calling property setters doesn't |
| 45 | // trigger an assertion failure when the object is nil. |
| 46 | @interface RDar9130239 |
| 47 | @property (assign) id delegate; |
| 48 | @end |
| 49 | |
| 50 | void test_RDar9130239(RDar9130239 *x) { |
| 51 | if (x) |
| 52 | return; |
| 53 | x.delegate = x; // no-warning |
| 54 | } |
| 55 | |