Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-checker=core,core.experimental -analyzer-constraints=range -analyzer-store=region -verify %s
      2 
      3 // <rdar://problem/6888289> - This test case shows that a nil instance
      4 // variable can possibly be initialized by a method.
      5 typedef struct RDar6888289_data {
      6   long data[100];
      7 } RDar6888289_data;
      8 
      9 @interface RDar6888289
     10 {
     11   RDar6888289 *x;
     12 }
     13 - (RDar6888289_data) test;
     14 - (RDar6888289_data) test2;
     15 - (void) invalidate;
     16 - (RDar6888289_data) getData;
     17 @end
     18 
     19 @implementation RDar6888289
     20 - (RDar6888289_data) test {
     21   if (!x)
     22     [self invalidate];
     23   return [x getData];
     24 }
     25 - (RDar6888289_data) test2 {
     26   if (!x) {}
     27   return [x getData]; // expected-warning{{The receiver of message 'getData' is nil and returns a value of type 'RDar6888289_data' that will be garbage}}
     28 }
     29 
     30 - (void) invalidate {
     31   x = self;
     32 }
     33 
     34 - (RDar6888289_data) getData {
     35   return (RDar6888289_data) { 0 };
     36 }
     37 @end
     38 
     39