This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Broken optimizer in gcc-2.95.2 with m68k-elf



I've configured gcc-2.95.2 with "--target=m6k-elf
--exec-prefix=m68k_gcc", host is RH-6.2 on i686, and with the command
line: 

m68k_gcc -S -m5200 -O2 -S test.c -o test.s 

The following file executes incorrectly(verified by running it on
a 5407 eval board). I've chopped it down to a single function for
easier debugging:


/* Start of broken file */
typedef struct _OB {
  int x;
  int y;
} OB;

#define ISWHITE(ch) (ctypes[(ch)&0xff] & W_)  /* whitespace char */
#define W_  0x1                               /* flag for whitespace */

extern const unsigned short ctypes[];
extern const char HexEquiv[];
int hexfetch (int (*retriever) (OB *), OB *obr)
{
  int i;
  int digit[2];

  for (i = 0; i < 2; i++) {
    while ((digit[i] = (*retriever) (obr)) >= 0) {
      if (!ISWHITE (digit[i])) {
        break;
      }
    }
    if (digit[i] < 0) {
      return -1;
    }
  }
  return ((int) HexEquiv[digit[0]] << 4) + (int) HexEquiv[digit[1]];
}
/* End of broken file */


The result is that the value of i is incremented *in* the while loop
as if it was written as:

    while ((digit[i++] = (*retriever) (obr)) >= 0) {
      if (!ISWHITE (digit[i-1])) {
        break;
      }
    }

Which is wrong in the case where ISWHITE(digit[i]) return TRUE

Here's the offending output from gcc:

	.file	"zz.c"
gcc2_compiled.:
.text
.globl hexfetch
	.type	 hexfetch,@function
hexfetch:
	link.w %a6,#-8
	lea (-28,%sp),%sp
	movm.l #0x3c1c,(%sp)
	move.l 8(%a6),%a4
	move.l 12(%a6),%d2
	lea (-8,%a6),%a5
	lea ctypes,%a3
	move.l %a5,%a2
	move.l %a6,%d3
	subq.l #4,%d3
.L10:
	move.l %d2,-(%sp)
	jsr (%a4)
	move.l %d0,%d1
	move.l %d1,(%a2)+     <----- It shouldn't increment %a2 here!
	addq.l #4,%sp
	jblt .L14
	and.l #255,%d0
	move.w (%a3,%d0.l*2),%d0
	moveq.l #1,%d4
	and.l %d4,%d0
	tst.w %d0
	jbne .L10
	tst.l %d1
	jbge .L5
.L14:
	moveq.l #-1,%d0
	jbra .L13
.L5:
	cmp.l %a2,%d3
	jbge .L10
	lea HexEquiv,%a0
	move.l -8(%a6),%d0
	move.b (%a0,%d0.l),%d0
	extb.l %d0
	lsl.l #4,%d0
	move.l 4(%a5),%d1
	move.b (%a0,%d1.l),%d1
	extb.l %d1
	add.l %d1,%d0
.L13:
	move.l -36(%a6),%d2
	move.l -32(%a6),%d3
	move.l -28(%a6),%d4
	move.l -24(%a6),%a2
	move.l -20(%a6),%a3
	move.l -16(%a6),%a4
	move.l -12(%a6),%a5
	unlk %a6
	rts
.Lfe1:
	.size	 hexfetch,.Lfe1-hexfetch
	.ident	"GCC: (GNU) 2.95.2 19991024 (release)"


If anyone has a patch to a stock gcc-2.95.2 which fixes this I'd be most
appreciative.

TIA,

-- 
Peter Barada                                       pbarada@mail.wm.sps.mot.com
Wizard                                             781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola)       781-270-0193 (fax)

"The real art of conversation is not only to say the right thing at the
right time, but also to leave unsaid the wrong thing at the tempting
moment."  -- Unknown

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]