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]
Other format: [Raw text]

Re: PR tree-optimization/19903


Eric Botcazou wrote:
> 
> Something like that (untested except on cxa4006.adb)?
> 
> 	* tree-chrec.c (chrec_convert): Return chrec_dont_know for constants
> 	that don't fit in their type after conversion.
> 

Seems okay.

> Index: tree-chrec.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/tree-chrec.c,v
> retrieving revision 2.12.12.1
> diff -u -p -r2.12.12.1 tree-chrec.c
> --- tree-chrec.c	1 Mar 2005 16:27:48 -0000	2.12.12.1
> +++ tree-chrec.c	4 Apr 2005 10:13:06 -0000
> @@ -1037,6 +1037,20 @@ chrec_convert (tree type, 
>  	TREE_OVERFLOW (res) = 0;
>  	if (CONSTANT_CLASS_P (res))
>  	  TREE_CONSTANT_OVERFLOW (res) = 0;
> +
> +	/* But reject constants that don't fit in their type after conversion.
> +	   This can happen if TYPE_MIN_VALUE or TYPE_MAX_VALUE are not the
> +	   natural values associated to TYPE_PRECISION and TYPE_UNSIGNED, and
> +	   can cause problems later when computing niters of loops.  Note that
> +	   we don't do the check before converting because we don't want to
> +	   reject conversions of negative chrecs to unsigned types.  */
> +	if (TREE_CODE (res) == INTEGER_CST
> +	    && TREE_CODE (type) == INTEGER_TYPE)
> +	  {
> +	    if (!int_fits_type_p (res, type))
> +	      res = chrec_dont_know;
> +	  }
> +
>  	return res;
>        }
>      }

A small change: could you remove the second "if" and insert its
condition at the end of the first list.

The documentation should also be changed with something like that:

*** tree-chrec.c.~2.13.~	2005-03-01 16:14:23.000000000 +0100
--- tree-chrec.c	2005-04-04 13:22:17.293584808 +0200
***************
*** 1002,1008 ****
  
  
  
! /* Convert the initial condition of chrec to type.  */
  
  tree 
  chrec_convert (tree type, 
--- 1002,1024 ----
  
  
  
! /* Convert CHREC to TYPE.  The following is rule is always true:
!    TREE_TYPE (chrec) == TREE_TYPE (CHREC_LEFT (chrec)) == TREE_TYPE
!    (CHREC_RIGHT (chrec)).  An example of what could happen when adding
!    two chrecs and the type of the CHREC_RIGHT is different than
!    CHREC_LEFT is:
!    
!    {(uint) 0, +, (uchar) 10} +
!    {(uint) 0, +, (uchar) 250}
!    
!    that would produce a wrong result if CHREC_RIGHT is not (uint):
!    
!    {(uint) 0, +, (uchar) 4}
! 
!    instead of
! 
!    {(uint) 0, +, (uint) 260}
! */
  
  tree 
  chrec_convert (tree type, 


Thank you,
Sebastian


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