Home arrow Support arrow Forums

Luminary Micro Forums

pbaston

Fresh Boarder
Click here to see the profile of this user

2007/01/06 09:10

Compiler Bug ?

Hi

Am I going mad or is there a bug in the Keil compiler ? I am trying to compile the code fragment:

Code:

 unsigned short int16; void testfunc(void) {    int16 >>= 1; }


But am finding the shift doesn't work !

the code produced looks like this:-
Code:

    176unsigned short int16;     177:      178void testfunc(void)     179: {  0x0000072E BD10      POP      {r4,pc}    180:         int16 >>= 10x00000730 480A      LDR      r0,[pc,#40]  ; @0x0000075C 0x00000732 8800      LDRH     r0,[r0,#0x00] 0x00000734 4909      LDR      r1,[pc,#36]  ; @0x0000075C 0x00000736 8008      STRH     r0,[r1,#0x00]    181: } 


I cannot see any right shift instruction in the above.
If, however, I do a left shift it seems OK:-
Code:

    176unsigned short int16;     177:      178void testfunc(void)     179: {  0x0000072E BD10      POP      {r4,pc}    180:         int16 <<= 10x00000730 480C      LDR      r0,[pc,#48]  ; @0x00000764 0x00000732 8800      LDRH     r0,[r0,#0x00] 0x00000734 F64F71FF  MOVW     r1,#0xFFFF 0x00000738 EA010040  AND      r0,r1,r0,LSL #1 0x0000073C 4909      LDR      r1,[pc,#36]  ; @0x00000764 0x0000073E 8008      STRH     r0,[r1,#0x00]    181: } 


... The LSL instruction clearly visible.

Am I doing something wrong ? I'm using uVision 3.33b

Thanks,

Pete Baston (UK).

login or register to reply

steriana

Junior Boarder
Click here to see the profile of this user

2007/01/07 22:10

Re:Compiler Bug ?

You're not going mad, I managed to reproduce your problem.

It seems to only occur with "no optimization", i.e., the -O0 flag. Any level of optimization (-O1, -O2, etc.) inserts a shift-right instruction as expected.

That's a pretty scary bug. Especially since one expects bugs to get worse with more optimization, not less.

Post edited by: steriana, at: 2007/01/07 22:11

login or register to reply

pbaston

Fresh Boarder
Click here to see the profile of this user

2007/01/08 02:00

Re:Compiler Bug ?

Hi

Thanks for that - glad I'm not doing something silly !

Yes, a bit worrying - I'm loathed to raise the optimisation level at this stage. Does anybody know how to report this to Keil ??

I also found that if I do something else on the same line as the shift then that works as well. My temp work around is ie:-

Code:

 int16 = (int16 >> 1) + 1; --int16;



Best Regards,
Pete.

login or register to reply