diff mbox

Fix oversight in change to gimple_fold_stmt_to_constant_1

Message ID 201112092209.43595.ebotcazou@adacore.com
State New
Headers show

Commit Message

Eric Botcazou Dec. 9, 2011, 9:09 p.m. UTC
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.
diff mbox

Patch

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