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 wait(void)16wait (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 testLR(void)31testLR (void) 32 { 33 unsigned char number; 34 unsigned char start = 1; 35 unsigned char i; 36 37 do 38 { 39 for (i = 1; i > 0 ; i--) 40 wait (); /* destroys all registers */ 41 if (start) 42 { 43 number = p0; 44 start = 0; 45 } 46 number--; /* 'number' might be used before initialization */ 47 /* the life range of 'number' must be extended to */ 48 /* the whole loop _including_ the conditional block */ 49 ++loops; 50 } 51 while (number != 0); 52 53 ASSERT (loops == p0); 54 } 55