#1920 Bad code for "switch" keyword is silently generated

closed-fixed
Maarten Brock
5
2013-05-25
2012-01-27
syd
No

Bad code for "switch" keyword is silently generated.

1. test.c attached
2. Command line : sdcc test.c
3. SDCC : mcs51/gbz80/z80/z180/r2k/ds390/pic16/pic14/TININative/ds400/hc08 3.1.0 #7066 (Nov 22 2011) (MINGW32)
4. Wrong asm code (instrucion is missed)

; test.c:5: switch( test )
mov r0,#_test
clr c
movx a,@r0
mov b,a
mov a,#0x11
subb a,b
jnc 00123$
ljmp 00119$
00123$:
mov r0,#_test
movx a,@r0
add a,#(00124$-3-.)
movc a,@a+pc
push acc
>
add a,#(00125$-3-.)
movc a,@a+pc
push acc
ret
00124$:
.db 00101$
.db 00102$
.db 00103$

__pdata unsigned char test = 1;
int main()
{
switch( test ) { case 0 : return 0; case 1 : return 1; case 2 : return 2; case 3 : return 3; case 4 : return 3; case 5 : return 3; case 6 : return 3; case 7 : return 3; case 8 : return 0; case 9 : return 1; case 10 : return 2; case 11 : return 3; case 12 : return 3; case 13 : return 3; case 14 : return 3; case 15 : return 3; case 16 : return 3; case 17 : return 3; } return 0; }

Discussion

  • syd
    syd
    2012-01-27

     
    Attachments
  • Maarten Brock
    Maarten Brock
    2012-01-28

    Fixed in SDCC 3.1.2 #7266.

     
  • Maarten Brock
    Maarten Brock
    2012-01-28

    • milestone: --> fixed
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-fixed