re PR lto/56168 (GCC seems to disregard -fno-builtin when compiling with LTO)
authorRichard Guenther <rguenther@suse.de>
Mon, 4 Feb 2013 12:19:25 +0000 (12:19 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 4 Feb 2013 12:19:25 +0000 (12:19 +0000)
2013-02-04  Richard Guenther  <rguenther@suse.de>

PR lto/56168
* lto-symtab.c (lto_symtab_merge_decls_1): Make non-builtin
node prevail as last resort.
(lto_symtab_merge_decls): Remove guard on LTRANS here.
(lto_symtab_prevailing_decl): Builtins are their own prevailing
decl.

lto/
* lto.c (read_cgraph_and_symbols): Do not call lto_symtab_merge_decls
or lto_fixup_decls at LTRANS time.

* gcc.dg/lto/pr56168_0.c: New testcase.
* gcc.dg/lto/pr56168_1.c: Likewise.

From-SVN: r195709

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

index 12e070a119ff98eedf6c00ddf38eab265c401a2f..6d5d53d7d009ede7ea4e48c07ab4fff7162a3ae9 100644 (file)
@@ -1,3 +1,12 @@
+2013-02-04  Richard Guenther  <rguenther@suse.de>
+
+       PR lto/56168
+       * lto-symtab.c (lto_symtab_merge_decls_1): Make non-builtin
+       node prevail as last resort.
+       (lto_symtab_merge_decls): Remove guard on LTRANS here.
+       (lto_symtab_prevailing_decl): Builtins are their own prevailing
+       decl.
+
 2013-02-04  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/56113
index 546601d5ebad47244ff7391c4cd1570b346b6beb..2b182ffaedfda62c8a995f12096e963752b81189 100644 (file)
@@ -439,12 +439,12 @@ lto_symtab_merge_decls_1 (symtab_node first)
                && COMPLETE_TYPE_P (TREE_TYPE (e->symbol.decl)))
              prevailing = e;
        }
-      /* For variables prefer the builtin if one is available.  */
+      /* For variables prefer the non-builtin if one is available.  */
       else if (TREE_CODE (prevailing->symbol.decl) == FUNCTION_DECL)
        {
          for (e = first; e; e = e->symbol.next_sharing_asm_name)
            if (TREE_CODE (e->symbol.decl) == FUNCTION_DECL
-               && DECL_BUILT_IN (e->symbol.decl))
+               && !DECL_BUILT_IN (e->symbol.decl))
              {
                prevailing = e;
                break;
@@ -507,12 +507,6 @@ lto_symtab_merge_decls (void)
 {
   symtab_node node;
 
-  /* In ltrans mode we read merged cgraph, we do not really need to care
-     about resolving symbols again, we only need to replace duplicated declarations
-     read from the callgraph and from function sections.  */
-  if (flag_ltrans)
-    return;
-
   /* Populate assembler name hash.   */
   symtab_initialize_asm_name_hash ();
 
@@ -598,6 +592,11 @@ lto_symtab_prevailing_decl (tree decl)
   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT (decl))
     return decl;
 
+  /* Likewise builtins are their own prevailing decl.  This preserves
+     non-builtin vs. builtin uses from compile-time.  */
+  if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
+    return decl;
+
   /* Ensure DECL_ASSEMBLER_NAME will not set assembler name.  */
   gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
 
index 503ff80460b9b836d88893718ffcefc7b928fcea..2da6ae1d2059eb38446271cf5b8efd2919c3abd6 100644 (file)
@@ -1,3 +1,9 @@
+2013-02-04  Richard Guenther  <rguenther@suse.de>
+
+       PR lto/56168
+       * lto.c (read_cgraph_and_symbols): Do not call lto_symtab_merge_decls
+       or lto_fixup_decls at LTRANS time.
+
 2013-01-09  Jan Hubicka  <jh@suse.cz>
 
        PR lto/45375
index 9583b9109b21c29bb581a2dcab9eb5bc4c93df42..6edf87a45b0cb6bda988110826db93adcf826a5d 100644 (file)
@@ -3033,16 +3033,22 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
     fprintf (stderr, "Merging declarations\n");
 
   timevar_push (TV_IPA_LTO_DECL_MERGE);
-  /* Merge global decls.  */
-  lto_symtab_merge_decls ();
+  /* Merge global decls.  In ltrans mode we read merged cgraph, we do not
+     need to care about resolving symbols again, we only need to replace
+     duplicated declarations read from the callgraph and from function
+     sections.  */
+  if (!flag_ltrans)
+    {
+      lto_symtab_merge_decls ();
 
-  /* If there were errors during symbol merging bail out, we have no
-     good way to recover here.  */
-  if (seen_error ())
-    fatal_error ("errors during merging of translation units");
+      /* If there were errors during symbol merging bail out, we have no
+        good way to recover here.  */
+      if (seen_error ())
+       fatal_error ("errors during merging of translation units");
 
-  /* Fixup all decls.  */
-  lto_fixup_decls (all_file_decl_data);
+      /* Fixup all decls.  */
+      lto_fixup_decls (all_file_decl_data);
+    }
   htab_delete (tree_with_vars);
   tree_with_vars = NULL;
   ggc_collect ();
index c7657437324aef582ea50358dcd63e065a31aabd..f4eb094c644f1a162cad275d4e22f28235293be9 100644 (file)
@@ -1,3 +1,9 @@
+2013-02-04  Richard Guenther  <rguenther@suse.de>
+
+       PR lto/56168
+       * gcc.dg/lto/pr56168_0.c: New testcase.
+       * gcc.dg/lto/pr56168_1.c: Likewise.
+
 2013-02-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/50627
diff --git a/gcc/testsuite/gcc.dg/lto/pr56168_0.c b/gcc/testsuite/gcc.dg/lto/pr56168_0.c
new file mode 100644 (file)
index 0000000..13f768e
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-lto-do run } */
+/* { dg-lto-options { { -flto -O -ffast-math -fno-builtin } } } */
+
+extern double pow(double, double);
+extern void abort (void);
+volatile double x = 1.0;
+int main(int argc, char **argv)
+{
+  double d1 = x;
+  double d2 = pow(d1, 1.0 / 3.0);
+  double d3 = d1 * d1;
+  if (d3 != 1.0 || d2 != 0.0)
+    abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr56168_1.c b/gcc/testsuite/gcc.dg/lto/pr56168_1.c
new file mode 100644 (file)
index 0000000..560d0bd
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-options "-fno-lto" } */
+
+double __attribute__((noinline,noclone))
+pow (double x, double y) { return 0.0; }