[CVS 980420] Still strength-reduce bug on HP-UX!
Manfred Hollstein
manfred@s-direktnet.de
Tue Apr 21 07:12:00 GMT 1998
The appended code snippet is a reduced part from our very big project
code here. It fails with strength-reduction enabled on
hppa1.1-hp-hpux10.20, but not on sparc-sun-solaris2.5.1,
sparc-sun-sunos4.1.4, m68k-motorola-sysv and m88k-motorola-sysv3.
$ ./xgcc -B./ -O -fstrength-reduce strength-reduce-bug-on-HP.cc
$ ./a.out
ABORT instruction (core dumped)
This is with current egcs source from CVS (as of 1998/04/20 18:17:02
MET DST), but interestingly, it fails with all gcc versions I have
available here (2.7.2, 2.8.1, egcs-1.0.2, egcs-2.91.24)!
Perhaps we could add the source file to egcs' testsuite.
manfred
// Special g++ Options: -O -fstrength-reduce
/*
* Compile this file with strength-reduction enabled:
* gcc -O -fstrength-reduce this-file.cc
*
* When running the resulting a.out, the output should look like:
buf 0x01020304
buf 0x01020304
* If the last line has the bytes reversed as in:
buf 0x04030201
* strength-reduction does not work!
*/
#include <stdio.h>
#include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif
extern void abort ();
#ifdef __cplusplus
}
#endif
int main ()
{
unsigned char bufin[4];
unsigned char bufout[4];
unsigned long twoc = 0;
long dst;
int i;
bufin[0] = '\x01';
bufin[1] = '\x02';
bufin[2] = '\x03';
bufin[3] = '\x04';
/* printf ("bufin 0x%02x%02x%02x%02x\n", bufin[0], bufin[1], bufin[2], bufin[3]); */
for (i = 3; i >= 0; i--)
twoc = (twoc << 8) + bufin[i];
if (twoc <= LONG_MAX)
dst = twoc;
else
dst = - (long) (ULONG_MAX - twoc) - 1;
twoc = dst;
for (i = 0; i < 4; i++)
{
bufout[i] = (unsigned char) twoc;
twoc >>= 8;
}
/* printf("bufout 0x%02x%02x%02x%02x\n", bufout[0], bufout[1], bufout[2], bufout[3]); */
if (! (bufin[0] == bufout[0] &&
bufin[1] == bufout[1] &&
bufin[2] == bufout[2] &&
bufin[3] == bufout[3]))
abort ();
return 0;
}
More information about the Gcc-bugs
mailing list