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]

Fix oversight in change to gimple_fold_stmt_to_constant_1


When the call to useless_type_conversion_p was removed for the pointer sub-case 
in the GIMPLE_UNARY_RHS case, it was replaced with a check on TYPE_ADDR_SPACE.
This isn't sufficient to guarantee that the value is preserved when pointer can 
have different modes like on s390x or VMS, and useless_type_conversion_p has a 
check on TYPE_MODE so you'll get a verification failure at -O on the attached 
testcase because FRE builds a VIEW_CONVERT_EXPR with different sizes.

Tested on i586-suse-linux, applied on the mainline as obvious.


2011-12-09  Eric Botcazou  <ebotcazou@adacore.com>

	* gimple-fold.c (gimple_fold_stmt_to_constant_1) <GIMPLE_UNARY_RHS>:
	Also check the TYPE_MODE to recognize useless pointer conversions.


2011-12-09  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc.c-torture/compile/20111209-1.c: New test.


-- 
Eric Botcazou
Index: gimple-fold.c
===================================================================
--- gimple-fold.c	(revision 182102)
+++ gimple-fold.c	(working copy)
@@ -2517,8 +2517,10 @@ gimple_fold_stmt_to_constant_1 (gimple s
 	      if (CONVERT_EXPR_CODE_P (subcode)
 		  && POINTER_TYPE_P (TREE_TYPE (lhs))
 		  && POINTER_TYPE_P (TREE_TYPE (op0))
-		  && (TYPE_ADDR_SPACE (TREE_TYPE (lhs))
-		      == TYPE_ADDR_SPACE (TREE_TYPE (op0))))
+		  && TYPE_ADDR_SPACE (TREE_TYPE (lhs))
+		     == TYPE_ADDR_SPACE (TREE_TYPE (op0))
+		  && TYPE_MODE (TREE_TYPE (lhs))
+		     == TYPE_MODE (TREE_TYPE (op0)))
 		return op0;
 
               return
/* { dg-do compile { target s390x-*-* *-*-*vms* } } */

typedef char* char_ptr32 __attribute__ ((mode(SI)));

char_ptr32 getenv (const char *name);
unsigned long strlen (const char *str);

void
__gnat_getenv (char *name, int *len, char **value)
{
  *value = getenv (name);
  *len = strlen (*value);
}

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