]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Backport r256989
authorMartin Liska <mliska@suse.cz>
Wed, 7 Mar 2018 09:47:46 +0000 (10:47 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Wed, 7 Mar 2018 09:47:46 +0000 (09:47 +0000)
2018-03-07  Martin Liska  <mliska@suse.cz>

Backport from mainline
2018-01-23  Martin Liska  <mliska@suse.cz>

PR lto/81440
* lto-symtab.c (lto_symtab_merge): Handle and do not warn about
trailing arrays at the end of a struct.
2018-03-07  Martin Liska  <mliska@suse.cz>

Backport from mainline
2018-01-23  Martin Liska  <mliska@suse.cz>

PR lto/81440
* gcc.dg/lto/pr81440.h: New test.
* gcc.dg/lto/pr81440_0.c: New test.
* gcc.dg/lto/pr81440_1.c: New test.

From-SVN: r258328

gcc/lto/ChangeLog
gcc/lto/lto-symtab.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/lto/pr81440.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/lto/pr81440_0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/lto/pr81440_1.c [new file with mode: 0644]

index 2d016a96ea1a0144a3488c74a087639d7a9b194f..c755b383d6d90ff0c05c80b6d89d99ee45e16616 100644 (file)
@@ -1,3 +1,12 @@
+2018-03-07  Martin Liska  <mliska@suse.cz>
+
+       Backport from mainline
+       2018-01-23  Martin Liska  <mliska@suse.cz>
+
+       PR lto/81440
+       * lto-symtab.c (lto_symtab_merge): Handle and do not warn about
+       trailing arrays at the end of a struct.
+
 2018-03-07  Martin Liska  <mliska@suse.cz>
 
        Backport from mainline
index e6fb95fe37294f61ba1b589383cbf1294c605e48..6b3b785b674fe7fa2c851a5dba3bfe12f947b5c3 100644 (file)
@@ -362,18 +362,31 @@ lto_symtab_merge (symtab_node *prevailing, symtab_node *entry)
     return false;
 
   if (DECL_SIZE (decl) && DECL_SIZE (prevailing_decl)
-      && !tree_int_cst_equal (DECL_SIZE (decl), DECL_SIZE (prevailing_decl))
+      && !tree_int_cst_equal (DECL_SIZE (decl), DECL_SIZE (prevailing_decl)))
+      {
+       if (!DECL_COMMON (decl) && !DECL_EXTERNAL (decl))
+         return false;
+
+       tree type = TREE_TYPE (decl);
+
+       /* For record type, check for array at the end of the structure.  */
+       if (TREE_CODE (type) == RECORD_TYPE)
+         {
+           tree field = TYPE_FIELDS (type);
+           while (DECL_CHAIN (field) != NULL_TREE)
+             field = DECL_CHAIN (field);
+
+           return TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE;
+         }
       /* As a special case do not warn about merging
         int a[];
         and
         int a[]={1,2,3};
         here the first declaration is COMMON
         and sizeof(a) == sizeof (int).  */
-      && ((!DECL_COMMON (decl) && !DECL_EXTERNAL (decl))
-         || TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE
-         || TYPE_SIZE (TREE_TYPE (decl))
-            != TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl)))))
-    return false;
+       else if (TREE_CODE (type) == ARRAY_TYPE)
+         return (TYPE_SIZE (decl) == TYPE_SIZE (TREE_TYPE (type)));
+      }
 
   return true;
 }
index e19c92e954876ef888fbbb19218b46d12c89c31b..2d75729f2961acd942938e5f38f9636fcab4001c 100644 (file)
@@ -1,3 +1,13 @@
+2018-03-07  Martin Liska  <mliska@suse.cz>
+
+       Backport from mainline
+       2018-01-23  Martin Liska  <mliska@suse.cz>
+
+       PR lto/81440
+       * gcc.dg/lto/pr81440.h: New test.
+       * gcc.dg/lto/pr81440_0.c: New test.
+       * gcc.dg/lto/pr81440_1.c: New test.
+
 2018-03-07  Martin Liska  <mliska@suse.cz>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.dg/lto/pr81440.h b/gcc/testsuite/gcc.dg/lto/pr81440.h
new file mode 100644 (file)
index 0000000..d9e6c3d
--- /dev/null
@@ -0,0 +1,4 @@
+typedef struct {
+  int i;
+  int ints[];
+} struct_t;
diff --git a/gcc/testsuite/gcc.dg/lto/pr81440_0.c b/gcc/testsuite/gcc.dg/lto/pr81440_0.c
new file mode 100644 (file)
index 0000000..07f2a87
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-lto-do link } */
+
+#include "pr81440.h"
+
+extern struct_t my_struct;
+
+int main() {
+ return my_struct.ints[0];
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr81440_1.c b/gcc/testsuite/gcc.dg/lto/pr81440_1.c
new file mode 100644 (file)
index 0000000..d035330
--- /dev/null
@@ -0,0 +1,6 @@
+#include "pr81440.h"
+
+struct_t my_struct = {
+ 20,
+ { 1, 2 }
+};