Be more carefull about DECL merging in LTO (PR lto/85248).
authorMartin Liska <marxin@gcc.gnu.org>
Tue, 10 Apr 2018 07:24:59 +0000 (07:24 +0000)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 10 Apr 2018 07:24:59 +0000 (07:24 +0000)
2018-04-10  Richard Biener  <rguenther@suse.de>
    Martin Liska  <mliska@suse.cz>

PR lto/85248
* lto-symtab.c (lto_symtab_merge_p): Handle noreturn attribute.
2018-04-10  Jakub Jelinek  <jakub@redhat.com>

PR lto/85248
* gcc.dg/lto/pr85248_0.c: New test.
* gcc.dg/lto/pr85248_1.c: New test.

From-SVN: r259265

gcc/lto/ChangeLog
gcc/lto/lto-symtab.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/lto/pr85248_0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/lto/pr85248_1.c [new file with mode: 0644]

index 55013a8..2c9c7bf 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-10  Richard Biener  <rguenther@suse.de>
+           Martin Liska  <mliska@suse.cz>
+
+       PR lto/85248
+       * lto-symtab.c (lto_symtab_merge_p): Handle noreturn attribute.
+
 2018-02-08  Jan Hubicka  <hubicka@ucw.cz>
 
        * lto-partition.c (lto_balanced_map): Watch overflow.
index 4f186ae..473c0d0 100644 (file)
@@ -572,6 +572,9 @@ lto_symtab_merge_p (tree prevailing, tree decl)
          return false;
        }
     }
+
+  /* FIXME: after MPX is removed, use flags_from_decl_or_type
+     function instead.  PR lto/85248.  */
   if (DECL_ATTRIBUTES (prevailing) != DECL_ATTRIBUTES (decl))
     {
       tree prev_attr = lookup_attribute ("error", DECL_ATTRIBUTES (prevailing));
@@ -599,6 +602,19 @@ lto_symtab_merge_p (tree prevailing, tree decl)
                     "warning attribute mismatch\n");
          return false;
        }
+
+      prev_attr = lookup_attribute ("noreturn", DECL_ATTRIBUTES (prevailing));
+      attr = lookup_attribute ("noreturn", DECL_ATTRIBUTES (decl));
+      if ((prev_attr == NULL) != (attr == NULL)
+         || (prev_attr
+             && TREE_VALUE (TREE_VALUE (prev_attr))
+                != TREE_VALUE (TREE_VALUE (attr))))
+       {
+          if (symtab->dump_file)
+           fprintf (symtab->dump_file, "Not merging decls; "
+                    "noreturn attribute mismatch\n");
+         return false;
+       }
     }
   return true;
 }
index 85392f6..de04c8b 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR lto/85248
+       * gcc.dg/lto/pr85248_0.c: New test.
+       * gcc.dg/lto/pr85248_1.c: New test.
+
 2018-04-09  Jan Hubicka  <jh@suse.cz>
 
        PR lto/85078
diff --git a/gcc/testsuite/gcc.dg/lto/pr85248_0.c b/gcc/testsuite/gcc.dg/lto/pr85248_0.c
new file mode 100644 (file)
index 0000000..df61ac9
--- /dev/null
@@ -0,0 +1,45 @@
+/* PR lto/85248 */
+/* { dg-lto-do run } */
+/* { dg-lto-options { { -flto -O2 } } } */
+
+extern void test_alias (int s, int e) __asm__ (__USER_LABEL_PREFIX__ "test");
+extern void test_noreturn (int s, int e) __asm__ (__USER_LABEL_PREFIX__ "test")
+  __attribute__ ((__noreturn__));
+
+extern inline __attribute__ ((__always_inline__, __gnu_inline__)) void
+test (int s, int e)
+{
+  if (__builtin_constant_p (s) && s != 0)
+    test_noreturn (s, e);
+  else
+    test_alias (s, e);
+}
+
+int
+foo (void)
+{
+  static volatile int a;
+  return a;
+}
+
+static void
+bar (void)
+{
+  test (0, 1);
+  __builtin_exit (0);
+}
+
+static void
+baz ()
+{
+  test (1, 0);
+}
+
+int
+main ()
+{
+  if (foo ())
+    baz ();
+  bar ();
+  __builtin_abort ();
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr85248_1.c b/gcc/testsuite/gcc.dg/lto/pr85248_1.c
new file mode 100644 (file)
index 0000000..418c069
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-options "-fno-lto" } */
+
+__attribute__((__noipa__)) void
+test (int s, int e)
+{
+  asm volatile ("" : "+g" (s), "+g" (e) : : "memory");
+  if (s)
+    __builtin_abort ();
+}