This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[LTO][PATCH] Fix for type merging with struct and typedef struct
- From: simonb at google dot com (Simon Baldwin)
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 24 Dec 2008 20:34:58 +0000 (GMT)
- Subject: [LTO][PATCH] Fix for type merging with struct and typedef struct
This patch fixes a failure to link where a struct is used in one module, and
a typedef for the struct in another. Currently, lto1 complains that the
types do not match.
gcc/ChangeLog.lto
2008-12-24 Simon Baldwin <simonb@google.com>
* lto-symtab.c (lto_same_type_p): Compare TYPE_MAIN_VARIANTs for
class types if the primary identifier string comparison fails.
gcc/testsuite/ChangeLog.lto
2008-12-24 Simon Baldwin <simonb@google.com>
* gcc.dg/20081224_0.h: New.
* gcc.dg/20081224_0.c: New.
* gcc.dg/20081224_1.c: New.
Index: gcc/lto-symtab.c
===================================================================
--- gcc/lto-symtab.c (revision 142907)
+++ gcc/lto-symtab.c (working copy)
@@ -279,6 +279,8 @@ lto_same_type_p (tree type_1, tree type_
/* Enumeration and class types are the same if they have the same
name. */
{
+ tree variant_1 = TYPE_MAIN_VARIANT (type_1);
+ tree variant_2 = TYPE_MAIN_VARIANT (type_2);
tree name_1 = TYPE_NAME (type_1);
tree name_2 = TYPE_NAME (type_2);
if (!name_1 || !name_2)
@@ -303,7 +305,18 @@ lto_same_type_p (tree type_1, tree type_
/* Identifiers can be compared with pointer equality rather
than a string comparison. */
- return name_1 == name_2;
+ if (name_1 == name_2)
+ return true;
+
+ /* If either type has a variant type, compare that. This finds
+ the case where a struct is typedef'ed in one module but referred
+ to as 'struct foo' in the other; here, the main type for one is
+ 'foo', and for the other 'foo_t', but the variants have the same
+ name 'foo'. */
+ if (variant_1 != type_1 || variant_2 != type_2)
+ return lto_same_type_p (variant_1, variant_2);
+ else
+ return false;
}
/* FIXME: add pointer to member types. */
Index: gcc/testsuite/gcc.dg/lto/20081224_0.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/20081224_0.c (revision 0)
+++ gcc/testsuite/gcc.dg/lto/20081224_0.c (revision 0)
@@ -0,0 +1,9 @@
+/* { dg-do link } */
+/* { dg-options "{-fwhopr -shared}" } */
+#include "20081224_0.h"
+
+extern struct foo x;
+
+void f(void) {
+ x.x = 0;
+}
Index: gcc/testsuite/gcc.dg/lto/20081224_1.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/20081224_1.c (revision 0)
+++ gcc/testsuite/gcc.dg/lto/20081224_1.c (revision 0)
@@ -0,0 +1,2 @@
+#include "20081224_0.h"
+foo_t x;
Index: gcc/testsuite/gcc.dg/lto/20081224_0.h
===================================================================
--- gcc/testsuite/gcc.dg/lto/20081224_0.h (revision 0)
+++ gcc/testsuite/gcc.dg/lto/20081224_0.h (revision 0)
@@ -0,0 +1,3 @@
+typedef struct foo {
+ int x;
+} foo_t;