Hello.

Following patch skips static {c,d}tors in IPA ICF.
Patch can bootstrap and survives regtests on x86_64-linux-gnu.

Ready for trunk?
Thanks,
Martin
>From 7a5748b38e173702c88b97420d6b4d8969ae7e85 Mon Sep 17 00:00:00 2001
From: marxin <mli...@suse.cz>
Date: Mon, 21 Mar 2016 13:51:32 +0100
Subject: [PATCH] Skip static ctors/dtors in IPA ICF (PR ipa/70306)

gcc/testsuite/ChangeLog:

2016-03-21  Martin Liska  <mli...@suse.cz>

	* gcc.dg/ipa/pr70306.c: New test.

gcc/ChangeLog:

2016-03-21  Martin Liska  <mli...@suse.cz>

	* ipa-icf.c (sem_function::parse): Skip static
	constructors and destructors.
---
 gcc/ipa-icf.c                      |  5 +++++
 gcc/testsuite/gcc.dg/ipa/pr70306.c | 45 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/pr70306.c

diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index d82eb87..aa6589c 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -1697,6 +1697,11 @@ sem_function::parse (cgraph_node *node, bitmap_obstack *stack)
   if (lookup_attribute_by_prefix ("omp ", DECL_ATTRIBUTES (node->decl)) != NULL)
     return NULL;
 
+  /* PR ipa/70306.  */
+  if (DECL_STATIC_CONSTRUCTOR (node->decl)
+      || DECL_STATIC_DESTRUCTOR (node->decl))
+    return NULL;
+
   sem_function *f = new sem_function (node, 0, stack);
 
   f->init ();
diff --git a/gcc/testsuite/gcc.dg/ipa/pr70306.c b/gcc/testsuite/gcc.dg/ipa/pr70306.c
new file mode 100644
index 0000000..be18208
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr70306.c
@@ -0,0 +1,45 @@
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+/* { dg-do run } */
+
+int ctor_counter = 1;
+int dtor_counter;
+
+__attribute__((constructor))
+void A()
+{
+  ctor_counter++;
+}
+
+__attribute__((destructor))
+void B()
+{
+  if (dtor_counter == 0)
+    __builtin_abort ();
+
+  dtor_counter--;
+}
+
+__attribute__((constructor))
+static void C() {
+    ctor_counter++;
+}
+
+__attribute__((destructor))
+static void D() {
+  if (dtor_counter == 0)
+    __builtin_abort ();
+
+  dtor_counter--;
+}
+
+int main()
+{
+    if (ctor_counter != 3)
+        __builtin_abort ();
+
+    dtor_counter = 2;
+
+    return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf"  } } */
-- 
2.7.1

Reply via email to