This is the mail archive of the gcc-patches@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]

Re: optimizer bug, latest version of egcs ( 0 && 0 => 1 )



kerr@pa.dec.com said:
> This bug occurs on multiple platforms (x86, arm, alpha), on both egcs
> and gcc (2.8) variants (but not in gcc 2.7.2.2, nor in the DEC
> compiler), appears to be in cc1, and only occurs with optimization on.
> 


> When you compile the program with no optimization, output is as
> expected:

> teeny: gcc -o foo foo.c teeny: ./foo Expect 65535, 0, 0  ->  65535 0 0

> When you compile the program with optimization, output is different:

> teeny: gcc -o foo -O foo.c teeny: ./foo Expect 65535, 0, 0  ->  65535
> 0 1

> #include <stdio.h>
> typedef struct {
>   unsigned int beg; } help1_t;
> main() {
>   help1_t foo;
>   foo.beg = (unsigned int)(-1);
>   printf("Expect 65535, 0, 0  ->  %d %d %d\n",
> 	 ( (unsigned short)foo.beg ),
> 	 ( (unsigned short)foo.beg != (unsigned short)65535 ),
> 	 (
> 	  ( (unsigned short)foo.beg != (unsigned short)65535 )
> 	  && 
> 	  ( (unsigned short)foo.beg != (unsigned short)65535 )
> 	  )
> 	 );
>   return(0); } 

The problem seems to lie in make_range, which is stripping off the cast 
information before saving it.  Here's a tentative patch which seems to fix 
the problem as reported.

Would someone with better knowledge of rtl generation care to comment?

Richard

Tue Mar 23 15:45:25 1999  Richard Earnshaw (rearnsha@arm.com)

	* fold-const.c (make_range): If orig_type is unset, set it as soon as
	we know the type.


Index: fold-const.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/fold-const.c,v
retrieving revision 1.56
diff -p -r1.56 fold-const.c
*** fold-const.c	1999/03/15 05:30:02	1.56
--- fold-const.c	1999/03/23 15:48:43
*************** make_range (exp, pin_p, plow, phigh)
*** 3132,3138 ****
  	  if (TREE_CODE_CLASS (code) == '<' 
  	      || TREE_CODE_CLASS (code) == '1'
  	      || TREE_CODE_CLASS (code) == '2')
! 	    type = TREE_TYPE (arg0);
  	  if (TREE_CODE_CLASS (code) == '2' 
  	      || TREE_CODE_CLASS (code) == '<'
  	      || (TREE_CODE_CLASS (code) == 'e' 
--- 3132,3143 ----
  	  if (TREE_CODE_CLASS (code) == '<' 
  	      || TREE_CODE_CLASS (code) == '1'
  	      || TREE_CODE_CLASS (code) == '2')
! 	    {
! 	      type = TREE_TYPE (arg0);
! 	      if (orig_type == NULL_TREE)
! 		orig_type = type;
! 	    }
! 
  	  if (TREE_CODE_CLASS (code) == '2' 
  	      || TREE_CODE_CLASS (code) == '<'
  	      || (TREE_CODE_CLASS (code) == 'e' 

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