diff options
Diffstat (limited to 'test/Analysis/idempotent-operations.m')
-rw-r--r-- | test/Analysis/idempotent-operations.m | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/Analysis/idempotent-operations.m b/test/Analysis/idempotent-operations.m new file mode 100644 index 0000000..a77e2cb --- /dev/null +++ b/test/Analysis/idempotent-operations.m @@ -0,0 +1,42 @@ +// 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 + +typedef signed char BOOL; +typedef unsigned long NSUInteger; +typedef struct _NSZone NSZone; +@protocol NSObject - (BOOL)isEqual:(id)object; +@end + +@interface NSObject {} + @property int locked; + @property(nonatomic, readonly) NSObject *media; +@end + +// <rdar://problem/8725041> - Don't flag idempotent operation warnings when +// a method may invalidate an instance variable. +@interface Rdar8725041 : NSObject { + id _attribute; +} + - (void) method2; +@end + +@implementation Rdar8725041 +- (BOOL) method1 { + BOOL needsUpdate = (BOOL)0; + id oldAttribute = _attribute; + [self method2]; + needsUpdate |= (_attribute != oldAttribute); // no-warning + return needsUpdate; +} + +- (void) method2 +{ + _attribute = ((void*)0); +} +@end + +// Test that the idempotent operations checker works in the prescence +// of property expressions. +void pr9116(NSObject *placeholder) { + int x = placeholder.media.locked = placeholder ? 1 : 0; +} + |