[PATCH] Fix PR tree-optimization/18184 (take 2)

Ulrich Weigand uweigand@de.ibm.com
Wed Nov 3 14:47:00 GMT 2004


Hello,

this is the second attempt to fix PR 18184 by preventing removal
of type conversions between pointers differing in their mode.

As pointed out by Richard Kenner, pointers differing by their
TYPE_REF_CAN_ALIAS_ALL flag setting also need to be distinguished,
so this version of the patch takes this flag into consideration
as well.

Bootstrapped/regtested on s390-ibm-linux and s390x-ibm-linux.
OK for mainline?

Bye,
Ulrich


ChangeLog:

	PR tree-optimization/18184
	* c-typeck.c (comptypes): Do not treat pointers of different
	modes or alias-all flags as equivalent.
	* tree-ssa.c (tree_ssa_useless_type_conversion_1): Likewise.

cp/ChangeLog:
	
	PR tree-optimization/18184
	* cp-lang.c (cxx_types_compatible_p): Do not treat pointers of
	different modes or alias-all flags as equivalent.
	* cp-typeck.c (comptypes): Likewise.

Index: gcc/c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.394
diff -c -p -r1.394 c-typeck.c
*** gcc/c-typeck.c	31 Oct 2004 06:17:49 -0000	1.394
--- gcc/c-typeck.c	3 Nov 2004 12:53:21 -0000
*************** comptypes (tree type1, tree type2)
*** 659,664 ****
--- 659,668 ----
  	   protocol qualifiers may be involved.  */
        if (c_dialect_objc () && (val = objc_comptypes (t1, t2, 0)) >= 0)
  	break;
+       /* Do not remove mode or aliasing information.  */
+       if (TYPE_MODE (t1) != TYPE_MODE (t2)
+ 	  || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
+ 	break;
        val = (TREE_TYPE (t1) == TREE_TYPE (t2)
  	     ? 1 : comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
        break;
Index: gcc/tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa.c,v
retrieving revision 2.53
diff -c -p -r2.53 tree-ssa.c
*** gcc/tree-ssa.c	31 Oct 2004 21:58:10 -0000	2.53
--- gcc/tree-ssa.c	3 Nov 2004 12:53:22 -0000
*************** tree_ssa_useless_type_conversion_1 (tree
*** 834,839 ****
--- 834,842 ----
       implement the ABI.  */
    else if (POINTER_TYPE_P (inner_type)
             && POINTER_TYPE_P (outer_type)
+ 	   && TYPE_MODE (inner_type) == TYPE_MODE (outer_type)
+ 	   && TYPE_REF_CAN_ALIAS_ALL (inner_type)
+ 	      == TYPE_REF_CAN_ALIAS_ALL (outer_type)
  	   && TREE_CODE (TREE_TYPE (outer_type)) == VOID_TYPE)
      return true;
  
*************** tree_ssa_useless_type_conversion_1 (tree
*** 841,846 ****
--- 844,852 ----
       so strip conversions that just switch between them.  */
    else if (POINTER_TYPE_P (inner_type)
             && POINTER_TYPE_P (outer_type)
+ 	   && TYPE_MODE (inner_type) == TYPE_MODE (outer_type)
+ 	   && TYPE_REF_CAN_ALIAS_ALL (inner_type)
+ 	      == TYPE_REF_CAN_ALIAS_ALL (outer_type)
             && lang_hooks.types_compatible_p (TREE_TYPE (inner_type),
  					     TREE_TYPE (outer_type)))
      return true;
Index: gcc/cp/cp-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-lang.c,v
retrieving revision 1.95
diff -c -p -r1.95 cp-lang.c
*** gcc/cp/cp-lang.c	22 Sep 2004 06:11:20 -0000	1.95
--- gcc/cp/cp-lang.c	3 Nov 2004 12:53:22 -0000
*************** static int cxx_types_compatible_p (tree 
*** 112,117 ****
--- 112,119 ----
       interchangeable.  FIXME should we try to replace all references with
       pointers?  */
    if (POINTER_TYPE_P (x) && POINTER_TYPE_P (y)
+       && TYPE_MODE (x) == TYPE_MODE (y)
+       && TYPE_REF_CAN_ALIAS_ALL (x) == TYPE_REF_CAN_ALIAS_ALL (y)
        && same_type_p (TREE_TYPE (x), TREE_TYPE (y)))
      return 1;
  
Index: gcc/cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.591
diff -c -p -r1.591 typeck.c
*** gcc/cp/typeck.c	1 Nov 2004 09:47:59 -0000	1.591
--- gcc/cp/typeck.c	3 Nov 2004 12:53:23 -0000
*************** comptypes (tree t1, tree t2, int strict)
*** 1030,1040 ****
        if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
  		      strict & ~COMPARE_REDECLARATION))
  	return false;
!       /* Fall through.  */
  
      case POINTER_TYPE:
      case REFERENCE_TYPE:
!       return same_type_p (TREE_TYPE (t1), TREE_TYPE (t2));
  
      case METHOD_TYPE:
      case FUNCTION_TYPE:
--- 1030,1042 ----
        if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
  		      strict & ~COMPARE_REDECLARATION))
  	return false;
!       return same_type_p (TREE_TYPE (t1), TREE_TYPE (t2));
  
      case POINTER_TYPE:
      case REFERENCE_TYPE:
!       return TYPE_MODE (t1) == TYPE_MODE (t2)
! 	     && TYPE_REF_CAN_ALIAS_ALL (t1) == TYPE_REF_CAN_ALIAS_ALL (t2)
! 	     && same_type_p (TREE_TYPE (t1), TREE_TYPE (t2));
  
      case METHOD_TYPE:
      case FUNCTION_TYPE:
-- 
  Dr. Ulrich Weigand
  Linux on zSeries Development
  Ulrich.Weigand@de.ibm.com



More information about the Gcc-patches mailing list