From patchwork Wed Feb 14 11:44:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 200926 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1151363dyb; Wed, 14 Feb 2024 03:46:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXXdFu954TnBnEn8nlfLI8MV+K0OOjWgqnxMM0DVBzUKrrnPkcH78HgoDHPZg/ycumaRAuN/gQT8rmHhGmHHzT9VP+0dw== X-Google-Smtp-Source: AGHT+IFQ6jHYtlCIa/E65RLBYlGOgx4hFL6WD6TtdDs7jibACtR4+LyYEITLUzUgVJLHBlD/peJa X-Received: by 2002:a25:8686:0:b0:dc6:f055:c16d with SMTP id z6-20020a258686000000b00dc6f055c16dmr1946097ybk.36.1707911199189; Wed, 14 Feb 2024 03:46:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707911199; cv=pass; d=google.com; s=arc-20160816; b=Z1aTXm8xqHP1Y9tJBWYC6/TyFnzMuoRuuqrNO+z7J83sZI3hTAFMexsSkvi+ufjckK iOgYOSUa4TRWMSJ28XsT1AgWVeFFZRTIDAQqQ2/cqXRTchDZv9q47YVKMX3Frdg6jvBo epL0Si56cdl3nSzs/7lF+ALq8U8WtnJgQL3vcyIYZ/3Fnh2nPPfFq199yGJpWaWx48Fn 2U3nIlKmWhL1XVDkyG29yLXFbxp8G8+z/USER7pMpVJs1Dp5X4w21X79smXQJq+3tl14 friFzVtQfSICIGjJJwi0TK/bS5Xft5sepPqH84DE8yqeANmXIgBbft6/6dncpH2vtvSw Xniw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=lnilSjNkyNw+P75u1spnEUULrgCxyRX7LpCiyrJytKY=; fh=Q2QCV/CiLgJUj3AaAL4d++9FR4af35na9Atn4JA66L0=; b=tS/aKZj6SPOwrGZrH/LmVAdFQL09sLdBzeOqnyFQJcMBohVS3q3OB/wwVwpPeoxKGy w5zV8piFdKRaRAED3Sa5ndKSbaBHCs0nCjQKePfRpaKWlRPB9MnIAv6jByQEfyM1JeJE vQApzRDnWWlJHOEwBBEBvJFMz2sURzqtbt6bUr26A2uEuh/MsfsVU0A+q9PZR62yPFFk /gSjGfG4B0iqB8sv/5R+jNLTsHAnudzrHZ3hvAJrQ71SIj79zOWmC3vw9WJhDrHJL0bw LGKk8qzsZuiCaWUfXymUNuWemH7dslPBnWVOMJvckm9SdyQnXGopwOqYzfbthPKcQ1DX HGxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SKJlm5KW; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org X-Forwarded-Encrypted: i=2; AJvYcCVi4GW8koaeJcvbjmmuZzGQfekCYFsNiSXzxTwRf3oGVvwLbjHDop7x5u/tCHrDCC2aS+jRoRumCovUbAiXCeYr0AmqXA== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id os6-20020a05620a810600b007859581c77dsi10179646qkn.567.2024.02.14.03.46.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 03:46:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SKJlm5KW; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CDE99385DC1A for ; Wed, 14 Feb 2024 11:46:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CDE99385DC1A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707911198; bh=lnilSjNkyNw+P75u1spnEUULrgCxyRX7LpCiyrJytKY=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=SKJlm5KW14BLhVRoijxcEdU9kyeqVUmzxxvtayjC0SbHrOMNVlfEenRtWxjkrKGdl I8qO4vAhPG+iYt6MUNiFyrlEn3e39/PoEFAzpWrqn7a0GqL4KomVHCZWtr093fqEvJ fP0KMGU6+33ad89Sw1G8a/Bi4OAuD4O3PewvsXXA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 4FEDF385C6E8; Wed, 14 Feb 2024 11:45:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FEDF385C6E8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4FEDF385C6E8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707911130; cv=none; b=fk3HfkaKWatW5iBtEPsVZ50YsT9ZhG9Dp0wpGboeziaJqOi3DdcFRa3J+lbk3zCbL7Ld8JzA8ts2yVojujkZHs66oylPO2GLkA1StpFy2StHjozQm7Mk9aTLL+HnIzJmVy5KJYch+JXvkNqaM2k+vD1MxL0bLZl2TcJXmxm5NCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707911130; c=relaxed/simple; bh=TC36lHwh3uKtei4oLZoVcS9hpnutBz1xIUTByxldaiE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=rEnKJ3GOuIwEUQRIPBo9cqgW3p2rZ+q6WoHaSysJDP5myssL6lznZTtrKehUzqng+pUgPUaSama8tzSvxJBUCnfvAcwBIiGkMQhfGs4z6aT/kIVNMrnqRtW/jLDQDEtg0S5yI/Mtzfsw0S93H4Yb9gk5GRDjelRR8b5fz2tLU3E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41EBg4YW024993; Wed, 14 Feb 2024 11:45:27 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3w8f1c4kf7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 11:45:27 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41EBj5uq019284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Feb 2024 03:45:05 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41EBj59u001247 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 03:45:05 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 1/2] c++: Implement __add_pointer built-in trait Date: Wed, 14 Feb 2024 03:44:47 -0800 Message-ID: <20240214114448.847646-1-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: SpElQZmHLXScYySB0Yx7YBLuVP8PVWuL X-Proofpoint-GUID: SpElQZmHLXScYySB0Yx7YBLuVP8PVWuL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_04,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 spamscore=0 suspectscore=0 phishscore=0 mlxlogscore=581 adultscore=0 clxscore=1034 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402140091 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790874693629428413 X-GMAIL-MSGID: 1790874693629428413 This patch implements built-in trait for std::add_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __add_pointer. * semantics.cc (finish_trait_type): Handle CPTK_ADD_POINTER. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __add_pointer. * g++.dg/ext/add_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 9 ++++++ gcc/testsuite/g++.dg/ext/add_pointer.C | 37 ++++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ 4 files changed, 50 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_pointer.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 394f006f20f..cec385ee501 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -48,6 +48,7 @@ #define DEFTRAIT_TYPE_DEFAULTED #endif +DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) DEFTRAIT_EXPR (HAS_NOTHROW_COPY, "__has_nothrow_copy", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 57840176863..e23693ab57f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12760,6 +12760,15 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_POINTER: + if (TREE_CODE (type1) == FUNCTION_TYPE + && ((TYPE_QUALS (type1) & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) + || FUNCTION_REF_QUALIFIED (type1))) + return type1; + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + return build_pointer_type (type1); + case CPTK_REMOVE_CV: return cv_unqualified (type1); diff --git a/gcc/testsuite/g++.dg/ext/add_pointer.C b/gcc/testsuite/g++.dg/ext/add_pointer.C new file mode 100644 index 00000000000..3091510f3b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_pointer.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__add_pointer(int), int*)); +SA(__is_same(__add_pointer(int*), int**)); +SA(__is_same(__add_pointer(const int), const int*)); +SA(__is_same(__add_pointer(int&), int*)); +SA(__is_same(__add_pointer(ClassType*), ClassType**)); +SA(__is_same(__add_pointer(ClassType), ClassType*)); +SA(__is_same(__add_pointer(void), void*)); +SA(__is_same(__add_pointer(const void), const void*)); +SA(__is_same(__add_pointer(volatile void), volatile void*)); +SA(__is_same(__add_pointer(const volatile void), const volatile void*)); + +void f1(); +using f1_type = decltype(f1); +using pf1_type = decltype(&f1); +SA(__is_same(__add_pointer(f1_type), pf1_type)); + +void f2() noexcept; // PR libstdc++/78361 +using f2_type = decltype(f2); +using pf2_type = decltype(&f2); +SA(__is_same(__add_pointer(f2_type), pf2_type)); + +using fn_type = void(); +using pfn_type = void(*)(); +SA(__is_same(__add_pointer(fn_type), pfn_type)); + +SA(__is_same(__add_pointer(void() &), void() &)); +SA(__is_same(__add_pointer(void() & noexcept), void() & noexcept)); +SA(__is_same(__add_pointer(void() const), void() const)); +SA(__is_same(__add_pointer(void(...) &), void(...) &)); +SA(__is_same(__add_pointer(void(...) & noexcept), void(...) & noexcept)); +SA(__is_same(__add_pointer(void(...) const), void(...) const)); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 02b4b4d745d..56e8db7ac32 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -2,6 +2,9 @@ // { dg-do compile } // Verify that __has_builtin gives the correct answer for C++ built-ins. +#if !__has_builtin (__add_pointer) +# error "__has_builtin (__add_pointer) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif