#1233 Wrong compilation???

closed-fixed
nobody
z80 port (188)
5
2008-02-20
2006-11-14
Anonymous
No

There is some unknown problems with compilation:
correct source is wrong translated and compiled code
crashes.

SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.6.0 #4309 (Jul 28 2006) (MINGW32)

Target: Z80

Original source which is correctly compiled by all
other C compilers (GCC, CC65,...) and doesn't work on
SDCC (target structure is filled with nonsense values,
which crash compiled program):

static void
s_Games_SI_BlockInit(S_GAMES_SI_BLOCK_STRUCT *bl, UINT8
i, UINT8 x, UINT8 y)
{
bl[i ].x = x - 1; bl[i ].y = y - 1;
bl[i + 1].x = x ; bl[i + 1].y = y - 1;
bl[i + 2].x = x + 1; bl[i + 2].y = y - 1;
bl[i + 3].x = x - 1; bl[i + 3].y = y ;
bl[i + 4].x = x ; bl[i + 4].y = y ;
bl[i + 5].x = x + 1; bl[i + 5].y = y ;
bl[i + 6].x = x - 1; bl[i + 6].y = y + 1;
bl[i + 7].x = x ; bl[i + 7].y = y + 1;
bl[i + 8].x = x + 1; bl[i + 8].y = y + 1;
}

===================

This is temporary bugfix, which is compiled correctly
with SDCC and works fine:

#ifdef SDCC_BUGFIX
static void s_Games_SI_BInit(UINT8 *bl, UINT8 val) //
This function must be used due to SDCC compiler bugs
{
DBG("s_Games_SI_BInit - start");

*bl = val;

DBG("s_Games_SI_BInit - end");
}

static void
s_Games_SI_BlockInit(S_GAMES_SI_BLOCK_STRUCT *bl, UINT8
i, UINT8 x, UINT8 y)
{
s_Games_SI_BInit(&bl[i ].x, x - 1);
s_Games_SI_BInit(&bl[i + 1].x, x );
s_Games_SI_BInit(&bl[i + 2].x, x + 1);
s_Games_SI_BInit(&bl[i + 3].x, x - 1);
s_Games_SI_BInit(&bl[i + 4].x, x );
s_Games_SI_BInit(&bl[i + 5].x, x + 1);
s_Games_SI_BInit(&bl[i + 6].x, x - 1);
s_Games_SI_BInit(&bl[i + 7].x, x );
s_Games_SI_BInit(&bl[i + 8].x, x + 1);

s_Games_SI_BInit(&bl[i ].y, y - 1);
s_Games_SI_BInit(&bl[i + 1].y, y - 1);
s_Games_SI_BInit(&bl[i + 2].y, y - 1);
s_Games_SI_BInit(&bl[i + 3].y, y );
s_Games_SI_BInit(&bl[i + 4].y, y );
s_Games_SI_BInit(&bl[i + 5].y, y );
s_Games_SI_BInit(&bl[i + 6].y, y + 1);
s_Games_SI_BInit(&bl[i + 7].y, y + 1);
s_Games_SI_BInit(&bl[i + 8].y, y + 1);
}
#else
...

Used structure:

typedef struct
{
S_GAMES_SI_CHARS c;
UINT8 x, y;
}S_GAMES_SI_BLOCK_STRUCT;
#define S_GAMES_SI_BLOCK_STRUCT_size
sizeof(S_GAMES_SI_BLOCK_STRUCT)

S_GAMES_SI_CHARS is enum (8bit), UINT8 is unsigned char.

I am sure, I haven't overflowed array.

Discussion

  • Logged In: YES
    user_id=564030
    Originator: NO

    Your code is affected by _two_ Z80 code generation bugs.

    The first affected all b[i] except for b[0]. I fixed it in #5027. It was a bug in register pair loading.

    The other one affects b[i + 2].y only. It is a bug in code generation for 16-bit addition, the same bug as #1736867.

     
  • Logged In: YES
    user_id=564030
    Originator: NO

    Fixed in #5028.

    Philipp

     
    • status: open --> closed-fixed