From fcb6fced16389962ebf2cebe737d534994a80fb6 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 4 Jan 2018 09:54:17 +0100 Subject: [PATCH] Be careful about comdat boundary in ICF (PR ipa/82352). 2018-01-04 Martin Liska PR ipa/82352 * ipa-icf.c (sem_function::merge): Do not cross comdat boundary. 2018-01-04 Martin Liska PR ipa/82352 * g++.dg/ipa/pr82352.C: New test. From-SVN: r256226 --- gcc/ChangeLog | 5 ++ gcc/ipa-icf.c | 11 ++++ gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/g++.dg/ipa/pr82352.C | 93 ++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ipa/pr82352.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 57c85613e2d..007e2d5999f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-01-04 Martin Liska + + PR ipa/82352 + * ipa-icf.c (sem_function::merge): Do not cross comdat boundary. + 2018-01-04 Jakub Jelinek * gimple-ssa-sprintf.c (parse_directive): Cast second dir.len to uhwi. diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index edb0b7896cd..b9f2bf30744 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -1113,6 +1113,17 @@ sem_function::merge (sem_item *alias_item) return false; } + if (!original->in_same_comdat_group_p (alias) + || original->comdat_local_p ()) + { + if (dump_file) + fprintf (dump_file, + "Not unifying; alias nor wrapper cannot be created; " + "across comdat group boundary\n\n"); + + return false; + } + /* See if original is in a section that can be discarded if the main symbol is not used. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 726869267f4..e7de3ae4c9d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-04 Martin Liska + + PR ipa/82352 + * g++.dg/ipa/pr82352.C: New test. + 2018-01-04 Jakub Jelinek * gcc.dg/vect-opt-info-1.c: Moved to ... diff --git a/gcc/testsuite/g++.dg/ipa/pr82352.C b/gcc/testsuite/g++.dg/ipa/pr82352.C new file mode 100644 index 00000000000..c044345a486 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr82352.C @@ -0,0 +1,93 @@ +// PR ipa/82352 +// { dg-do compile } +// { dg-options "-O2" } + +typedef long unsigned int size_t; + +class A +{ +public : + typedef enum { Zero = 0, One = 1 } tA; + A(tA a) { m_a = a; } + +private : + tA m_a; +}; + +class B +{ +public : + void *operator new(size_t t) { return (void*)(42); }; +}; + +class C +{ +public: + virtual void ffff () = 0; +}; + +class D +{ + public : + virtual void g() = 0; + virtual void h() = 0; +}; + +template class IIII: public T, public D +{ +public: + void ffff() + { + if (!m_i2) throw A(A::One); + }; + + void h() + { + if (m_i2) throw A(A::Zero); + } + +protected: + virtual void g() + { + if (m_i1 !=0) throw A(A::Zero); + }; + +private : + int m_i1; + void *m_i2; +}; + +class E +{ +private: + size_t m_e; + static const size_t Max; + +public: + E& i(size_t a, size_t b, size_t c) + { + if ((a > Max) || (c > Max)) throw A(A::Zero ); + if (a + b > m_e) throw A(A::One ); + return (*this); + } + + inline E& j(const E &s) + { + return i(0,0,s.m_e); + } +}; + +class F : public C { }; +class G : public C { }; +class HHHH : public B, public F, public G { }; + +void k() +{ + new IIII(); +} + +void l() +{ + E e1, e2; + e1.j(e2); +} -- 2.30.2