[PATCH] Fix PR41491

Richard Guenther rguenther@suse.de
Wed Dec 2 22:57:00 GMT 2009


On Wed, 2 Dec 2009, Eric Botcazou wrote:

> > This fixes an ICE in VRP that happens because we leak arithmetic
> > in domain types into the IL.  That's generally a bad idea as they
> > have the same issue as Ada sub-types.
> 
> ...used to have.  Ada subtypes directly referenced in the IL (as opposed to 
> indirectly, like through TYPE_DOMAIN) should be "clean" now.

Indeed.  And the following fixes the fallout from the patch, notable
in the g++.dg/tree-ssa/pr19807.C fail it caused (that got unnoticed
in the C++ fail noise).  div_if_zero_remainder does not properly
honor sizetypes.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.


2009-12-02  Richard Guenther  <rguenther@suse.de>

	* fold-const.c (div_if_zero_remainder): Honor that sizetypes
	are sign-extending.  Simplify.

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c	(revision 154920)
--- gcc/fold-const.c	(working copy)
*************** div_if_zero_remainder (enum tree_code co
*** 881,902 ****
    HOST_WIDE_INT int1h, int2h;
    unsigned HOST_WIDE_INT quol, reml;
    HOST_WIDE_INT quoh, remh;
!   tree type = TREE_TYPE (arg1);
!   int uns = TYPE_UNSIGNED (type);
  
    int1l = TREE_INT_CST_LOW (arg1);
    int1h = TREE_INT_CST_HIGH (arg1);
-   /* &obj[0] + -128 really should be compiled as &obj[-8] rather than
-      &obj[some_exotic_number].  */
-   if (POINTER_TYPE_P (type))
-     {
-       uns = false;
-       type = signed_type_for (type);
-       fit_double_type (int1l, int1h, &int1l, &int1h,
- 		       type);
-     }
-   else
-     fit_double_type (int1l, int1h, &int1l, &int1h, type);
    int2l = TREE_INT_CST_LOW (arg2);
    int2h = TREE_INT_CST_HIGH (arg2);
  
--- 881,898 ----
    HOST_WIDE_INT int1h, int2h;
    unsigned HOST_WIDE_INT quol, reml;
    HOST_WIDE_INT quoh, remh;
!   int uns;
! 
!   /* The sign of the division is according to operand two, that
!      does the correct thing for POINTER_PLUS_EXPR where we want
!      a signed division.  */
!   uns = TYPE_UNSIGNED (TREE_TYPE (arg2));
!   if (TREE_CODE (TREE_TYPE (arg2)) == INTEGER_TYPE
!       && TYPE_IS_SIZETYPE (TREE_TYPE (arg2)))
!     uns = false;
  
    int1l = TREE_INT_CST_LOW (arg1);
    int1h = TREE_INT_CST_HIGH (arg1);
    int2l = TREE_INT_CST_LOW (arg2);
    int2h = TREE_INT_CST_HIGH (arg2);
  
*************** div_if_zero_remainder (enum tree_code co
*** 905,911 ****
    if (remh != 0 || reml != 0)
      return NULL_TREE;
  
!   return build_int_cst_wide (type, quol, quoh);
  }
  
  /* This is nonzero if we should defer warnings about undefined
--- 901,907 ----
    if (remh != 0 || reml != 0)
      return NULL_TREE;
  
!   return build_int_cst_wide (TREE_TYPE (arg1), quol, quoh);
  }
  
  /* This is nonzero if we should defer warnings about undefined



More information about the Gcc-patches mailing list