ipa-icf.c (sem_item_optimizer::merge): Don't pick 'main' as the source function.

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
This commit is contained in:
Nathan Sidwell 2015-12-17 21:29:30 +00:00 committed by Nathan Sidwell
parent 94c40e19af
commit aa3987819a
4 changed files with 45 additions and 3 deletions

View 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.

View 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",

View 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.

View file

@ -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" } } */