blob: c1cc076a936232599731fbbc6803fefdb621307a [file] [log] [blame]
Patrick Beardb2f68202012-04-06 18:12:22 +00001// RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-checker=core,experimental.core -analyzer-constraints=range -analyzer-store=region -verify -Wno-objc-root-class %s
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +00002
3// <rdar://problem/6888289> - This test case shows that a nil instance
4// variable can possibly be initialized by a method.
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +00005@interface RDar6888289
6{
Ted Kremenek4a037c72011-10-28 19:05:10 +00007 id *x;
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +00008}
Ted Kremenek4a037c72011-10-28 19:05:10 +00009- (void) test:(id) y;
10- (void) test2:(id) y;
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +000011- (void) invalidate;
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +000012@end
13
Ted Kremenek4a037c72011-10-28 19:05:10 +000014id *getVal(void);
15
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +000016@implementation RDar6888289
Ted Kremenek4a037c72011-10-28 19:05:10 +000017- (void) test:(id)y {
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +000018 if (!x)
19 [self invalidate];
Ted Kremenek4a037c72011-10-28 19:05:10 +000020 *x = y;
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +000021}
Ted Kremenek4a037c72011-10-28 19:05:10 +000022- (void) test2:(id)y {
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +000023 if (!x) {}
Ted Kremenek4a037c72011-10-28 19:05:10 +000024 *x = y; // expected-warning {{null}}
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +000025}
26
27- (void) invalidate {
Ted Kremenek4a037c72011-10-28 19:05:10 +000028 x = getVal();
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +000029}
30
Ted Kremenekf9eb0ae2011-02-12 01:25:04 +000031@end
32