re PR lto/89358 (Combining -std=c++14 and -std=c++17 objects gives ODR warnings)
authorJan Hubicka <hubicka@ucw.cz>
Sun, 14 Apr 2019 20:56:45 +0000 (22:56 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Sun, 14 Apr 2019 20:56:45 +0000 (20:56 +0000)
PR lto/89358
* g++.dg/lto/pr89358_0.C: New testcase.
* g++.dg/lto/pr89358_1.C: New testcase.
* ipa-devirt.c (skip_in_fields_list_p): New.
(odr_types_equivalent_p): Use it.

From-SVN: r270355

gcc/ChangeLog
gcc/ipa-devirt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lto/pr89358_0.C [new file with mode: 0644]
gcc/testsuite/g++.dg/lto/pr89358_1.C [new file with mode: 0644]

index 6a394b8ce0fff06e48067d7789f60df4d94c2032..a41417bbcbd58a3de8591414805c89f45dccd422 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-14  Jan Hubicka  <hubicka@ucw.cz>
+
+       PR lto/89358
+       * ipa-devirt.c (skip_in_fields_list_p): New.
+       (odr_types_equivalent_p): Use it.
+
 2019-04-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/89093
index 61e4efc83d413c4b01d739cd11d2b2c5309213c6..defa2ed3a5dc95bbd8411be1d04b8037bc9f9212 100644 (file)
@@ -1282,6 +1282,24 @@ warn_types_mismatch (tree t1, tree t2, location_t loc1, location_t loc2)
     inform (loc_t2, "the incompatible type is defined here");
 }
 
+/* Return true if T should be ignored in TYPE_FIELDS for ODR comparsion.  */
+
+static bool
+skip_in_fields_list_p (tree t)
+{
+  if (TREE_CODE (t) != FIELD_DECL)
+    return true;
+  /* C++ FE introduces zero sized fields depending on -std setting, see
+     PR89358.  */
+  if (DECL_SIZE (t)
+      && integer_zerop (DECL_SIZE (t))
+      && DECL_ARTIFICIAL (t)
+      && DECL_IGNORED_P (t)
+      && !DECL_NAME (t))
+    return true;
+  return false;
+}
+
 /* Compare T1 and T2, report ODR violations if WARN is true and set
    WARNED to true if anything is reported.  Return true if types match.
    If true is returned, the types are also compatible in the sense of
@@ -1548,9 +1566,9 @@ odr_types_equivalent_p (tree t1, tree t2, bool warn, bool *warned,
                 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
              {
                /* Skip non-fields.  */
-               while (f1 && TREE_CODE (f1) != FIELD_DECL)
+               while (f1 && skip_in_fields_list_p (f1))
                  f1 = TREE_CHAIN (f1);
-               while (f2 && TREE_CODE (f2) != FIELD_DECL)
+               while (f2 && skip_in_fields_list_p (f2))
                  f2 = TREE_CHAIN (f2);
                if (!f1 || !f2)
                  break;
index 0c4ae15ae9b6adb0a8e0d609a4babbb985782e48..8055780aaa18810ca329d433b87547ece0bb31db 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-14  Jan Hubicka  <hubicka@ucw.cz>
+
+       PR lto/89358
+       * g++.dg/lto/pr89358_0.C: New testcase.
+       * g++.dg/lto/pr89358_1.C: New testcase.
+
 2019-04-14  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/85448
diff --git a/gcc/testsuite/g++.dg/lto/pr89358_0.C b/gcc/testsuite/g++.dg/lto/pr89358_0.C
new file mode 100644 (file)
index 0000000..aebd212
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do link } */
+/* { dg-options "-std=c++17"  } */
+#include <map>
+
+extern void test();
+
+int main()
+{
+        std::map<int, int> m;
+        test();
+}
diff --git a/gcc/testsuite/g++.dg/lto/pr89358_1.C b/gcc/testsuite/g++.dg/lto/pr89358_1.C
new file mode 100644 (file)
index 0000000..68b80a3
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-options "-std=c++14"  } */
+#include <map>
+
+void test()
+{
+        std::map<int, int> m;
+}