From b6d3c0311a633503f63884eb8eec3679256ace2c Mon Sep 17 00:00:00 2001
From: Jan Hubicka <hubicka@ucw.cz>
Date: Wed, 21 Oct 2015 20:00:30 +0200
Subject: [PATCH] re PR middle-end/67966 (ICE in convert_move, at expr.c:282)

	PR middle-end/67966
	* tree.c (verify_type): Verify that TYPE_MODE match
 	between TYPE_CANONICAL and type.
 	* expr.c (store_expr_with_bounds): Revert my previous change.
 	* expmed.c (store_bit_field_1): Revert prevoius change.
 	* gimple-expr.c (useless_type_conversion_p): Require TYPE_MODE
 	to match for all types.

From-SVN: r229132
---
 gcc/ChangeLog     | 10 ++++++++++
 gcc/expmed.c      |  8 --------
 gcc/expr.c        |  8 --------
 gcc/gimple-expr.c | 13 +++++--------
 gcc/tree.c        |  8 ++++++++
 5 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 21164b13ca30..266310252a54 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2015-10-11  Jan Hubicka  <hubicka@ucw.cz>
+
+	PR middle-end/67966
+	* tree.c (verify_type): Verify that TYPE_MODE match
+ 	between TYPE_CANONICAL and type.
+ 	* expr.c (store_expr_with_bounds): Revert my previous change.
+ 	* expmed.c (store_bit_field_1): Revert prevoius change.
+ 	* gimple-expr.c (useless_type_conversion_p): Require TYPE_MODE
+ 	to match for all types.
+
 2015-10-21  Nathan Sidwell  <nathan@codesourcery.com>
 
 	* omp-low.c (check_omp_nesting_restrictions): Check OpenACC loop
diff --git a/gcc/expmed.c b/gcc/expmed.c
index 69ea511a6f6d..93cf50822aef 100644
--- a/gcc/expmed.c
+++ b/gcc/expmed.c
@@ -757,14 +757,6 @@ store_bit_field_1 (rtx str_rtx, unsigned HOST_WIDE_INT bitsize,
       }
   }
 
-  /* We allow move between structures of same size but different mode.
-     If source is in memory and the mode differs, simply change the memory.  */
-  if (GET_MODE (value) == BLKmode && GET_MODE (op0) != BLKmode)
-    {
-      gcc_assert (MEM_P (value));
-      value = adjust_address_nv (value, GET_MODE (op0), 0);
-    }
-
   /* Storing an lsb-aligned field in a register
      can be done with a movstrict instruction.  */
 
diff --git a/gcc/expr.c b/gcc/expr.c
index 595324dc3959..adde00d078ab 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -5425,14 +5425,6 @@ store_expr_with_bounds (tree exp, rtx target, int call_param_p,
     temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
 			  temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
 
-  /* We allow move between structures of same size but different mode.
-     If source is in memory and the mode differs, simply change the memory.  */
-  if (GET_MODE (temp) == BLKmode && GET_MODE (target) != BLKmode)
-    {
-      gcc_assert (MEM_P (temp));
-      temp = adjust_address_nv (temp, GET_MODE (target), 0);
-    }
-
   /* If value was not generated in the target, store it there.
      Convert the value to TARGET's type first if necessary and emit the
      pending incrementations that have been queued when expanding EXP.
diff --git a/gcc/gimple-expr.c b/gcc/gimple-expr.c
index 2a6ba1aadb91..c6dd2ebb0e93 100644
--- a/gcc/gimple-expr.c
+++ b/gcc/gimple-expr.c
@@ -87,10 +87,8 @@ useless_type_conversion_p (tree outer_type, tree inner_type)
   if (inner_type == outer_type)
     return true;
 
-  /* Changes in machine mode are never useless conversions unless we
-     deal with aggregate types in which case we defer to later checks.  */
-  if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type)
-      && !AGGREGATE_TYPE_P (inner_type))
+  /* Changes in machine mode are never useless conversions unless.  */
+  if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type))
     return false;
 
   /* If both the inner and outer types are integral types, then the
@@ -270,10 +268,9 @@ useless_type_conversion_p (tree outer_type, tree inner_type)
      use the types in move operations.  */
   else if (AGGREGATE_TYPE_P (inner_type)
 	   && TREE_CODE (inner_type) == TREE_CODE (outer_type))
-    return (!TYPE_SIZE (outer_type)
-	    || (TYPE_SIZE (inner_type)
-		&& operand_equal_p (TYPE_SIZE (inner_type),
-				    TYPE_SIZE (outer_type), 0)));
+    return (TYPE_MODE (outer_type) != BLKmode
+	    || operand_equal_p (TYPE_SIZE (inner_type),
+			        TYPE_SIZE (outer_type), 0));
 
   else if (TREE_CODE (inner_type) == OFFSET_TYPE
 	   && TREE_CODE (outer_type) == OFFSET_TYPE)
diff --git a/gcc/tree.c b/gcc/tree.c
index 6c75699b36de..adc874847ff9 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -13408,6 +13408,14 @@ verify_type (const_tree t)
       error_found = true;
     }
 
+  if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
+      && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
+    {
+      error ("TYPE_MODE of TYPE_CANONICAL is not compatible");
+      debug_tree (ct);
+      error_found = true;
+    }
+
 
   /* Check various uses of TYPE_MINVAL.  */
   if (RECORD_OR_UNION_TYPE_P (t))
-- 
GitLab