Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,debug.ExprInspection -analyzer-store=region -verify -Wno-objc-root-class %s
      2 // RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,debug.ExprInspection -analyzer-store=region -verify -Wno-objc-root-class -fobjc-arc %s
      3 
      4 void clang_analyzer_eval(bool);
      5 void clang_analyzer_checkInlined(bool);
      6 
      7 @interface IntWrapper
      8 @property (readonly) int &value;
      9 @end
     10 
     11 @implementation IntWrapper
     12 @synthesize value;
     13 @end
     14 
     15 void testReferenceConsistency(IntWrapper *w) {
     16   clang_analyzer_eval(w.value == w.value); // expected-warning{{TRUE}}
     17   clang_analyzer_eval(&w.value == &w.value); // expected-warning{{TRUE}}
     18 
     19   if (w.value != 42)
     20     return;
     21 
     22   clang_analyzer_eval(w.value == 42); // expected-warning{{TRUE}}
     23 }
     24 
     25 void testReferenceAssignment(IntWrapper *w) {
     26   w.value = 42;
     27   clang_analyzer_eval(w.value == 42); // expected-warning{{TRUE}}
     28 }
     29 
     30 
     31 struct IntWrapperStruct {
     32   int value;
     33 };
     34 
     35 @interface StructWrapper
     36 @property IntWrapperStruct inner;
     37 @end
     38 
     39 @implementation StructWrapper
     40 @synthesize inner;
     41 @end
     42 
     43 void testConsistencyStruct(StructWrapper *w) {
     44   clang_analyzer_eval(w.inner.value == w.inner.value); // expected-warning{{TRUE}}
     45 
     46   int origValue = w.inner.value;
     47   if (origValue != 42)
     48     return;
     49 
     50   clang_analyzer_eval(w.inner.value == 42); // expected-warning{{TRUE}}
     51 }
     52 
     53 
     54 class CustomCopy {
     55 public:
     56   CustomCopy() : value(0) {}
     57   CustomCopy(const CustomCopy &other) : value(other.value) {
     58     clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
     59   }
     60   int value;
     61 };
     62 
     63 @interface CustomCopyWrapper
     64 @property CustomCopy inner;
     65 @end
     66 
     67 @implementation CustomCopyWrapper
     68 //@synthesize inner;
     69 @end
     70 
     71 void testConsistencyCustomCopy(CustomCopyWrapper *w) {
     72   clang_analyzer_eval(w.inner.value == w.inner.value); // expected-warning{{TRUE}}
     73 
     74   int origValue = w.inner.value;
     75   if (origValue != 42)
     76     return;
     77 
     78   clang_analyzer_eval(w.inner.value == 42); // expected-warning{{TRUE}}
     79 }
     80