PR middle-end/38505
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Dec 2008 07:52:07 +0000 (07:52 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Dec 2008 07:52:07 +0000 (07:52 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@142806 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr38505.c [new file with mode: 0644]
gcc/tree-ssa.c

index df3ced5..4917689 100644 (file)
@@ -1,3 +1,9 @@
+2008-12-18  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.
+
 2008-12-17  Sebastian Pop  <sebastian.pop@amd.com>
        
         * doc/install.texi (Prerequisites): Document PPL and CLooG-PPL
index 11a6a70..0bf69e2 100644 (file)
@@ -1,3 +1,8 @@
+2008-12-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/38505
+       * gcc.c-torture/compile/pr38505.c: New test.
+
 2008-12-17  Jason Merrill  <jason@redhat.com>
 
        * g++.dg/cpp0x/auto6.C: Test more stuff.
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr38505.c b/gcc/testsuite/gcc.c-torture/compile/pr38505.c
new file mode 100644 (file)
index 0000000..b3b4a10
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR middle-end/38505 */
+/* { dg-do compile } */
+
+struct S
+{
+  unsigned short a[50];
+  unsigned short b[20];
+};
+extern void bar (struct S *);
+extern void baz (unsigned short *);
+extern unsigned short d[];
+
+void
+foo (void)
+{
+  struct S s;
+  unsigned short g[50];
+
+  baz (g);
+  __builtin_memcpy (&s, g, sizeof (g));
+  __builtin_memcpy (s.b, d, sizeof (s.b));
+  bar (&s);
+}
index 935cad6..ce0f1e4 100644 (file)
@@ -1188,6 +1188,11 @@ useless_type_conversion_p_1 (tree outer_type, tree inner_type)
       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.  */