ipa-icf.c (sem_item_optimizer::merge): Don't pick 'main' as the source function.
authorNathan Sidwell <nathan@acm.org>
Thu, 17 Dec 2015 21:29:30 +0000 (21:29 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 17 Dec 2015 21:29:30 +0000 (21:29 +0000)
gcc/
* ipa-icf.c (sem_item_optimizer::merge): Don't pick 'main' as the
source function.

gcc/testsuite/
* gcc.dg/ipa/ipa-icf-merge-1.c: New.

From-SVN: r231787

gcc/ChangeLog
gcc/ipa-icf.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ipa/ipa-icf-merge-1.c [new file with mode: 0644]

index 82a836d177c6610b8d5e67f92c94ba91a3fb9e01..a1f71bdfa865413714d8688c404859dfb809a546 100644 (file)
@@ -1,3 +1,8 @@
+2015-12-17  Nathan Sidwell  <nathan@acm.org>
+
+       * ipa-icf.c (sem_item_optimizer::merge): Don't pick 'main' as the
+       source function.
+
 2015-12-17  Sebastian Pop  <s.pop@samsung.com>
 
        * Makefile.in: Replace ISL with isl.
index 889a07de697a47fb61823b5d760ba0ddb72a4cef..4538677c860169e2ec9a73e63d340475acadd65f 100644 (file)
@@ -3398,14 +3398,20 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count)
        if (c->members.length () == 1)
          continue;
 
-       gcc_assert (c->members.length ());
-
        sem_item *source = c->members[0];
 
-       for (unsigned int j = 1; j < c->members.length (); j++)
+       if (MAIN_NAME_P (DECL_NAME (source->decl)))
+         /* If merge via wrappers, picking main as the target can be
+            problematic.  */
+         source = c->members[1];
+
+       for (unsigned int j = 0; j < c->members.length (); j++)
          {
            sem_item *alias = c->members[j];
 
+           if (alias == source)
+             continue;
+
            if (dump_file)
              {
                fprintf (dump_file, "Semantic equality hit:%s->%s\n",
index 2cbde3b85527813172873d1ad12c7f402fdc6cc7..d5ae29900974d00a8464851130cbe3991081ee3d 100644 (file)
@@ -1,3 +1,7 @@
+2015-12-17  Nathan Sidwell  <nathan@acm.org>
+
+       * gcc.dg/ipa/ipa-icf-merge-1.c: New.
+       
 2015-12-17  David Malcolm  <dmalcolm@redhat.com>
 
        * gcc.dg/diagnostic-range-bad-return.c: New test case.
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-icf-merge-1.c b/gcc/testsuite/gcc.dg/ipa/ipa-icf-merge-1.c
new file mode 100644 (file)
index 0000000..06958a4
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O2 -fdump-ipa-icf" } */
+
+/* Picking 'main' as a candiate target for equivalent functios is not a
+   good idea.  */
+
+int baz (int);
+
+int foo ()
+{
+  return baz (baz (0));
+}
+
+
+int main ()
+{
+  return baz (baz (0));
+}
+
+/* Notice the two functions are the same.  */
+/* { dg-final { scan-ipa-dump "Semantic equality hit:foo->main" "icf" } } */
+
+/* Make sure we don't tail call main.  */
+/* { dg-final { scan-ipa-dump-not "= main \\(\\);" "icf" } } */
+
+/* Make sure we tail call foo.  */
+/* { dg-final { scan-ipa-dump "= foo \\(\\);" "icf" } } */