From patchwork Thu Oct 31 08:10:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 99896 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A2AC3857BBF for ; Thu, 31 Oct 2024 08:10:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id B30683858D21 for ; Thu, 31 Oct 2024 08:10:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B30683858D21 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B30683858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730362214; cv=none; b=Di6h2L2jdQJvkUxCrh1OWLBwIc/YyjXp43f+kVZcPPX10NXfsK5uSx+Y5PupWRx98l0C7rpnHga85wPKkbuCo7dQRh2oEPZN+LyABn6eyceS0G2+iS2oL+JTm9t8MUwcmo6TR/rLEo2zfQ/1ShZrl74JoOBdq3051+xyGZ/k/hA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730362214; c=relaxed/simple; bh=dhCuMyr+3FA3l/9GRm9rPg75cWNT33LJlnf4f5ZqMMM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Xzg8kCayemkmRlBVvdoOxf7x48Bi5G5zhTyTnt+xlFDvG3A9q8PN6j/vrwmyLGgFfBBTs/8wMkRJApz/uZipLVSmAZ3ESLjj86FFhILeMYW6PzMD5fAhaeaBLMPsawvW9xoOdlxI3NaSLmwJ44MH4J/zIbnWR4K9OXKKKDGHiU4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730362211; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=PAp6q5ydqLTr2nXpEVbwjj7J5fEYDO6Bndm6wbkGs5Q=; b=fJiTexhjGhbWKuGz7jvz74YxHyyvqZmxmRO2yIIe4WQmgP8UJbEAx1rjRKi/DkVN/k2s3V OAageo1XmZMSSwJWKHCHJUDXuvHAaf+Mil5Rm7UQOyljJlH8e42hF5sVui2/7jB3PrzOhV owVJISADhqiPtfnt6tHzExXRguXtNMU= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-403-jI8hwyo3Nt6Y-dvRUlk_WA-1; Thu, 31 Oct 2024 04:10:07 -0400 X-MC-Unique: jI8hwyo3Nt6Y-dvRUlk_WA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8DA2D19560AF; Thu, 31 Oct 2024 08:10:06 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.16]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E280D19560A2; Thu, 31 Oct 2024 08:10:05 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 49V8A23U765688 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 31 Oct 2024 09:10:02 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 49V8A2v6765687; Thu, 31 Oct 2024 09:10:02 +0100 Date: Thu, 31 Oct 2024 09:10:01 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, Jan Hubicka Subject: [PATCH] c++: Mark replaceable global operator new/delete with const std::nothrow_t& argument as DECL_IS_REPLACEABLE_OPERATOR [PR117370] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Hi! cxx_init_decl_processing predeclares 12 out of the 20 replaceable global new/delete operators and sets DECL_IS_REPLACEABLE_OPERATOR on those. But it doesn't handle the remaining 8, in particular void* operator new(std::size_t, const std::nothrow_t&) noexcept; void* operator new[](std::size_t, const std::nothrow_t&) noexcept; void operator delete(void*, const std::nothrow_t&) noexcept; void operator delete[](void*, const std::nothrow_t&) noexcept; void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) noexcept; void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&) noexcept; void operator delete(void*, std::align_val_t, const std::nothrow_t&) noexcept; void operator delete[](void*, std::align_val_t, const std::nothrow_t&) noexcept; The following patch sets that flag during grok_op_properties for those, so that they don't need to be predeclared. The patch doesn't fix the whole PR, as some work is needed on the CDDCE side too, unlike the throwing operator new case the if (ptr) conditional around operator delete isn't removed by VRP and so we need to handle conditional delete for unconditional new. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-10-31 Jakub Jelinek PR c++/117370 * decl.cc (grok_op_properties): Mark global replaceable operator new/delete operators with const std::nothrow_t & last argument with DECL_IS_REPLACEABLE_OPERATOR. Jakub --- gcc/cp/decl.cc.jj 2024-10-25 10:00:29.413768644 +0200 +++ gcc/cp/decl.cc 2024-10-30 17:50:48.165446364 +0100 @@ -16191,6 +16191,52 @@ grok_op_properties (tree decl, bool comp } } + /* Check for replaceable global new/delete operators with + const std::nothrow_t & last argument, other replaceable global + new/delete operators are marked in cxx_init_decl_processing. */ + if (CP_DECL_CONTEXT (decl) == global_namespace) + { + tree args = argtypes; + if (args + && args != void_list_node + && same_type_p (TREE_VALUE (args), + (op_flags & OVL_OP_FLAG_DELETE) + ? ptr_type_node : size_type_node)) + { + args = TREE_CHAIN (args); + if (aligned_new_threshold + && args + && args != void_list_node) + { + tree t = TREE_VALUE (args); + if (TREE_CODE (t) == ENUMERAL_TYPE + && DECL_NAMESPACE_STD_P (CP_TYPE_CONTEXT (t)) + && TYPE_NAME (t) + && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL + && DECL_NAME (TYPE_NAME (t)) + && id_equal (DECL_NAME (TYPE_NAME (t)), "align_val_t")) + args = TREE_CHAIN (args); + } + if (args + && args != void_list_node + && TREE_CHAIN (args) == void_list_node) + { + tree t = TREE_VALUE (args); + if (TYPE_REF_P (t) + && !TYPE_REF_IS_RVALUE (t) + && (t = TREE_TYPE (t)) + && TYPE_QUALS (t) == TYPE_QUAL_CONST + && TREE_CODE (t) == RECORD_TYPE + && DECL_NAMESPACE_STD_P (CP_TYPE_CONTEXT (t)) + && TYPE_NAME (t) + && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL + && DECL_NAME (TYPE_NAME (t)) + && id_equal (DECL_NAME (TYPE_NAME (t)), "nothrow_t")) + DECL_IS_REPLACEABLE_OPERATOR (decl) = 1; + } + } + } + if (op_flags & OVL_OP_FLAG_DELETE) { DECL_SET_IS_OPERATOR_DELETE (decl, true);