I have found what I think may be a bug with switch() But cannot reproduce
with a simple example. (Not exactly a Bug, but 256 Bytes of wasted space are
inserted in the machine code after a switch() statement, independent of the
optimise parameter .

I am using the Latest WIN32 Build (mspgcc-setup-2002-08-14) but earlier
versions have the bug as well.

My compile command line is as follows
g:\projects\msp_source\p1>msp430-gcc -c -g -O2 -mmcu=msp430x149 -Wall -Wstri
ct-prototypes -Wa,-ahlms=test.lst -Wall test.c


Extract from the Listing showing the flaw

  10:test.c        ****          switch(c)
  74                            .stabn 68,0,10,.LM3-diag
  75                    .LM3:
  76 0004 3F50 CFFF             add     #llo(-49), r15
  77 0008 3F90 4A00             cmp     #llo(74), r15
  78 000c 4E2C                  jhs     .L2
  79 000e 0F5F                  rla     r15
  80 0010 104F 0000             br      .L12(r15)       ;       .L12
  81                            .p2align 1,0
  82                    .L12:
  83 0014 0000                  .word   .L2
  84 0016 0000                  .word   .L2
  85 0018 0000                  .word   .L2

    ... (for 256 bytes of FlashRom space)

 155 00a4 0000                  .word   .L2
 156 00a6 0000                  .word   .L2
 157                    .L6:
  11:test.c        ****          {
  12:test.c        ****
  13:test.c        ****              case 't' : //
  14:test.c        ****                         break;




The following is the minimum I have been able to create, and still reproduce
the flaw.
If I alter each case to become sequential (IE: 1,2,..7) The bug disappears.

If  the last case statement is removed, the flaw disappears. Seems very
sensitive to something in the code


//-
test.c ---------------------------------------------------------------------
-------------------------------------------------------

#include <signal.h>

void  diag(void)
{
int c;

    if (c)
    {
         switch(c)
         {

             case 't' : //
                        break;

         case 'a' :
                break;


             case 'c' : //
                _EINT();
                break;

             case 's' : // Set time
                break;

             case '1' : // test ints
                break;

             case 'z' : // configure various parameters for device
                break;

             case 'f' : //
        break;

             case 'e' : //
                break;
         }
    }
}

//--------------------------------------------------------------------------
--------------------


Am I doing something wrong to make the compiler produce this curious output,
or is this really a bug?

Cheers
Harry R. Lemmens



Reply via email to