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