Let tree_single_nonzero_warnv_p use range information
[official-gcc.git] / gcc / testsuite / gcc.dg / 20000906-1.c
blob90d09d4dba5b4290b75aa8115990da87f8ecf611
1 /* { dg-do run } */
3 /* Testcase distilled from glibc's nss_parse_service_list in nss/nsswitch.c
4 It can't be distilled further. Fails with `-O2' for i[3456]86. */
6 /* this simulates a bounded-pointer type. */
7 struct ucharp { unsigned char *v, *l, *h; };
9 /* this simulates bounded-pointer check prior to pointer dereference. */
10 #define AREF(var, idx) ((((((((var).v+(idx)) < (var).l) \
11 || (((var).v+(idx)+1) > (var).h))) \
12 && (__builtin_trap (), 0)), \
13 (var).v)[(idx)])
15 struct list
17 struct list *next;
20 struct list *
21 alloc_list (void)
23 static struct list l;
24 return &l;
27 int one = 1;
29 void
30 foo (struct ucharp cp, struct ucharp lp, struct list **nextp)
32 while (1)
34 struct list *list;
35 while (AREF (lp, 0) && AREF (cp, AREF (lp, 0)))
36 ++lp.v;
37 list = alloc_list ();
38 while (AREF (cp, AREF (lp, 0)))
39 ++lp.v;
40 if (AREF (lp, 0) == one)
42 ++lp.v;
43 while (AREF (lp, 0) && AREF (cp, AREF (lp, 0)));
44 /* The above AREF (cp, ...) fails because the pseudo created to
45 hold cp.v holds garbage, having never been set.
46 The easiest way to see the problem is to compile wiht `-O2 -da'
47 then look at *.09.loop. Search for something like this:
49 Hoisted regno 183 r/o from (mem/s:SI (reg:SI 16 argp) 10)
50 Replaced reg 91, deleting init_insn (213).
52 Now, look for the use of reg 91, which has no set. */
54 *nextp = list;
55 nextp = &list->next;
56 if (!*lp.v)
57 break;
61 extern void exit (int);
63 int
64 main (void)
66 static unsigned char cp0[] = "\0\0\0\0";
67 struct ucharp cp = { cp0, cp0, cp0 + sizeof (cp0) };
69 static unsigned char lp0[] = "\1\1\0\0";
70 struct ucharp lp = { lp0, lp0, lp0 + sizeof (lp0) };
72 struct list list;
73 struct list *nextp = &list;
75 foo (cp, lp, &nextp);
77 exit (0);