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]

[PATCH] Fix PR33666, type verification error with folding casts from pointers


This fixes said PR by leaving int vs. pointer conversion optimization to
the hunk that exclusively deals with them.  Which needs adjustment as 
well, as it places an unnecessary restriction on them.

Bootstrapped and tested on x86_64-unknown-linux-gnu for all languages
including ada, applied to mainline.

Richard.

2007-10-05  Richard Guenther  <rguenther@suse.de>

	PR middle-end/33666
	* fold-const.c (fold_unary): Do not fold (long long)(int)ptr
	to (long long)ptr.

	* gcc.dg/pr33666.c: New testcase.

Index: testsuite/gcc.dg/pr33666.c
===================================================================
*** testsuite/gcc.dg/pr33666.c	(revision 0)
--- testsuite/gcc.dg/pr33666.c	(revision 0)
***************
*** 0 ****
--- 1,11 ----
+ /* { dg-do compile } */
+ /* { dg-options { -std=c99 } } */
+ 
+ /* This used to fail with type-checking enabled because we stripped
+    the inner conversion to unsigned int.  */
+ 
+ void __lock_get_list(void *dp)
+ {
+   if (((__SIZE_TYPE__)dp + 1) & ~1ULL)
+     ;
+ }
Index: fold-const.c
===================================================================
*** fold-const.c	(revision 129032)
--- fold-const.c	(working copy)
*************** fold_unary (enum tree_code code, tree ty
*** 8128,8134 ****
  	     (for integers).  Avoid this if the final type is a pointer
  	     since then we sometimes need the inner conversion.  Likewise if
  	     the outer has a precision not equal to the size of its mode.  */
! 	  if ((((inter_int || inter_ptr) && (inside_int || inside_ptr))
  	       || (inter_float && inside_float)
  	       || (inter_vec && inside_vec))
  	      && inter_prec >= inside_prec
--- 8128,8134 ----
  	     (for integers).  Avoid this if the final type is a pointer
  	     since then we sometimes need the inner conversion.  Likewise if
  	     the outer has a precision not equal to the size of its mode.  */
! 	  if (((inter_int && inside_int)
  	       || (inter_float && inside_float)
  	       || (inter_vec && inside_vec))
  	      && inter_prec >= inside_prec
*************** fold_unary (enum tree_code code, tree ty
*** 8158,8164 ****
  	       intermediate and final types differ, or
  	     - the final type is a pointer type and the precisions of the
  	       initial and intermediate types differ.
- 	     - the final type is a pointer type and the initial type not
  	     - the initial type is a pointer to an array and the final type
  	       not.  */
  	  if (! inside_float && ! inter_float && ! final_float
--- 8158,8163 ----
*************** fold_unary (enum tree_code code, tree ty
*** 8173,8180 ****
  	      && ! (final_ptr && inside_prec != inter_prec)
  	      && ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (type))
  		    && TYPE_MODE (type) == TYPE_MODE (inter_type))
! 	      && final_ptr == inside_ptr
! 	      && ! (inside_ptr
  		    && TREE_CODE (TREE_TYPE (inside_type)) == ARRAY_TYPE
  		    && TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
  	    return fold_build1 (code, type, TREE_OPERAND (op0, 0));
--- 8172,8178 ----
  	      && ! (final_ptr && inside_prec != inter_prec)
  	      && ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (type))
  		    && TYPE_MODE (type) == TYPE_MODE (inter_type))
! 	      && ! (inside_ptr && final_ptr
  		    && TREE_CODE (TREE_TYPE (inside_type)) == ARRAY_TYPE
  		    && TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
  	    return fold_build1 (code, type, TREE_OPERAND (op0, 0));


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