public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators.
@ 2019-08-01 13:12 Martin Liška
  2019-08-01 16:16 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Liška @ 2019-08-01 13:12 UTC (permalink / raw)
  To: gcc-patches; +Cc: Marc Glisse, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 826 bytes --]

Hi.

As discussed with Marc, I'm suggesting to mark user-provided
delete operators with DECL_SET_IS_OPERATOR_DELETE in order to allow
possible DCE for it. I've checked that clang can also optimize that
situation out.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

gcc/cp/ChangeLog:

2019-07-30  Martin Liska  <mliska@suse.cz>

	* decl.c (grok_op_properties):
	Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators.

gcc/testsuite/ChangeLog:

2019-07-30  Martin Liska  <mliska@suse.cz>

	* g++.dg/cpp1y/new2.C: New test.
---
 gcc/cp/decl.c                     |  5 +++-
 gcc/testsuite/g++.dg/cpp1y/new2.C | 39 +++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/new2.C



[-- Attachment #2: 0001-Mark-DECL_SET_IS_OPERATOR_DELETE-for-user-provided-d.patch --]
[-- Type: text/x-patch, Size: 1439 bytes --]

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 9fa090c8767..bc438d23db3 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13670,7 +13670,10 @@ grok_op_properties (tree decl, bool complain)
 	}
 
       if (op_flags & OVL_OP_FLAG_DELETE)
-	coerce_delete_type (decl, loc);
+	{
+	  DECL_SET_IS_OPERATOR_DELETE (decl, true);
+	  coerce_delete_type (decl, loc);
+	}
       else
 	{
 	  DECL_SET_IS_OPERATOR_NEW (decl, true);
diff --git a/gcc/testsuite/g++.dg/cpp1y/new2.C b/gcc/testsuite/g++.dg/cpp1y/new2.C
new file mode 100644
index 00000000000..926e7960528
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/new2.C
@@ -0,0 +1,39 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -std=c++17 -fdump-tree-cddce-details" } */
+
+#include <cstdio>
+#include <cstdlib>
+#include <new>
+
+void* operator new(std::size_t sz)
+{
+  std::printf("global op new called, size = %zu\n", sz);
+  void *ptr = std::malloc(sz);
+  if (ptr)
+    return ptr;
+  else
+    throw std::bad_alloc{};
+}
+
+void operator delete(void* ptr) noexcept
+{
+  std::puts("global op delete called");
+  std::free(ptr);
+}
+
+void
+new_primitive_load() {
+  int *x = new int;
+  int tmp = *x;
+  delete x;
+}
+
+void
+new_array_load() {
+  int *x = new int[10];
+  int tmp = x[4];
+  delete [] x;
+}
+
+/* { dg-final { scan-tree-dump-times "Deleting : _\\d+ = operator new" 2 "cddce1"} } */
+/* { dg-final { scan-tree-dump-times "Deleting : operator delete" 2 "cddce1"} } */


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators.
  2019-08-01 13:12 [PATCH] Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators Martin Liška
@ 2019-08-01 16:16 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2019-08-01 16:16 UTC (permalink / raw)
  To: Martin Liška, gcc-patches; +Cc: Marc Glisse

OK.

On 8/1/19 9:12 AM, Martin Liška wrote:
> Hi.
> 
> As discussed with Marc, I'm suggesting to mark user-provided
> delete operators with DECL_SET_IS_OPERATOR_DELETE in order to allow
> possible DCE for it. I've checked that clang can also optimize that
> situation out.
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Ready to be installed?
> Thanks,
> Martin
> 
> gcc/cp/ChangeLog:
> 
> 2019-07-30  Martin Liska  <mliska@suse.cz>
> 
> 	* decl.c (grok_op_properties):
> 	Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators.
> 
> gcc/testsuite/ChangeLog:
> 
> 2019-07-30  Martin Liska  <mliska@suse.cz>
> 
> 	* g++.dg/cpp1y/new2.C: New test.
> ---
>   gcc/cp/decl.c                     |  5 +++-
>   gcc/testsuite/g++.dg/cpp1y/new2.C | 39 +++++++++++++++++++++++++++++++
>   2 files changed, 43 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp1y/new2.C
> 
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-01 16:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 13:12 [PATCH] Mark DECL_SET_IS_OPERATOR_DELETE for user-provided delete operators Martin Liška
2019-08-01 16:16 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).