diff mbox series

ipa: Release body of clone_of when removing its last clone (PR 100413)

Message ID ri6a6c5lg5k.fsf@suse.cz
State New
Headers show
Series ipa: Release body of clone_of when removing its last clone (PR 100413) | expand

Commit Message

Martin Jambor April 28, 2022, 9:18 a.m. UTC
Hi,

In the PR, the verifier complains that we did not manage to remove the
body of a node and it is right.  The node is kept for materialization
of two clones but after one is materialized, the other one is removed
as unneeded (as a part of delete_unreachable_blocks_update_callgraph).
The problem is that the node removal does not check for this situation
and can leave the clone_of node there with a body attached to it even
though there is no use for it any more.  This patch does checks for it
and handles the situation in a simlar way that
cgraph_node::materialize_clone does it, except that it also has to be
careful that the removed node itself does not have any clones, which
would still need the clone_of's body.  Failing to do that results in a
bootstrap failure.

Bootstrapped and tested and LTO-bootstrapped on x86_64-linux.

OK for master and GCC 11?  Or should I perhaps wait for GCC 12 to
branch and only backport to 12.2 after some time on GCC 13 master?

Thanks,

Martin


gcc/ChangeLog:

2022-04-27  Martin Jambor  <mjambor@suse.cz>

	PR ipa/100413
	* cgraph.cc (cgraph_node::remove): Release body of the node this
	is clone_of if appropriate.

gcc/testsuite/ChangeLog:

2022-04-27  Martin Jambor  <mjambor@suse.cz>

	PR ipa/100413
	* g++.dg/ipa/pr100413.C: New test.
---
 gcc/cgraph.cc                       |  6 ++-
 gcc/testsuite/g++.dg/ipa/pr100413.C | 64 +++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr100413.C

Comments

Jan Hubicka April 28, 2022, 11:40 a.m. UTC | #1
> Hi,
> 
> In the PR, the verifier complains that we did not manage to remove the
> body of a node and it is right.  The node is kept for materialization
> of two clones but after one is materialized, the other one is removed
> as unneeded (as a part of delete_unreachable_blocks_update_callgraph).
> The problem is that the node removal does not check for this situation
> and can leave the clone_of node there with a body attached to it even
> though there is no use for it any more.  This patch does checks for it
> and handles the situation in a simlar way that
> cgraph_node::materialize_clone does it, except that it also has to be
> careful that the removed node itself does not have any clones, which
> would still need the clone_of's body.  Failing to do that results in a
> bootstrap failure.
> 
> Bootstrapped and tested and LTO-bootstrapped on x86_64-linux.
> 
> OK for master and GCC 11?  Or should I perhaps wait for GCC 12 to
> branch and only backport to 12.2 after some time on GCC 13 master?
> 
> Thanks,
> 
> Martin
> 
> 
> gcc/ChangeLog:
> 
> 2022-04-27  Martin Jambor  <mjambor@suse.cz>
> 
> 	PR ipa/100413
> 	* cgraph.cc (cgraph_node::remove): Release body of the node this
> 	is clone_of if appropriate.
> 
> gcc/testsuite/ChangeLog:
> 
> 2022-04-27  Martin Jambor  <mjambor@suse.cz>
> 
> 	PR ipa/100413
> 	* g++.dg/ipa/pr100413.C: New test.

OK, thanks!
I think it should be good for gcc 12 as well.

Honza
diff mbox series

Patch

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index b923a59ab0c..7a70619412b 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -1892,7 +1892,11 @@  cgraph_node::remove (void)
   if (prev_sibling_clone)
     prev_sibling_clone->next_sibling_clone = next_sibling_clone;
   else if (clone_of)
-    clone_of->clones = next_sibling_clone;
+    {
+      clone_of->clones = next_sibling_clone;
+      if (!clone_of->analyzed && !clone_of->clones && !clones)
+	clone_of->release_body ();
+    }
   if (next_sibling_clone)
     next_sibling_clone->prev_sibling_clone = prev_sibling_clone;
   if (clones)
diff --git a/gcc/testsuite/g++.dg/ipa/pr100413.C b/gcc/testsuite/g++.dg/ipa/pr100413.C
new file mode 100644
index 00000000000..96d71e7cf35
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr100413.C
@@ -0,0 +1,64 @@ 
+/* { dg-do compile } */
+/* { dg-options "-std=c++11 -O2 -fno-guess-branch-probability -fno-inline-functions-called-once -fipa-cp-clone -fipa-pta -fnon-call-exceptions --param=ipa-cp-eval-threshold=0" } */
+
+
+template <typename> class allocator {
+public:
+  ~allocator();
+};
+template <typename> struct allocator_traits;
+template <typename _Tp> struct allocator_traits<allocator<_Tp>> {
+  using allocator_type = allocator<_Tp>;
+  template <typename _Up> using rebind_alloc = allocator<_Up>;
+  static void deallocate(allocator_type);
+};
+template <typename _ForwardIterator, typename _Tp>
+void _Destroy(_ForwardIterator, _ForwardIterator, _Tp);
+struct __alloc_traits : allocator_traits<allocator<int>> {
+  struct rebind {
+    typedef rebind_alloc<int> other;
+  };
+};
+struct _Vector_base {
+  struct _Vector_impl_data {
+    int _M_start;
+    int _M_finish;
+  };
+  struct _Vector_impl : __alloc_traits::rebind::other, _Vector_impl_data {};
+  __alloc_traits::rebind::other _M_get_Tp_allocator();
+  ~_Vector_base() { _M_deallocate(); }
+  _Vector_impl _M_impl;
+  void _M_deallocate() { __alloc_traits::deallocate(_M_impl); }
+};
+class vector : _Vector_base {
+public:
+  vector() noexcept {
+    allocator<int> __trans_tmp_1 = _M_get_Tp_allocator();
+    _Destroy(_M_impl._M_start, _M_impl._M_finish, __trans_tmp_1);
+  }
+  void size();
+};
+struct HTTPCallback {
+  virtual void OnFailure();
+};
+struct ContentCallback {
+  virtual void OnDownloadProgress();
+};
+class ClientNetworkContentSocketHandler : ContentCallback, HTTPCallback {
+  vector requested;
+  vector infos;
+  vector lastActivity;
+  void OnFailure();
+public:
+  int IDLE_TIMEOUT = 0;
+  ClientNetworkContentSocketHandler();
+  void DownloadSelectedContent();
+} _network_content_client;
+void ClientNetworkContentSocketHandler::DownloadSelectedContent() {
+  vector content;
+  content.size();
+}
+void ClientNetworkContentSocketHandler::OnFailure() {
+  DownloadSelectedContent();
+}
+ClientNetworkContentSocketHandler::ClientNetworkContentSocketHandler() {}