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]

[PATCH] Fix convert_for_assignment with --combine (PR c/30762)


Hi!

convert_for_assignment only compares TYPE_MAIN_VARIANTS of the types
for equality, which isn't good enough for --combine and aggregates
in different TUs.  The following patch uses comptypes in that case
which will do the needed checking.

Regtested on x86_64-linux, ok for 4.3/4.2/4.1?

2007-03-13  Jakub Jelinek  <jakub@redhat.com>

	PR c/30762
	* c-typeck.c (convert_for_assignment): Call comptypes for
	RECORD_TYPE or UNION_TYPE.

	* gcc.dg/pr30762-1.c: New test.
	* gcc.dg/pr30762-2.c: New test.

--- gcc/c-typeck.c.jj	2007-03-12 17:18:17.000000000 +0100
+++ gcc/c-typeck.c	2007-03-13 14:45:45.000000000 +0100
@@ -3896,10 +3896,16 @@ convert_for_assignment (tree type, tree 
 	       || coder == BOOLEAN_TYPE))
     return convert_and_check (type, rhs);
 
+  /* Aggregates in different TUs might need conversion.  */
+  if ((codel == RECORD_TYPE || codel == UNION_TYPE)
+      && codel == coder
+      && comptypes (type, rhstype))
+    return convert_and_check (type, rhs);
+
   /* Conversion to a transparent union from its member types.
      This applies only to function arguments.  */
-  else if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type)
-	   && (errtype == ic_argpass || errtype == ic_argpass_nonproto))
+  if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type)
+      && (errtype == ic_argpass || errtype == ic_argpass_nonproto))
     {
       tree memb, marginal_memb = NULL_TREE;
 
--- gcc/testsuite/gcc.dg/pr30762-1.c.jj	2007-03-13 15:02:13.000000000 +0100
+++ gcc/testsuite/gcc.dg/pr30762-1.c	2007-03-13 15:05:06.000000000 +0100
@@ -0,0 +1,15 @@
+/* PR c/30762 */
+/* { dg-do compile } */
+/* { dg-options "--combine -O3" } */
+/* { dg-additional-sources pr30762-2.c } */
+
+typedef struct { int i; } D;
+extern void foo (D);
+
+void
+bar (void)
+{
+  D d;
+  d.i = 1;
+  foo (d);
+}
--- gcc/testsuite/gcc.dg/pr30762-2.c.jj	2007-03-13 15:02:10.000000000 +0100
+++ gcc/testsuite/gcc.dg/pr30762-2.c	2007-03-13 15:05:33.000000000 +0100
@@ -0,0 +1,9 @@
+/* PR c/30762 */
+/* { dg-do compile } */
+
+typedef struct { int i; } D;
+
+void
+foo (D x)
+{
+}

	Jakub


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