#430 Register allocation bug (with source)

closed-fixed
nobody
7
2013-05-25
2002-12-31
Jan Matejka
No

If source code (below) is compiled with SDCC 2.3.2
then bad code is generated.
There is IMHO a problem with register allocation.
For variable n compiler uses register R3 but this register
is overwriten on line 36 in index calculation.
If --noinduction command line option is used, then
correct code is generated.
In SDCC 2.3.0 this error does not occur, but variables
are allocated to memory (less effective generated code).

Test source code:

typedef bit bool;
typedef signed char S8;
typedef unsigned char U8;
typedef signed int S16;
typedef unsigned int U16;
typedef signed long S32;
typedef unsigned long U32;

#define false 0
#define true 1

U8 klvGetString(char *buf,U8 maxchars)
{
buf[0]='1';
buf[1]='6';
return maxchars;
}

bool badFormat;

U8 klvGetU8()
{
char buf[2];
U8 n,ret=0,i=0;

badFormat=false;
n=klvGetString(buf,sizeof(buf));
while(i<n)
{
if(buf[i]<'0' || buf[i]>'9')
{badFormat=true;
break;
}
ret = ret*10;
ret = ret + (buf[i]-'0');
++i;
}
return ret;
}

U8 zz;
void main()
{
zz=klvGetU8();
}

Discussion

  • Bernhard Held

    Bernhard Held - 2003-01-01

    Logged In: YES
    user_id=203539

    I confirm this bug. Hint: you can workaroung this bug by defining:

    volatile U8 n;

     
  • Johan Knol

    Johan Knol - 2003-02-02
    • priority: 5 --> 7
     
  • Erik Petrich

    Erik Petrich - 2003-12-16

    Logged In: YES
    user_id=635249

    I have verified that the new live range code (specifically,
    Klaus's 2003/10/28 cvs commit) has fixed this bug.

     
  • Erik Petrich

    Erik Petrich - 2003-12-16
    • milestone: --> fixed
    • status: open --> closed-fixed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks