From e3e968e90602ffd3ccbff201b8202b0d4075b4e9 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 9 Feb 2015 11:31:14 +0100 Subject: [PATCH] IPA ICF: Fix late initialization of callgraph hooks. * g++.dg/ipa/pr64858.C: New test. * ipa-icf.c (sem_item_optimizer::register_hooks): Register hooks just if not yet registered. (ipa_icf_generate_summary): Register callgraph hooks. From-SVN: r220531 --- gcc/ChangeLog | 6 ++ gcc/ipa-icf.c | 11 ++-- gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/g++.dg/ipa/pr64858.C | 93 ++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ipa/pr64858.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bd743267c33..202a815a9a3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-02-09 Martin Liska + + * ipa-icf.c (sem_item_optimizer::register_hooks): Register hooks + just if not yet registered. + (ipa_icf_generate_summary): Register callgraph hooks. + 2015-02-08 Andrew Pinski * config/aarch64/aarch64.c (gty_dummy): Delete. diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index cf5e5d92968..d19ddc321e6 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -1562,11 +1562,13 @@ sem_item_optimizer::read_summary (void) void sem_item_optimizer::register_hooks (void) { - m_cgraph_node_hooks = symtab->add_cgraph_removal_hook - (&sem_item_optimizer::cgraph_removal_hook, this); + if (!m_cgraph_node_hooks) + m_cgraph_node_hooks = symtab->add_cgraph_removal_hook + (&sem_item_optimizer::cgraph_removal_hook, this); - m_varpool_node_hooks = symtab->add_varpool_removal_hook - (&sem_item_optimizer::varpool_removal_hook, this); + if (!m_varpool_node_hooks) + m_varpool_node_hooks = symtab->add_varpool_removal_hook + (&sem_item_optimizer::varpool_removal_hook, this); } /* Unregister callgraph and varpool hooks. */ @@ -2438,6 +2440,7 @@ ipa_icf_generate_summary (void) if (!optimizer) optimizer = new sem_item_optimizer (); + optimizer->register_hooks (); optimizer->parse_funcs_and_vars (); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bef2f1934ec..020b9be8f1d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-02-09 Martin Liska + + * g++.dg/ipa/pr64858.C: New test. + 2015-02-09 Tom de Vries * gcc.dg/uninit-19.c: Fix warning line for fpic. diff --git a/gcc/testsuite/g++.dg/ipa/pr64858.C b/gcc/testsuite/g++.dg/ipa/pr64858.C new file mode 100644 index 00000000000..c03feaf6561 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr64858.C @@ -0,0 +1,93 @@ +// { dg-do compile } +// { dg-options "-O2 -std=gnu++11" } + +template class A +{ + reference_type *m_pBody; +public: + A (const A &) { m_pBody->acquire (); } +}; +class B; +class C +{ +protected: + B *_pInterface; +}; +template class I : C +{ +public: + I (interface_type *); +}; +class B +{ +public: + virtual void acquire (); +}; +class D +{ +protected: + void acquire (); +}; +template class J : D, public Ifc1 +{ + void + acquire () + { + D::acquire (); + } +}; +class K : B +{ +}; +class L; +class F +{ + A m_pDocument; + F (A const &, int &&); +}; +class XUnoTunnel; +class XEventTarget; +template class WeakImplHelper3 : D, B +{ + void + acquire () + { + D::acquire (); + } +}; +template class G +{ +public: + void + acquire () + { + WeakImplHelper3 (); + } +}; +struct H +{ + H () + : mxAttribList (new J), mxCurrentHandler (0), mxDocHandler (0), + mxTokenHandler (0) + { + } + I > mxAttribList; + I mxCurrentHandler; + I mxDocHandler; + I mxTokenHandler; +}; +class L : public G +{ +}; +class M : public J +{ +public: + M (); +}; +template I::I (interface_type *p1) +{ + B *a = static_cast (static_cast (p1)); + _pInterface = a; + _pInterface->acquire (); +} +F::F (A const &p1, int &&) : m_pDocument (p1) { I (new M); } -- 2.30.2