From: SourceForge.net <no...@so...> - 2003-09-27 16:15:33
|
Bugs item #813572, was opened at 2003-09-27 09:51 Message generated for change (Comment added) made by epetrich You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=813572&group_id=599 Category: msc51(8051) target >Group: non bugs >Status: Closed >Resolution: Rejected Priority: 5 Submitted By: Stas Sergeev (stsp) >Assigned to: Erik Petrich (epetrich) Summary: unmatched switch causes jump to a random location Initial Comment: Hi. There seem to be a bug in sdcc which causes a jump to a random location when the "switch" without a "default" case is unmatched. Attached is a test program. Also here it is: --- #include <at89S8252.h> /* special function register declarations */ int main() { char a, b; b = SBUF; switch (b) { case 1: a = 'a'; break; case 2: a = 'b'; break; } return a; } --- The code it generates, looks as follows: --- ;switch.c:7: switch (b) { ; genMinus ; genMinusDec dec r2 ; genJumpTab mov a,r2 add a,acc add a,r2 mov dptr,#00106$ jmp @a+dptr 00106$: ljmp 00101$ ljmp 00102$ C$switch.c$8$2$2 ==. ;switch.c:8: case 1: a = 'a'; --- Now, as "b" contains some garbage and there is no a "default" case, the "switch" must be bypassed. But instead it is being performed, and the ljmp misses a jump table with an unpredictable results. ---------------------------------------------------------------------- >Comment By: Erik Petrich (epetrich) Date: 2003-09-27 11:15 Message: Logged In: YES user_id=635249 Unless I am overlooking your point, the compiler appears to work as designed. If you specify --nojtbound, the compiler omits the code that verifies that the switched value is within the range of cases handled in the switch statement. Essentially, by using --nojtbound you are making a promise to the compiler that you have already (by some other means) ensured that your value is within the range of cases given; in exchange, the compiler generates faster and shorter code. Your sample test case breaks this promise and so will fail when b<1 or b>2. Perhaps the option's name has tricked you? Whereas most of the --no_x_ options turn OFF an optimization, the --nojtbound option turns one ON. ---------------------------------------------------------------------- Comment By: Stas Sergeev (stsp) Date: 2003-09-27 10:11 Message: Logged In: YES user_id=501371 Compile the test-case on a latest sdcc from CVS with the following command line: sdcc -mmcs51 --nojtbound --noinduction --noloopreverse --xram-size 0 --code-size 8192 --debug --no-peep switch.c ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=813572&group_id=599 |