1 /* { dg-do compile } */
2 /* PR c/16531 */
3 /* { dg-options "-O2 -fdelete-null-pointer-checks -Wnull-dereference" } */
4 /* { dg-skip-if "" keeps_null_pointer_checks } */
5 
6 #ifndef __cplusplus
7 #define NULL (void *)0
8 #else
9 #define NULL nullptr
10 #endif
11 
12 struct t
13 {
14   int bar;
15 };
16 
17 struct t2
18 {
19   struct t *s;
20 };
21 
test1()22 void test1 ()
23 {
24   struct t *s = NULL;
25   s->bar = 1;  /* { dg-warning "null" } */
26 }
27 
test2(struct t * s)28 void test2 (struct t *s)
29 {
30   if (s == NULL && s->bar > 2)  /* { dg-warning "null" } */
31     return;
32 
33   s->bar = 3;
34 }
35 
test3(struct t * s)36 void test3 (struct t *s)
37 {
38   if (s != NULL || s->bar > 2)  /* { dg-warning "null" } */
39     return;
40 
41   s->bar = 3;  /* { dg-warning "null" } */
42 }
43 
test4(struct t * s)44 int test4 (struct t *s)
45 {
46   if (s != NULL && s->bar > 2)  /* { dg-bogus "null" } */
47     return 1;
48   return 0;
49 }
50 
test5(struct t * s)51 int test5 (struct t *s)
52 {
53   if (s == NULL || s->bar > 2)  /* { dg-bogus "null" } */
54     return 1;
55   return 0;
56 }
57 
test6(struct t2 * s)58 int test6 (struct t2 *s)
59 {
60   if (s->s == 0 && s->s->bar == 0)  /* { dg-warning "null" } */
61     return 1;
62   return 0;
63 }
64 
test7(struct t * s)65 int test7 (struct t *s)
66 {
67   s = 0;
68   return s->bar;  /* { dg-warning "null" } */
69 }
70 
test8()71 int test8 ()
72 {
73   return ((struct t *)0)->bar;  /* { dg-warning "null" } */
74 }
75 
test9(struct t ** s)76 void test9 (struct t **s)
77 {
78   if (s == 0)
79     *s = 0;  /* { dg-warning "null" } */
80 }
81 
82 
83