Hi,

There seems to be a bug in the support for GCC 3.2.3 when a structure is over 127 bytes. Depending what the source code looks like, it might do the right thing, or it might go crazy. The attached test.c file compiles OK if "GOOD_VERSION" is defined, otherwise it produces bad code. The two results, compiled with -O2, are in test.result. If I play around with the source code I can get different errors, like the registers being mixed up and overwritten.

With structures up to 126 bytes I have not seen any similar problems.

Regards,
Steve

#define GOOD_VERSION

#include <stdint.h>
#include <signal.h>
#include <io.h>

/* This is 131 bytes */
struct sss_s
{
	int16_t aaa[2];
    uint16_t bbb;
    int16_t xxx[62];
	int8_t zzz;
};

extern struct sss_s chan[3];

typedef union
{
	uint8_t uint8[72];
	uint16_t uint16[(72)/2];
} ttt_t;

ttt_t ttt;

int xxx;

void problem_routine(ttt_t *rrr, int rx_len)
{
    struct sss_s *ppp;

	switch (rrr->uint8[10])
	{
	case 0x61:
	case 0x62:
	case 0x63:
#if defined(GOOD_VERSION)
		xxx = rrr->uint8[10] - 0x61;
		ppp = &chan[xxx];
#else
		ppp = &chan[rrr->uint8[10] - 0x61];
#endif
        ttt.uint8[14] = rrr->uint8[10];
		ttt.uint8[14 + 1] = 0x80;
		ttt.uint16[7 + 1] = ppp->bbb;
		break;
	}
}
GOOD:

process_rx_message:
        mov.b   10(r15), r13
        mov.b   r13, r14
        add     #llo(-97), r14                  ; Do the test for the three 
case values
        cmp     #llo(3), r14
        jhs         .L1
        mov         r14, &xxx                       ; Extra step the bad one 
doesn't need
        ;
    mov     r14, r15                        ; 132*R14 => R15 
        rla     r15
        rla         r15
        rla         r15
        rla         r15
        rla         r15
        rla         r15
        rla         r15
        rla         r14
        rla         r14
        add         r14, r15
        ;
    mov.b       r13, &tx_msg+14
        mov.b   #llo(-128), &tx_msg+15
        mov         chan+4(r15), &tx_msg+16         ; Correct offset for bbb 
within the structure
        ret

BAD:

process_rx_message:
        mov     r15, r13 
        mov.b   10(r15), r14
        mov.b   r14, r15
        add     #llo(-97), r15                  ; Do the test for the three 
case values
        cmp     #llo(3), r15
        jhs     .L1
    ;
        push    r2
        dint                                    ; 132*R14 => R15
        nop
        mov.b   r14, &__MPY
        clr.b   &__MPY+1
        mov     #llo(-124), &__OP2
        clr.b   &__OP2+1
        mov     &__RESLO, r15
        pop     r2
        ;
    mov.b       10(r13), &tx_msg+14
        mov.b   #llo(-128), &tx_msg+15
        mov     chan+-12800(r15), &tx_msg+16    ; Eh? where does the -12800 
come from?
.L1:
        ret

Reply via email to