Argyrios Kyrtzidis | c9f2e0f | 2011-02-15 22:55:14 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -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 | |