1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -fblocks -verify -Wno-objc-root-class %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist-multi-file -fblocks -Wno-objc-root-class %s -o %t
3 // RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/null-deref-path-notes.m.plist -
9 - (id)initWithID:(int)newID;
13 int testNull(Root *obj) {
15 // expected-note@-1 {{Assuming 'obj' is nil}}
16 // expected-note@-2 {{Taking false branch}}
18 int *x = &obj->uniqueID; // expected-note{{'x' initialized to a null pointer value}}
19 return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} expected-note{{Dereference of null pointer (loaded from variable 'x')}}
23 @interface Subclass : Root
26 @implementation Subclass
27 - (id)initWithID:(int)newID {
28 self = [super initWithID:newID]; // expected-note{{Value assigned to 'self'}}
29 if (self) return self;
30 // expected-note@-1 {{Assuming 'self' is nil}}
31 // expected-note@-2 {{Taking false branch}}
33 uniqueID = newID; // expected-warning{{Access to instance variable 'uniqueID' results in a dereference of a null pointer (loaded from variable 'self')}} expected-note{{Access to instance variable 'uniqueID' results in a dereference of a null pointer (loaded from variable 'self')}}
39 void repeatedStores(int coin) {
42 // expected-note@-1 {{Assuming 'coin' is 0}}
43 // expected-note@-2 {{Taking false branch}}
44 extern int *getPointer(void);
47 p = 0; // expected-note {{Null pointer value stored to 'p'}}
50 *p = 1; // expected-warning{{Dereference of null pointer}} expected-note{{Dereference of null pointer}}
53 @interface WithArrayPtr
57 @implementation WithArrayPtr {
61 p[1] = 2; // expected-warning{{Array access (via ivar 'p') results in a null pointer dereference}}
62 // expected-note@-1{{Array access (via ivar 'p') results in a null pointer dereference}}
66 void testWithArrayPtr(WithArrayPtr *w) {
67 w->p = 0; // expected-note{{Null pointer value stored to 'p'}}
68 [w useArray]; // expected-note{{Calling 'useArray'}}