From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 74800384AB67; Thu, 2 May 2024 16:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74800384AB67 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 74800384AB67 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666608; cv=none; b=Wq5uCFPU+JQpIweWoy4X6nIRovuFD6CTtNwp1OHjpezMDFJsI1XYTr1kkwjklOdEHoAoURY0zT1AhIqcBdIoUus8KUlK5uHLuBBqmzucofavt1uNW9JeouknWEjRYJbc5897zRmT7nj9W0CdO0w589pYa0C37PcvwR7U2RFiUw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666608; c=relaxed/simple; bh=FRuuCiOTc7DjrwCm4eM0ctZg5Y9aICULpWy0p/FOd6Q=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KpET0Ih8Vs++IWzUlgBhZi9M+Lj/zdSPRA4RqP5t8pVNUA3s9CUUuVWxn7jFEaEngR3ehSFE24/LDcIkY2BJ2f7lBggLq0hPRXS0XU3OGp6iLFIHARx8ohZS6U3KkjJ/q9DgxiQ0EiLzZw0U4wc9M9SG+Aq/3hvGpBRlX6nN6qQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GEUbR009945; Thu, 2 May 2024 16:16:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e4kd9b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:37 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGG9S024914 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFoi023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 05/26] c++: Implement __builtin_is_pointer trait Date: Thu, 2 May 2024 09:13:31 -0700 Message-ID: <20240502161614.3705912-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: 0g2jH-A1CpOFDK7Ei2aQwbM9S8OVhek2 X-Proofpoint-GUID: 0g2jH-A1CpOFDK7Ei2aQwbM9S8OVhek2 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_05,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 impostorscore=0 mlxlogscore=788 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NEUTRAL,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: This patch implements built-in trait for std::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_is_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_is_pointer. * g++.dg/ext/is_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_pointer.C | 51 ++++++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d9caf546423..5a8aaa70fa6 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3829,6 +3829,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POD: inform (loc, " %qT is not a POD type", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index a7ea3caff4e..a6a3c195529 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_OBJECT, "__is_object", 1) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) +DEFTRAIT_EXPR (IS_POINTER, "__builtin_is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 351235a639a..86372ea0aba 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12586,6 +12586,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POD: return pod_type_p (type1); + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); @@ -12825,6 +12828,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_OBJECT: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 398719fe8d6..7954b42df97 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -17,6 +17,9 @@ #if !__has_builtin (__builtin_is_corresponding_member) # error "__has_builtin (__builtin_is_corresponding_member) failed" #endif +#if !__has_builtin (__builtin_is_pointer) +# error "__has_builtin (__builtin_is_pointer) failed" +#endif #if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) # error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..9a7a4939bbe --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__builtin_is_pointer(int)); +SA(__builtin_is_pointer(int*)); +SA(__builtin_is_pointer(int**)); + +SA(__builtin_is_pointer(const int*)); +SA(__builtin_is_pointer(const int**)); +SA(__builtin_is_pointer(int* const)); +SA(__builtin_is_pointer(int** const)); +SA(__builtin_is_pointer(int* const* const)); + +SA(__builtin_is_pointer(volatile int*)); +SA(__builtin_is_pointer(volatile int**)); +SA(__builtin_is_pointer(int* volatile)); +SA(__builtin_is_pointer(int** volatile)); +SA(__builtin_is_pointer(int* volatile* volatile)); + +SA(__builtin_is_pointer(const volatile int*)); +SA(__builtin_is_pointer(const volatile int**)); +SA(__builtin_is_pointer(const int* volatile)); +SA(__builtin_is_pointer(volatile int* const)); +SA(__builtin_is_pointer(int* const volatile)); +SA(__builtin_is_pointer(const int** volatile)); +SA(__builtin_is_pointer(volatile int** const)); +SA(__builtin_is_pointer(int** const volatile)); +SA(__builtin_is_pointer(int* const* const volatile)); +SA(__builtin_is_pointer(int* volatile* const volatile)); +SA(__builtin_is_pointer(int* const volatile* const volatile)); + +SA(!__builtin_is_pointer(int&)); +SA(!__builtin_is_pointer(const int&)); +SA(!__builtin_is_pointer(volatile int&)); +SA(!__builtin_is_pointer(const volatile int&)); + +SA(!__builtin_is_pointer(int&&)); +SA(!__builtin_is_pointer(const int&&)); +SA(!__builtin_is_pointer(volatile int&&)); +SA(!__builtin_is_pointer(const volatile int&&)); + +SA(!__builtin_is_pointer(int[3])); +SA(!__builtin_is_pointer(const int[3])); +SA(!__builtin_is_pointer(volatile int[3])); +SA(!__builtin_is_pointer(const volatile int[3])); + +SA(!__builtin_is_pointer(int(int))); +SA(__builtin_is_pointer(int(*const)(int))); +SA(__builtin_is_pointer(int(*volatile)(int))); +SA(__builtin_is_pointer(int(*const volatile)(int))); -- 2.44.0