re PR lto/69866 (lto1: internal compiler error: in add_symbol_to_partition_1, at...
authorJan Hubicka <hubicka@gcc.gnu.org>
Thu, 15 Jun 2017 18:42:10 +0000 (18:42 +0000)
committerJan Hubicka <hubicka@gcc.gnu.org>
Thu, 15 Jun 2017 18:42:10 +0000 (18:42 +0000)
PR lto/69866
* lto-symtab.c (lto_symtab_merge_symbols): Drop useless definitions
that resolved externally.

* gcc.dg/lto/pr69866_0.c: New test.
* gcc.dg/lto/pr69866_1.c: Likewise.

From-SVN: r249224

gcc/lto/ChangeLog
gcc/lto/lto-partition.c
gcc/lto/lto-symtab.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/lto/pr69866_0.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/lto/pr69866_1.c [new file with mode: 0644]

index e63f2037191a049d0f24b30f4d2f32a7935ed4a7..58601c54b46d92e5240c2ac99a2215bae47a9aea 100644 (file)
@@ -1,3 +1,10 @@
+2017-06-15  Jan Hubicka  <hubicka@ucw.cz>
+           Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+       PR lto/69866
+       * lto-symtab.c (lto_symtab_merge_symbols): Drop useless definitions
+       that resolved externally.
+
 2017-05-23  Jan Hubicka  <hubicka@ucw.cz>
 
        * lto.c (do_whole_program_analysis): Replace inline_free_summary
index 3600ab23bd9157aad76751912306abd498acae92..620deac090b7e718f05d3f37e6ef68e759de0008 100644 (file)
@@ -132,7 +132,7 @@ add_symbol_to_partition_1 (ltrans_partition part, symtab_node *node)
 
   /* Be sure that we never try to duplicate partitioned symbol
      or add external symbol.  */
-  gcc_assert (c != SYMBOL_EXTERNAL
+  gcc_assert ((c != SYMBOL_EXTERNAL || node->alias)
              && (c == SYMBOL_DUPLICATE || !symbol_partitioned_p (node)));
 
   part->symbols++;
index 9fd94861c6d456efb2056b2eae7ca91826dd736b..019677eaf95e906d5dfc15f609f70fadfa1b3856 100644 (file)
@@ -952,6 +952,42 @@ lto_symtab_merge_symbols (void)
              if (tgt)
                node->resolve_alias (tgt, true);
            }
+         /* If the symbol was preempted outside IR, see if we want to get rid
+            of the definition.  */
+         if (node->analyzed
+             && !DECL_EXTERNAL (node->decl)
+             && (node->resolution == LDPR_PREEMPTED_REG
+                 || node->resolution == LDPR_RESOLVED_IR
+                 || node->resolution == LDPR_RESOLVED_EXEC
+                 || node->resolution == LDPR_RESOLVED_DYN))
+           {
+             DECL_EXTERNAL (node->decl) = 1;
+             /* If alias to local symbol was preempted by external definition,
+                we know it is not pointing to the local symbol.  Remove it.  */
+             if (node->alias
+                 && !node->weakref
+                 && !node->transparent_alias
+                 && node->get_alias_target ()->binds_to_current_def_p ())
+               {
+                 node->alias = false;
+                 node->remove_all_references ();
+                 node->definition = false;
+                 node->analyzed = false;
+                 node->cpp_implicit_alias = false;
+               }
+             else if (!node->alias
+                      && node->definition
+                      && node->get_availability () <= AVAIL_INTERPOSABLE)
+               {
+                 if ((cnode = dyn_cast <cgraph_node *> (node)) != NULL)
+                   cnode->reset ();
+                 else
+                   {
+                     node->analyzed = node->definition = false;
+                     node->remove_all_references ();
+                   }
+               }
+           }
 
          if (!(cnode = dyn_cast <cgraph_node *> (node))
              || !cnode->clone_of
index 3677d15c453efb77a59e74ba3b952495a6e41744..a79f533992ef0703cc3c506ac65b311bc9a0ec51 100644 (file)
@@ -1,3 +1,9 @@
+2017-06-15  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+       PR lto/69866
+       * gcc.dg/lto/pr69866_0.c: New test.
+       * gcc.dg/lto/pr69866_1.c: Likewise.
+
 2017-06-15  Jozef Lawrynowicz  <jozef.l@somniumtech.com>
 
        PR target/78818
diff --git a/gcc/testsuite/gcc.dg/lto/pr69866_0.c b/gcc/testsuite/gcc.dg/lto/pr69866_0.c
new file mode 100644 (file)
index 0000000..f49ef8d
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-lto-do link } */
+
+int _umh(int i)
+{
+  return i+1;
+}
+
+int weaks(int i) __attribute__((weak, alias("_umh")));
+
+int main()
+{
+  return weaks(10);
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr69866_1.c b/gcc/testsuite/gcc.dg/lto/pr69866_1.c
new file mode 100644 (file)
index 0000000..3a14f85
--- /dev/null
@@ -0,0 +1,6 @@
+/* { dg-options { -fno-lto } } */
+
+int weaks(int i)
+{
+  return i+1;
+}