Interesting. Almost any change to the parameters - add one or remove one - and the compilation behaves properly.

Regards,
Steve


Rick Jenkins wrote:

Compiling:-

****************************************************************

// ARRAY_BUG.C demonstrates a compiler bug

unsigned char transducer_type;
long output_scale;

void show_array_bug( int limit, int gain, int p_off, int q_off )
{
 static const long std_gain[4] = { 0L, 1L, 2L, 3L };

 output_scale = ((long)limit * std_gain[transducer_type]);
}

****************************************************************

With:-

$ msp430-gcc -mmcu=msp430x149 -O2 -S array_bug.c

Produces:-

****************************************************************

        .file   "array_bug.c"
        .arch msp430x149

/* Hardware multiplier registers: */
__MPY=0x130
__MPYS=0x132
__MAC=0x134
__MACS=0x136
__OP2=0x138
__RESLO=0x13a
__RESHI=0x13c
__SUMEXT=0x13e

        .text
        .p2align 1,0
        .type   std_gain.0,@object
        .size   std_gain.0,16
std_gain.0:
        .long   0
        .long   1
        .long   2
        .long   3
        .p2align 1,0
.global show_array_bug
        .type   show_array_bug,@function
/***********************
* Function `show_array_bug' ***********************/
show_array_bug:
/* prologue: frame size = 0 */
.L__FrameSize_show_array_bug=0x0
.L__FrameOffset_show_array_bug=0x0
/* prologue end (size=0) */
        mov     r15, r14
        mov     r14, r15
        rla     r15
        subc    r15, r15
        inv     r15
        rla     r14
        rlc     r15
        rla     r14
        rlc     r15
        rla     r14
        rlc     r15
        rla     r14
        rlc     r15
        rla     r14
        rlc     r15
        mov     r14, &output_scale
        mov     r15, &output_scale+2
        ret
/* epilogue: not required */
/* function show_array_bug size 20 (19) */
.Lfe1:
        .size   show_array_bug,.Lfe1-show_array_bug
/********* End of function ******/

        .comm transducer_type,1
        .comm output_scale,4,2

/*********************************************************************
* File array_bug.c: code size: 20 words (0x14)
* incl. words in prologues: 0, epilogues: 1
*********************************************************************/


****************************************************************

Those unused parameters have a big effect on the code produced. In the
real function from which this is excerpted, they are all used, of
course.



Reply via email to