Workaround for Sun V5.0 compiler

Jeffrey A Law law@cygnus.com
Fri Aug 27 22:43:00 GMT 1999


There's been numerous reports of bootstrap comparison failures when building
gcc-2.95[.1] with the Sun V5.0 compilers.  Through the efforts of Patrick Chan
we have been able to isolate a bug in the Sun V5.0 compiler.

For the interested parties, here's the testcase the Sun compilers mis-compile:

foo(long x)
{
  if ( -x >= 0 )
    printf("%ld is >= 0\n", -x);
  else
    printf("%ld is < 0\n", -x);
}
 
main()
{
  foo (0x80000000);
}

Anyway, this patch works around the problem.  It will be seriously considered
for gcc-2.95.2.

	* cse.c (fold_rtx): Work around bug in Sun V5.0 compilers.

Index: cse.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cse.c,v
retrieving revision 1.82
diff -c -3 -p -r1.82 cse.c
*** cse.c	1999/08/25 13:37:44	1.82
--- cse.c	1999/08/28 05:39:50
*************** fold_rtx (x, insn)
*** 5802,5808 ****
  	     hence not save anything) or be incorrect.  */
  	  if (const_arg1 != 0 && GET_CODE (const_arg1) == CONST_INT
  	      && INTVAL (const_arg1) < 0
! 	      && - INTVAL (const_arg1) >= 0
  	      && GET_CODE (folded_arg1) == REG)
  	    {
  	      rtx new_const = GEN_INT (- INTVAL (const_arg1));
--- 5802,5815 ----
  	     hence not save anything) or be incorrect.  */
  	  if (const_arg1 != 0 && GET_CODE (const_arg1) == CONST_INT
  	      && INTVAL (const_arg1) < 0
! 	      /* This used to test
! 
! 	         - INTVAL (const_arg1) >= 0
! 
! 		 But The Sun V5.0 compilers mis-compiled that test.  So
! 		 instead we test for the problematic value in a more direct
! 		 manner and hope the Sun compilers get it correct.  */
! 	      && INTVAL (const_arg1) != (1 << (HOST_BITS_PER_WIDE_INT - 1))
  	      && GET_CODE (folded_arg1) == REG)
  	    {
  	      rtx new_const = GEN_INT (- INTVAL (const_arg1));






More information about the Gcc-patches mailing list