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]

[tuples] Fix SRA of gcc.c-torture/unsorted/structret.c


Hi!

gcc.c-torture/unsorted/structret.c ICEs on the tuples branch,
because fold_build3 (BIT_FIELD_REF, ...) can return a NOP_EXPR
which is later on used as LHS for GIMPLE_ASSIGN.  On the trunk
this happens to work, eventhough it is clearly invalid GIMPLE
even there.  As there are many places in which fold_build3
is called on BIT_FIELD_REF and all in the end call sra_build_assignment,
I think it is best to handle this case in there.

Bootstrapped/regtested on x86_64-linux, ok for tuples (or for trunk
instead)?

Note that this patch doesn't add force_gimple_operand calls which
might be needed too, while I don't have a testcase where invalid
GIMPLE is generated, I don't see anything that would actually check
that invalid GIMPLE isn't passed as RHS for gimple assignment.
But that can be dealt with in a separate patch.

2008-07-07  Jakub Jelinek  <jakub@redhat.com>

	* tree-sra.c (sra_build_assignment): Handle CONVERT_EXPR_P
	dst.

--- gcc/tree-sra.c.jj	2008-07-02 11:38:31.000000000 +0200
+++ gcc/tree-sra.c	2008-07-07 19:19:01.000000000 +0200
@@ -2245,6 +2245,9 @@ sra_build_assignment (tree dst, tree src
 	  var = utmp;
 	}
 
+      /* fold_build3 (BIT_FIELD_REF, ...) sometimes returns a cast.  */
+      STRIP_NOPS (dst);
+
       /* Finally, move and convert to the destination.  */
       if (!useless_type_conversion_p (TREE_TYPE (dst), TREE_TYPE (var)))
 	{
@@ -2269,6 +2272,12 @@ sra_build_assignment (tree dst, tree src
       return seq;
     }
 
+  /* fold_build3 (BIT_FIELD_REF, ...) sometimes returns a cast.  */
+  if (CONVERT_EXPR_P (dst))
+    {
+      STRIP_NOPS (dst);
+      src = fold_convert (TREE_TYPE (dst), src);
+    }
   /* It was hoped that we could perform some type sanity checking
      here, but since front-ends can emit accesses of fields in types
      different from their nominal types and copy structures containing
@@ -2279,8 +2288,8 @@ sra_build_assignment (tree dst, tree src
      So we just assume type differences at this point are ok.
      The only exception we make here are pointer types, which can be different
      in e.g. structurally equal, but non-identical RECORD_TYPEs.  */
-  if (POINTER_TYPE_P (TREE_TYPE (dst))
-      && !useless_type_conversion_p (TREE_TYPE (dst), TREE_TYPE (src)))
+  else if (POINTER_TYPE_P (TREE_TYPE (dst))
+	   && !useless_type_conversion_p (TREE_TYPE (dst), TREE_TYPE (src)))
     src = fold_convert (TREE_TYPE (dst), src);
 
   stmt = gimple_build_assign (dst, src);

	Jakub


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