#767 This produces a bug

closed-fixed
Erik Petrich
5
2013-05-25
2004-06-05
Anonymous
No

Hi,
------------------------------------------------------
-----
Please see this code(Version 2.4.1 (Jun 1 2004) :

//========================
data unsigned char times[2][3];
code unsigned char value[4]={1,2,3,4};
//--------------------------------
void func2()
{
times[1][0]+= value[3];
if(times[1][0]>23) times[1][0] -= 24;
}
//========================

This is compiled as( I have removed the genxxx &
peephole comments):-

;E:/sdcode/Trials/trial.c:7: times[1][0]+= value[3];
mov dptr,#(_value + 0x0003)
clr a
movc a,@a+dptr
mov r2,a
mov r3,(_times + 0x0003) ;<----r3 is used to store
value of times[1][0].
mov a,r2
add a,r3
mov (_times + 0x0003),a ;<-----times[1][0] is
updated, but r3 still contains it's old value.

;E:/sdcode/Trials/trial.c:8: if(times[1][0]>23) times[1]
[0] -= 24;
clr c
mov a,#0x17
subb a,r3 ;<-----r3 is used without being
updated with the new value of times[1][0] :(
jnc 00103$
;...etc
//-----------------------
The workaround is to use a pointer in place of times[][].
But eventually this needs to be corrected.

Thanks,
--Royce.

Discussion

  • Erik Petrich
    Erik Petrich
    2004-06-15

    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
    • status: open --> closed-fixed
     
  • Erik Petrich
    Erik Petrich
    2004-06-15

    Logged In: YES
    user_id=635249

    Fixed in src/SDCCcse.c 1.94.

    This reverts the key changes made in 1.77 (to fix bug
    #734169), but all is still well since the changes in 1.89
    (to fix bug #773153) fix bug #734169 too.