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]

Bug in egcs 1.1 on OSF1/alpha (-O2)


Hi,

Trying to help someone with installation troubles for SWI-Prolog, I stumbled
onto a bug in the optimizer of

	egcs-2.91.57 19980901 (egcs-1.1 release)

running on

	OSF1 alpha.logic.tuwien.ac.at V4.0 878 alpha

Using -O2, the code below misbehaves, while using no optimisation all
is fine.   I cannot find a bug in the code and it has been compiled
by many compilers on many platforms.

Summarising the problem:

Relevant headers:

#define STATIC_BUFFER_SIZE (512)
typedef struct
{ char *        base;                   /* allocated base */
  char *        top;                    /* pointer to top */
  char *        max;                    /* current location */
  char          static_buffer[STATIC_BUFFER_SIZE];
} tmp_buffer, *TmpBuffer;

#define addUnalignedBuffer(b, obj, type) \
        do \
        { if ( (b)->top + sizeof(type) > (b)->max ) \
            growBuffer((Buffer)b, sizeof(type)); \
          memcpy((b)->top, (char *)&obj, sizeof(type)); \
          (b)->top += sizeof(type); \
        } while(0)


Usage:

	...
	addUnalignedBuffer(&info->vars, p, Word);
	...

Where Word is defined as unsigned long *, and p is of type Word.
info->vars is a tmp_buffer.

Instead of writing 8 bytes to the buffer, it just writes a single
byte to the buffer.

To reproduce, fetch

	ftp://swi.psy.uva.nl/pub/SWI-Prolog/pl-3.2.8.tar.gz

and do:

	% <unpack it>
	% cd pl-3.2.8/src
	% ./configure --disable-segv-handling
	% make
	<crash when running Prolog engine>

	% gdb pl
	(gdb) break pl-rec.c:<line-holding-above-in compile_term_to_heap()>
	(gdb) r -O -o pl.prc -b ../boot/init.pl
	(gdb) p info->vars
	(gdb) n
	(gdb) p info->vars

It appears optimisation replaces memcpy() with wrong code (but my knowledge
of alpha assembler is extremely limited :-).

	Regards --- Jan


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