Fix warning with -Wsign-compare -Wsystem-headers
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / wnull-dereference.c
blobdb36acc15b7787cf31b446eb294d1800455a886b
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 } */
6 #ifndef __cplusplus
7 #define NULL (void *)0
8 #else
9 #define NULL nullptr
10 #endif
12 struct t
14 int bar;
17 struct t2
19 struct t *s;
22 void test1 ()
24 struct t *s = NULL;
25 s->bar = 1; /* { dg-warning "null" } */
28 void test2 (struct t *s)
30 if (s == NULL && s->bar > 2) /* { dg-warning "null" } */
31 return;
33 s->bar = 3;
36 void test3 (struct t *s)
38 if (s != NULL || s->bar > 2) /* { dg-warning "null" } */
39 return;
41 s->bar = 3; /* { dg-warning "null" } */
44 int test4 (struct t *s)
46 if (s != NULL && s->bar > 2) /* { dg-bogus "null" } */
47 return 1;
48 return 0;
51 int test5 (struct t *s)
53 if (s == NULL || s->bar > 2) /* { dg-bogus "null" } */
54 return 1;
55 return 0;
58 int test6 (struct t2 *s)
60 if (s->s == 0 && s->s->bar == 0) /* { dg-warning "null" } */
61 return 1;
62 return 0;
65 int test7 (struct t *s)
67 s = 0;
68 return s->bar; /* { dg-warning "null" } */
71 int test8 ()
73 return ((struct t *)0)->bar; /* { dg-warning "null" } */
76 void test9 (struct t **s)
78 if (s == 0)
79 *s = 0; /* { dg-warning "null" } */