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)
sample code
Increasing priority, since bad code is generated silently.
Philipp
Fixed in revision #7862