[PATCH] Fix PR tree-optimization/18184 (pointer mode conversions ignored)

Ulrich Weigand weigand@i1.informatik.uni-erlangen.de
Wed Oct 27 16:55:00 GMT 2004


Hello,

this patch fixes PR tree-optimization/18184 as suggested by Andrew Pinski in
http://gcc.gnu.org/ml/gcc/2004-10/msg00776.html
by not treating pointers differing in their modes as equivalent.

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 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 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.392
diff -c -p -r1.392 c-typeck.c
*** gcc/c-typeck.c	17 Oct 2004 22:01:19 -0000	1.392
--- gcc/c-typeck.c	20 Oct 2004 15:19:06 -0000
*************** comptypes (tree type1, tree type2)
*** 659,664 ****
--- 659,667 ----
  	   protocol qualifiers may be involved.  */
        if (c_dialect_objc () && (val = objc_comptypes (t1, t2, 0)) >= 0)
  	break;
+       /* Do not remove __attribute__ ((mode)) conversions.  */
+       if (TYPE_MODE (t1) != TYPE_MODE (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.49
diff -c -p -r2.49 tree-ssa.c
*** gcc/tree-ssa.c	18 Oct 2004 18:01:10 -0000	2.49
--- gcc/tree-ssa.c	20 Oct 2004 15:19:07 -0000
*************** tree_ssa_useless_type_conversion_1 (tree
*** 814,819 ****
--- 814,820 ----
       implement the ABI.  */
    else if (POINTER_TYPE_P (inner_type)
             && POINTER_TYPE_P (outer_type)
+ 	   && TYPE_MODE (inner_type) == TYPE_MODE (outer_type)
  	   && TREE_CODE (TREE_TYPE (outer_type)) == VOID_TYPE)
      return true;
  
*************** tree_ssa_useless_type_conversion_1 (tree
*** 821,826 ****
--- 822,828 ----
       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)
             && 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	20 Oct 2004 15:19:08 -0000
*************** static int cxx_types_compatible_p (tree 
*** 112,117 ****
--- 112,118 ----
       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)
        && 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.583
diff -c -p -r1.583 typeck.c
*** gcc/cp/typeck.c	18 Oct 2004 17:21:29 -0000	1.583
--- gcc/cp/typeck.c	20 Oct 2004 15:19:09 -0000
*************** comptypes (tree t1, tree t2, int strict)
*** 1034,1040 ****
  
      case POINTER_TYPE:
      case REFERENCE_TYPE:
!       return same_type_p (TREE_TYPE (t1), TREE_TYPE (t2));
  
      case METHOD_TYPE:
      case FUNCTION_TYPE:
--- 1034,1041 ----
  
      case POINTER_TYPE:
      case REFERENCE_TYPE:
!       return TYPE_MODE (t1) == TYPE_MODE (t2)
! 	     && same_type_p (TREE_TYPE (t1), TREE_TYPE (t2));
  
      case METHOD_TYPE:
      case FUNCTION_TYPE:
-- 
  Dr. Ulrich Weigand
  weigand@informatik.uni-erlangen.de



More information about the Gcc-patches mailing list