Menu

#2020 Variable allocated to registers is damaged.

closed-fixed
7
2013-05-25
2012-05-16
syd
No

1. Code:
#include <stdio.h>

unsigned long GetX()
{
return 0x12345678;
}

char GetY()
{
return 1;
}

int main() __reentrant
{
unsigned long x;
char buff[20];

x = GetX();
if( GetY() != 0 )
{
sprintf( buff, "%.8lx", x );
}

return 0;
}

Variable "x" (allocated to registers r4-r7) is damaged.

; test0003.c:21: sprintf( buff, "%.8lx", x );
push ar4
push ar5
push ar6
push ar7
mov r3,_bp
inc r3
mov ar2,r3
mov r3,#0x00
mov r7,#0x40 // here the "x" is damaged
push ar4
push ar5
push ar6
push ar7 // here the "x" is pushed to stack as sprintf argument
mov a,#__str_0
push acc
mov a,#(__str_0 >> 8)
push acc
mov a,#0x80
push acc
push ar2
push ar3
push ar7
lcall _sprintf
mov a,sp
add a,#0xf6
mov sp,a

2. Cmd line "sdcc test0003.c"
3. SDCC : mcs51/gbz80/z80/z180/r2k/ds390/pic16/pic14/TININative/ds400/hc08 3.1.5 #7708 (May 16 2012) (MINGW32)

Discussion

  • syd

    syd - 2012-05-16

    sample code

     
  • Philipp Klaus Krause

    Increasing priority, since bad code is generated silently.

    Philipp

     
  • Philipp Klaus Krause

    • priority: 5 --> 7
     
  • Erik Petrich

    Erik Petrich - 2012-06-05

    Fixed in revision #7862

     
  • Erik Petrich

    Erik Petrich - 2012-06-05
    • labels: --> mcs51(8051) target
    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
    • status: open --> closed-fixed
     

Log in to post a comment.