1 // RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-checker=experimental.deadcode.IdempotentOperations,osx.cocoa.RetainCount -verify %s 2 3 typedef signed char BOOL; 4 typedef unsigned long NSUInteger; 5 typedef struct _NSZone NSZone; 6 @protocol NSObject - (BOOL)isEqual:(id)object; 7 @end 8 9 @interface NSObject {} 10 @property int locked; 11 @property(nonatomic, readonly) NSObject *media; 12 @end 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 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 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 55