Home | History | Annotate | Download | only in Analysis
      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
      2 // expected-no-diagnostics
      3 
      4 typedef signed char BOOL;
      5 typedef unsigned long NSUInteger;
      6 typedef struct _NSZone NSZone;
      7 @protocol NSObject  - (BOOL)isEqual:(id)object;
      8 @end
      9 
     10 @interface NSObject {}
     11   @property int locked;
     12   @property(nonatomic, readonly) NSObject *media;
     13 @end
     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 
     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 
     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 
     56