From ab32c06873590a49a00be0b4089b9584b82dbbb0 Mon Sep 17 00:00:00 2001 From: marxin Date: Thu, 18 Dec 2014 12:02:22 +0000 Subject: [PATCH] Fix for PR ipa/64146 PR ipa/64146 * ipa-icf.c (sem_function::merge): Check for decl_binds_to_current_def_p is newly added to merge operation. * g++.dg/ipa/pr64146.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@218860 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/ipa-icf.c | 8 ++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/ipa/pr64146.C | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ipa/pr64146.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3757021fff5..24a252ac68f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-12-18 Martin Liska + + PR ipa/64146 + * ipa-icf.c (sem_function::merge): Check for + decl_binds_to_current_def_p is newly added to merge operation. + 2014-12-18 Bin Cheng PR tree-optimization/62178 diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index b1932008f65..91878b2d3fc 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -101,6 +101,7 @@ along with GCC; see the file COPYING3. If not see #include #include "ipa-icf-gimple.h" #include "ipa-icf.h" +#include "varasm.h" using namespace ipa_icf_gimple; @@ -624,6 +625,13 @@ sem_function::merge (sem_item *alias_item) return false; } + if (!decl_binds_to_current_def_p (alias->decl)) + { + if (dump_file) + fprintf (dump_file, "Declaration does not bind to currect definition.\n\n"); + return false; + } + if (redirect_callers) { /* If alias is non-overwritable then diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index aa7e8c7409d..025dfcead10 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-12-18 Martin Liska + + * g++.dg/ipa/pr64146.C: New test. + 2014-12-18 Rainer Orth * lib/mpx-dg.exp (check_effective_target_mpx): Change into link test. diff --git a/gcc/testsuite/g++.dg/ipa/pr64146.C b/gcc/testsuite/g++.dg/ipa/pr64146.C new file mode 100644 index 00000000000..8a2b947a215 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr64146.C @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-require-alias "" } */ +/* { dg-options "-fpic -fdump-ipa-icf-details -fipa-icf" } */ + +extern "C" const char* +foo() +{ + return "original"; +} + +const char* +test_foo() +{ + return foo(); +} + +extern "C" const char* +bar() +{ + return "original"; +} + +const char* +test_bar() +{ + return bar(); +} + +int main (int argc, char **argv) +{ + test_foo (); + test_bar (); + + return 0; +} + +/* { dg-final { scan-ipa-dump-times "Declaration does not bind to currect definition." 2 "icf" } } */ +/* { dg-final { scan-ipa-dump "Equal symbols: 2" "icf" } } */ -- 2.11.4.GIT