+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.
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",
+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.
--- /dev/null
+/* { 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" } } */