From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id C36513875425; Tue, 14 May 2024 13:47:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C36513875425 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kam.mff.cuni.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C36513875425 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.113.20.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715694474; cv=none; b=Ss7olnEdbRHN1iAwOfwNnr07Gwwj2p9D93uMkhdFEeWFXJUS/+QK29caRf/75d5qaqnLW+vyKxnUfqcuUvUDq1u0iungW+pRqdeiWuGNoCVOTpTeiBLQdkaPlv5oLkCocOqPmN5HFEghKPWLByc+0hI3iuldYrOFC9djIBNqxf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715694474; c=relaxed/simple; bh=/QYi9rx29JFvnH0vpi8CqYklAz2Lkc1TApGsmZMV4qg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=J6ZBNsxJtc+2wd7I2DmRkLo1jOW7TXuUjAEVSWQD6427kSi2casTbX55pl/tt8Bz8r+Y1hvA+GrPqEqUDqYoIMgsuu4WffiDEZ59GfoOMCXKFSuCt5taTqlkAa2E3yzmO/ntcg2C5frlzjgHmGTHQGZvDQl5aSSovcrnOzyCxso= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 6EC18286F97; Tue, 14 May 2024 15:47:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1715694470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8icwSveudpSuIDYwivlR8eEMuIRHs5+0EliO8SOGz4s=; b=QJj3dpGV3DivaPR8R1J0Xquny4/wrxK4/IfVk7zvdohkt1p+X49ake/qV60p48kekpyNcX jU3jg8LyfzbFyXhpi8YvTxzOFrO98v2SnN/rhog/geRu2YyVRTSwT4G0BUwOhJrso9/MRQ cfPQKn/kFvrwrPJApUiJkXscV4fc3gQ= Date: Tue, 14 May 2024 15:47:50 +0200 From: Jan Hubicka To: "hubicka at gcc dot gnu.org" Cc: gcc-bugs@gcc.gnu.org Subject: Re: [Bug libstdc++/109442] Dead local copy of std::vector not removed from function Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="LpKvH1sWp/HcRqGr" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,JMQ_SPF_NEUTRAL,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --LpKvH1sWp/HcRqGr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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? --LpKvH1sWp/HcRqGr Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=newdelete 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; --LpKvH1sWp/HcRqGr--