public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: "hubicka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
Cc: gcc-bugs@gcc.gnu.org
Subject: Re: [Bug libstdc++/109442] Dead local copy of std::vector not removed from function
Date: Tue, 14 May 2024 15:47:50 +0200	[thread overview]
Message-ID: <ZkNrhtt7BLzI7-BJ@kam.mff.cuni.cz> (raw)
In-Reply-To: <bug-109442-4-bNLdkV8s8m@http.gcc.gnu.org/bugzilla/>

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

This patch attempts to add __builtin_operator_new/delete. So far they
are not optimized, which will need to be done by extra flag of BUILT_IN_
code.  also the decl.cc code can be refactored to be less of cut&paste
and I guess has_builtin hack to return proper value needs to be moved
to C++ FE.

However the immediate problem I run into is that libstdc++ testuiste
fails due to lack of std::nothrow overrides.  I wonder how to get that
working?

[-- Attachment #2: newdelete --]
[-- Type: text/plain, Size: 5119 bytes --]

diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc
index ff5ce2bf729..602b097059c 100644
--- a/gcc/c-family/c-lex.cc
+++ b/gcc/c-family/c-lex.cc
@@ -533,6 +533,10 @@ c_common_has_builtin (cpp_reader *pfile)
   if (!name)
     return 0;
 
+  if (!strcmp (name, "__builtin_operator_new")
+      || !strcmp (name, "__builtin_operator_delete"))
+    return 201802L;
+
   return names_builtin_p (name);
 }
 
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 3fc8835154d..90b100ca3dc 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -59,6 +59,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "omp-general.h"
 #include "omp-offload.h"  /* For offload_vars.  */
 #include "opts.h"
+#include "print-tree.h"
 #include "langhooks-def.h"  /* For lhd_simulate_record_decl  */
 
 /* Possible cases of bad specifiers type used by bad_specifiers. */
@@ -5048,13 +5049,27 @@ cxx_init_decl_processing (void)
     DECL_IS_MALLOC (opnew) = 1;
     DECL_SET_IS_OPERATOR_NEW (opnew, true);
     DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
+    tree builtin_opnew = build_cp_library_fn (get_identifier("__builtin_operator_new"),
+					      NEW_EXPR, newtype, 0);
+    DECL_IS_MALLOC (builtin_opnew) = 1;
+    DECL_SET_IS_OPERATOR_NEW (builtin_opnew, true);
+    DECL_IS_REPLACEABLE_OPERATOR (builtin_opnew) = 1;
+    SET_DECL_ASSEMBLER_NAME (builtin_opnew, DECL_ASSEMBLER_NAME (opnew));
+    pushdecl (builtin_opnew);
     opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
     DECL_IS_MALLOC (opnew) = 1;
     DECL_SET_IS_OPERATOR_NEW (opnew, true);
     DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
+
     tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
     DECL_SET_IS_OPERATOR_DELETE (opdel, true);
     DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
+    tree builtin_opdel = build_cp_library_fn (get_identifier("__builtin_operator_delete"),
+					      DELETE_EXPR, deltype, ECF_NOTHROW);
+    DECL_SET_IS_OPERATOR_DELETE (builtin_opdel, true);
+    DECL_IS_REPLACEABLE_OPERATOR (builtin_opdel) = 1;
+    SET_DECL_ASSEMBLER_NAME (builtin_opdel, DECL_ASSEMBLER_NAME (opdel));
+    pushdecl (builtin_opdel);
     opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
     DECL_SET_IS_OPERATOR_DELETE (opdel, true);
     DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
@@ -5072,6 +5087,12 @@ cxx_init_decl_processing (void)
 	opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
 	DECL_SET_IS_OPERATOR_DELETE (opdel, true);
 	DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
+	builtin_opdel = build_cp_library_fn (get_identifier("__builtin_operator_delete"),
+					     DELETE_EXPR, deltype, ECF_NOTHROW);
+	DECL_SET_IS_OPERATOR_DELETE (builtin_opdel, true);
+	DECL_IS_REPLACEABLE_OPERATOR (builtin_opdel) = 1;
+	SET_DECL_ASSEMBLER_NAME (builtin_opdel, DECL_ASSEMBLER_NAME (opdel));
+	pushdecl (builtin_opdel);
 	opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
 	DECL_SET_IS_OPERATOR_DELETE (opdel, true);
 	DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
@@ -5094,6 +5115,13 @@ cxx_init_decl_processing (void)
 	DECL_IS_MALLOC (opnew) = 1;
 	DECL_SET_IS_OPERATOR_NEW (opnew, true);
 	DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
+	builtin_opnew = build_cp_library_fn (get_identifier("__builtin_operator_new"),
+					     VEC_NEW_EXPR, newtype, 0);
+	DECL_IS_MALLOC (builtin_opnew) = 1;
+	DECL_SET_IS_OPERATOR_NEW (builtin_opnew, true);
+	DECL_IS_REPLACEABLE_OPERATOR (builtin_opnew) = 1;
+	SET_DECL_ASSEMBLER_NAME (builtin_opnew, DECL_ASSEMBLER_NAME (opnew));
+	pushdecl (builtin_opnew);
 	opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
 	DECL_IS_MALLOC (opnew) = 1;
 	DECL_SET_IS_OPERATOR_NEW (opnew, true);
@@ -5107,6 +5135,12 @@ cxx_init_decl_processing (void)
 	opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
 	DECL_SET_IS_OPERATOR_DELETE (opdel, true);
 	DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
+	builtin_opdel = build_cp_library_fn (get_identifier("__builtin_operator_delete"),
+					     DELETE_EXPR, deltype, ECF_NOTHROW);
+	DECL_SET_IS_OPERATOR_DELETE (builtin_opdel, true);
+	DECL_IS_REPLACEABLE_OPERATOR (builtin_opdel) = 1;
+	SET_DECL_ASSEMBLER_NAME (builtin_opdel, DECL_ASSEMBLER_NAME (opdel));
+	pushdecl (builtin_opdel);
 	opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
 	DECL_SET_IS_OPERATOR_DELETE (opdel, true);
 	DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
@@ -5122,6 +5156,12 @@ cxx_init_decl_processing (void)
 	    opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
 	    DECL_SET_IS_OPERATOR_DELETE (opdel, true);
 	    DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
+	    builtin_opdel = build_cp_library_fn (get_identifier("__builtin_operator_delete"),
+						 DELETE_EXPR, deltype, ECF_NOTHROW);
+	    DECL_SET_IS_OPERATOR_DELETE (builtin_opdel, true);
+	    DECL_IS_REPLACEABLE_OPERATOR (builtin_opdel) = 1;
+	    SET_DECL_ASSEMBLER_NAME (builtin_opdel, DECL_ASSEMBLER_NAME (opdel));
+	    pushdecl (builtin_opdel);
 	    opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
 	    DECL_SET_IS_OPERATOR_DELETE (opdel, true);
 	    DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;

  reply	other threads:[~2024-05-14 13:47 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-06 19:00 [Bug tree-optimization/109442] New: " hiraditya at msn dot com
2023-04-11 13:28 ` [Bug tree-optimization/109442] " rguenth at gcc dot gnu.org
2023-04-11 13:33 ` redi at gcc dot gnu.org
2023-04-11 13:38 ` redi at gcc dot gnu.org
2023-04-12  7:40 ` [Bug libstdc++/109442] " rguenth at gcc dot gnu.org
2023-04-12  9:29 ` redi at gcc dot gnu.org
2023-04-12  9:45 ` rguenth at gcc dot gnu.org
2023-04-12 10:01 ` redi at gcc dot gnu.org
2023-04-12 10:13 ` redi at gcc dot gnu.org
2023-04-12 10:22 ` rguenth at gcc dot gnu.org
2023-04-12 10:29 ` redi at gcc dot gnu.org
2023-04-12 10:35 ` redi at gcc dot gnu.org
2023-04-12 11:52 ` rguenther at suse dot de
2023-04-12 11:55 ` redi at gcc dot gnu.org
2023-04-16 18:38 ` richard-gccbugzilla at metafoo dot co.uk
2023-04-17  6:49 ` rguenth at gcc dot gnu.org
2023-04-18  2:15 ` richard-gccbugzilla at metafoo dot co.uk
2023-06-15 18:38 ` hiraditya at msn dot com
2024-05-11  0:07 ` xry111 at gcc dot gnu.org
2024-05-11 16:05 ` hubicka at gcc dot gnu.org
2024-05-14 13:47   ` Jan Hubicka [this message]
2024-05-11 16:44 ` redi at gcc dot gnu.org
2024-05-14 13:47 ` hubicka at ucw dot cz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZkNrhtt7BLzI7-BJ@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc-bugs@gcc.gnu.org \
    --cc=gcc-bugzilla@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).