203250bd7a5add29d558ca4dc72fc8959ffa27c6
[fw/sdcc] / support / regression / tests / bug-895992.c
1 /* bug-895992.c
2
3    Life Range problem with
4    - uninitialized variable
5    - loop
6    - conditional block
7
8    LR problem hits all ports, but this test is mcs51 specific
9  */
10 #include <testfwk.h>
11
12 char p0 = 2;
13 unsigned short loops;
14
15 static void
16 wait (void)
17 {
18   long i, j;
19
20   /* just clobber all registers: */
21   for (i = 0; i < 2; ++i)
22     for (j = 0; j < 2; ++j)
23       ;
24 }
25
26 #if !defined(PORT_HOST)
27 #  pragma save
28 #  pragma disable_warning 84
29 #endif
30
31 static void
32 testLR(void)
33 {
34   unsigned char number;
35   unsigned char start = 1;
36   unsigned char i;
37
38   do
39     {
40       for (i = 1; i > 0 ; i--)
41         wait();         /* destroys all registers */
42       if (start)
43         {
44           number = p0;
45           start = 0;
46         }
47       number--;         /* 'number' might be used before initialization     */
48                         /* the life range of 'number' must be extended to   */
49                         /* the whole loop _including_ the conditional block */
50       ++loops;
51     }
52   while (number != 0);
53
54   ASSERT(loops == p0);
55 }
56
57 #if !defined(PORT_HOST)
58 #  pragma restore
59 #endif