1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
2 
test1()3 int test1() {
4   int *p = (int *)sizeof(int);
5   p -= 1;
6   return *p; // expected-warning {{Dereference of null pointer}}
7 }
8 
test2()9 int test2() {
10   int *p = (int *)sizeof(int);
11   p -= 2;
12   p += 1;
13   return *p; // expected-warning {{Dereference of null pointer}}
14 }
15 
test3()16 int test3() {
17   int *p = (int *)sizeof(int);
18   p++;
19   p--;
20   p--;
21   return *p; // expected-warning {{Dereference of null pointer}}
22 }
23 
test4()24 int test4() {
25   // This is a special case where pointer arithmetic is not calculated to
26   // preserve useful warnings on dereferences of null pointers.
27   int *p = 0;
28   p += 1;
29   return *p; // expected-warning {{Dereference of null pointer}}
30 }
31