77018e072f26d5497fc49fe07c8b477abdcb6806
[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 disable_warning 84
28 #endif
29
30 static void
31 testLR(void)
32 {
33 /*
34  * excluded for pic16 due to bug:
35  * [ 1511794 ] pic16: regression test bug-895992.c fails
36  */
37 #ifndef SDCC_pic16
38   unsigned char number;
39   unsigned char start = 1;
40   unsigned char i;
41
42   do
43     {
44       for (i = 1; i > 0 ; i--)
45         wait();         /* destroys all registers */
46       if (start)
47         {
48           number = p0;
49           start = 0;
50         }
51       number--;         /* 'number' might be used before initialization     */
52                         /* the life range of 'number' must be extended to   */
53                         /* the whole loop _including_ the conditional block */
54       ++loops;
55     }
56   while (number != 0);
57
58   ASSERT(loops == p0);
59 #endif
60 }