[PATCH] Fix useless_type_conversion_p with incomplete types (PR middle-end/38505)

Jakub Jelinek jakub@redhat.com
Tue Dec 30 23:51:00 GMT 2008


On Mon, Dec 29, 2008 at 05:21:43PM +0100, Richard Guenther wrote:
> On Wed, Dec 17, 2008 at 4:42 PM, Ian Lance Taylor <iant@google.com> wrote:
> > Jakub Jelinek <jakub@redhat.com> writes:
> >
> >> 2008-12-15  Jakub Jelinek  <jakub@redhat.com>
> >>
> >>       PR middle-end/38505
> >>       * tree-ssa.c (useless_type_conversion_p_1): Return
> >>       false if inner_type is incomplete and outer_type is complete.
> >>
> >>       * gcc.c-torture/compile/pr38505.c: New test.
> >
> > This is OK.
> 
> I think the other patch is better.  The important difference is only if we
> de-reference a pointer type.

After discussion on IRC and bootstrapping/regtesting on x86_64-linux, I've reverted
this patch and applied the other patch instead.

2008-12-31  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/38505
	* tree-ssa-ccp.c (may_propagate_address_into_dereference): Return
	false if ADDR's operand has incomplete type.

	Revert:
	2008-12-15  Jakub Jelinek  <jakub@redhat.com>
	PR middle-end/38505
	* tree-ssa.c (useless_type_conversion_p_1): Return
	false if inner_type is incomplete and outer_type is complete.

--- gcc/tree-ssa.c.jj	2008-11-07 23:00:33.000000000 +0100
+++ gcc/tree-ssa.c	2008-12-15 11:29:44.000000000 +0100
@@ -1188,11 +1188,6 @@ useless_type_conversion_p_1 (tree outer_
       if (TREE_CODE (inner_type) != TREE_CODE (outer_type))
 	return false;
 
-      /* Conversion from an incomplete to a complete type is never
-	 useless.  */
-      if (!COMPLETE_TYPE_P (inner_type) && COMPLETE_TYPE_P (outer_type))
-	return false;
-
       /* ???  This seems to be necessary even for aggregates that don't
 	 have TYPE_STRUCTURAL_EQUALITY_P set.  */
 
	* gcc.c-torture/compile/pr38505.c: New test.

--- gcc/tree-ssa-ccp.c.jj	2008-12-10 16:54:35.000000000 +0100
+++ gcc/tree-ssa-ccp.c	2008-12-12 21:26:56.000000000 +0100
@@ -860,6 +860,10 @@ may_propagate_address_into_dereference (
   gcc_assert (INDIRECT_REF_P (deref)
 	      && TREE_CODE (addr) == ADDR_EXPR);
 
+  /* Don't propagate if ADDR's operand has incomplete type.  */
+  if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_OPERAND (addr, 0))))
+    return false;
+
   /* If the address is invariant then we do not need to preserve restrict
      qualifications.  But we do need to preserve volatile qualifiers until
      we can annotate the folded dereference itself properly.  */

	Jakub



More information about the Gcc-patches mailing list