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

Backport from mainline
2018-01-30  Jan Hubicka  <hubicka@ucw.cz>

PR lto/83954
* lto-symtab.c (warn_type_compatibility_p): Silence false positive
for type match warning on arrays of pointers.
2018-03-07  Martin Liska  <mliska@suse.cz>

Backport from mainline
2018-01-30  Jan Hubicka  <hubicka@ucw.cz>

PR lto/83954
* gcc.dg/lto/pr83954.h: New testcase.
* gcc.dg/lto/pr83954_0.c: New testcase.
* gcc.dg/lto/pr83954_1.c: New testcase.

From-SVN: r258319

gcc/lto/ChangeLog
gcc/lto/lto-symtab.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/lto/pr83954.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/lto/pr83954_0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/lto/pr83954_1.c [new file with mode: 0644]

index 940e6d2662ece61457dbf9e8dacb2b4485ddcdfe..b2cbe74fa6b40861981c48cf12930cb85bc981ba 100644 (file)
@@ -1,3 +1,12 @@
+2018-03-07  Martin Liska  <mliska@suse.cz>
+
+       Backport from mainline
+       2018-01-30  Jan Hubicka  <hubicka@ucw.cz>
+
+       PR lto/83954
+       * lto-symtab.c (warn_type_compatibility_p): Silence false positive
+       for type match warning on arrays of pointers.
+
 2018-03-07  Martin Liska  <mliska@suse.cz>
 
        Backport from mainline
index 94b919b53e6ed18583e4212f71aac3637b933230..395dca479291a01607af144bdfb3629b3714ebc1 100644 (file)
@@ -280,11 +280,22 @@ warn_type_compatibility_p (tree prevailing_type, tree type,
       alias_set_type set1 = get_alias_set (type);
       alias_set_type set2 = get_alias_set (prevailing_type);
 
-      if (set1 && set2 && set1 != set2 
-          && (!POINTER_TYPE_P (type) || !POINTER_TYPE_P (prevailing_type)
+      if (set1 && set2 && set1 != set2)
+       {
+          tree t1 = type, t2 = prevailing_type;
+
+         /* Alias sets of arrays are the same as alias sets of the inner
+            types.  */
+         while (TREE_CODE (t1) == ARRAY_TYPE && TREE_CODE (t2) == ARRAY_TYPE)
+           {
+             t1 = TREE_TYPE (t1);
+             t2 = TREE_TYPE (t2);
+           }
+          if ((!POINTER_TYPE_P (t1) || !POINTER_TYPE_P (t2))
              || (set1 != TYPE_ALIAS_SET (ptr_type_node)
-                 && set2 != TYPE_ALIAS_SET (ptr_type_node))))
-        lev |= 5;
+                 && set2 != TYPE_ALIAS_SET (ptr_type_node)))
+             lev |= 5;
+       }
     }
 
   return lev;
index 705b89d20d5e7b45572e220f1c10b41ea56727a2..e19c92e954876ef888fbbb19218b46d12c89c31b 100644 (file)
@@ -1,3 +1,13 @@
+2018-03-07  Martin Liska  <mliska@suse.cz>
+
+       Backport from mainline
+       2018-01-30  Jan Hubicka  <hubicka@ucw.cz>
+
+       PR lto/83954
+       * gcc.dg/lto/pr83954.h: New testcase.
+       * gcc.dg/lto/pr83954_0.c: New testcase.
+       * gcc.dg/lto/pr83954_1.c: New testcase.
+
 2018-03-06  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/56667
diff --git a/gcc/testsuite/gcc.dg/lto/pr83954.h b/gcc/testsuite/gcc.dg/lto/pr83954.h
new file mode 100644 (file)
index 0000000..e015540
--- /dev/null
@@ -0,0 +1,3 @@
+struct foo;
+extern struct foo *FOO_PTR_ARR[1];
+
diff --git a/gcc/testsuite/gcc.dg/lto/pr83954_0.c b/gcc/testsuite/gcc.dg/lto/pr83954_0.c
new file mode 100644 (file)
index 0000000..065a31d
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-lto-do link } */
+#include "pr83954.h"
+
+int main() {
+  // just to prevent symbol removal
+  FOO_PTR_ARR[1] = 0;
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr83954_1.c b/gcc/testsuite/gcc.dg/lto/pr83954_1.c
new file mode 100644 (file)
index 0000000..61b40fc
--- /dev/null
@@ -0,0 +1,7 @@
+#include "pr83954.h"
+
+struct foo {
+ int x;
+};
+struct foo *FOO_PTR_ARR[1] = { 0 };
+