Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#444 Global structure members kept in temps over func calls

closed-fixed
Erik Petrich
5
2013-05-25
2003-01-28
Anonymous
No

From: Stef (stef@svdiest.demon.nl)

Target: MCS51, --model-large

[I created a small example of the problem]

In the following code, the value from TestStruct.Low
(global structure) is put in register r3 in line 47. After
this, DoLimits() is called, which may modify
TestStruct.Low.

In line 54 however, the value of r3 is used again (not
reloaded) although TestStruct.Low may have been
changed by the function. This results in incorrect
behaviour.

This problem does not happen with the global TestVal,
only with the structure members.

The problem is solved by declaring the structure
volatile, but this should not be needed. The problem
does not occur in small model.

See attached file for asm output.

Regards,

Stef
----------- test.c --------------
/* File: test.c */
/* Target: MCS51 */
/* Compiled with SDCC :
mcs51/gbz80/z80/avr/ds390/pic14/TININative/xa51
2.3.3 (Jan 27 2003) (UNIX) */
/* commandline: sdcc --model-large test.c */

typedef struct {
char Count;
char ValA;
char ValB;
char ResA;
char ResB;
char ResT;
char Low;
char High;
} T_TEST;

T_TEST TestStruct;

char TestVal = 0;

void InitTest(void);
void DoChecks(void);
void DoLimits(char i);

int main(void)
{
InitTest();

while(1) {
DoChecks();
}
}

void InitTest(void)
{
TestStruct.Count = 10;
TestStruct.ValA = 10;
TestStruct.ValB = 20;
TestStruct.Low = 0;
TestStruct.High = 0;
}

void DoChecks(void)
{
TestStruct.Count--;

if(TestStruct.ValA < TestStruct.Low)
{
TestStruct.ResA--;
DoLimits(0);
TestVal++;
}

if(TestStruct.ValB < TestStruct.Low)
{
TestStruct.ResB--;
DoLimits(0);
TestVal++;
}
}

void DoLimits(char i)
{
if(i)
{
TestStruct.High += 10;
}
else
{
TestStruct.Low -= 10;
}
TestVal++;
}

Discussion

  • Logged In: NO

    Sorry,

    Forgot to tell this also happens with the version from
    2002/09/24. Thats why I tried the upgrade. :-)

    Stef

     
  • Erik Petrich
    Erik Petrich
    2003-11-15

    Logged In: YES
    user_id=635249

    Same as bug #587536; fixed in src/SDCCdflow.c 1.12

     
  • Erik Petrich
    Erik Petrich
    2003-11-15

    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
    • status: open --> closed-fixed