From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa33.google.com (mail-vk1-xa33.google.com [IPv6:2607:f8b0:4864:20::a33]) by sourceware.org (Postfix) with ESMTPS id CFE1A3858D35 for ; Sat, 24 Jun 2023 14:47:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFE1A3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.washington.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.washington.edu Received: by mail-vk1-xa33.google.com with SMTP id 71dfb90a1353d-4753de0807dso574211e0c.2 for ; Sat, 24 Jun 2023 07:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1687618075; x=1690210075; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5uNsGyui8BAl+ih4YFaWwccFfWH3uWa3rgCMcEJfO/g=; b=VFDPgvhOjxPj0IWvJFEV2gl0eCNAFdqlDJc3JtseLydgtnk4Bp4nYduFsxX+3FuIqU AtrA8e3UyniJTatWFvU1qwPEFXdMD6CwMQunqy52onYQV5m2SMvxHgXxBRCc8HKjL4eV jsQG+BC+FNvxNL+OnWhEY+qY3Uz8RtahAfyPQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687618075; x=1690210075; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5uNsGyui8BAl+ih4YFaWwccFfWH3uWa3rgCMcEJfO/g=; b=AIPyYxkCBinGmvQmNrZPCmkd2PppQMiD1wsEcs4hEBTfFcbQUhsWcVVIza1Fu+Ym9L PttWTGG0wP+tZggDqOzVG3WTp8V2pP5H5pFnLfY9sG2Rl5WJ2h9TkbVrR/m3F0aMNCk2 QKB5OIkj/CIUedvVMEnvMt6fhEQbcvjeoWliRTiAZ8PFncvzWM1u3P2VFK6lgV+6FhXa 1AzXobJTHvwFW4eSHx/CCtGsTo70d0m6gjalBFql2KsY1kxXd43Ko4Xwn6IADhpqlPFo ADNETDQ1JTCHJ2S6VQQbGi75SP6TtMF6PY2+F4+MPXkEzRXpCXjH/vaKshf9YnWulKdj 1FwQ== X-Gm-Message-State: AC+VfDxiRCIOf+n9nsM1DRaBTGewYhlKQPXBuuFhuKMFxVVQCY7m8suY LKdpxjqve8Zi/Gh7/S+2P52vsvK+82NqWGA0s98DUFszdUSWXNeN4GY= X-Google-Smtp-Source: ACHHUZ782nL0hDhmFF9vGowEqM37Wv28yOMNmQ2AgwMbC+Rm3CdYL8Ps2N8REpAzyCQISPJ5kUxc2cUgGYYZSx8grKM= X-Received: by 2002:a67:ea8c:0:b0:43f:3f51:b804 with SMTP id f12-20020a67ea8c000000b0043f3f51b804mr11584515vso.32.1687618075157; Sat, 24 Jun 2023 07:47:55 -0700 (PDT) MIME-Version: 1.0 References: <20230322234134.14578-1-kmatsui@cs.washington.edu> <20230624142346.84325-1-kmatsui@cs.washington.edu> In-Reply-To: <20230624142346.84325-1-kmatsui@cs.washington.edu> From: Ken Matsui Date: Sat, 24 Jun 2023 07:47:39 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] c++: implement __is_volatile built-in trait To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Here is the benchmark result for is_volatile: https://github.com/ken-matsui/gcc-benches/blob/main/is_volatile.md#sat-jun-= 24-074036-am-pdt-2023 Time: -2.42335% Peak Memory Usage: -1.07651% Total Memory Usage: -1.62369% On Sat, Jun 24, 2023 at 7:24=E2=80=AFAM Ken Matsui wrote: > > This patch implements built-in trait for std::is_volatile. > > gcc/cp/ChangeLog: > > * cp-trait.def: Define __is_volatile. > * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_VOLATILE. > * semantics.cc (trait_expr_value): Likewise. > (finish_trait_expr): Likewise. > > gcc/testsuite/ChangeLog: > > * g++.dg/ext/has-builtin-1.C: Test existence of __is_volatile. > * g++.dg/ext/is_volatile.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_volatile.C | 19 +++++++++++++++++++ > 5 files changed, 30 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/ext/is_volatile.C > > diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc > index 8cf0f2d0974..e971d67ee25 100644 > --- a/gcc/cp/constraint.cc > +++ b/gcc/cp/constraint.cc > @@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args) > case CPTK_IS_UNION: > inform (loc, " %qT is not a union", t1); > break; > + case CPTK_IS_VOLATILE: > + inform (loc, " %qT is not a volatile type", t1); > + break; > case CPTK_IS_AGGREGATE: > inform (loc, " %qT is not an aggregate", t1); > break; > diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def > index 8b7fece0cc8..414b1065a11 100644 > --- a/gcc/cp/cp-trait.def > +++ b/gcc/cp/cp-trait.def > @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially= _assignable", 2) > DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible= ", -1) > DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) > DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) > +DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) > DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_fr= om_temporary", 2) > DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_t= emporary", 2) > /* FIXME Added space to avoid direct usage in GCC 13. */ > diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc > index 8fb47fd179e..10934d01504 100644 > --- a/gcc/cp/semantics.cc > +++ b/gcc/cp/semantics.cc > @@ -12079,6 +12079,9 @@ trait_expr_value (cp_trait_kind kind, tree type1,= tree type2) > case CPTK_IS_ENUM: > return type_code1 =3D=3D ENUMERAL_TYPE; > > + case CPTK_IS_VOLATILE: > + return CP_TYPE_VOLATILE_P (type1); > + > case CPTK_IS_FINAL: > return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); > > @@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind = kind, tree type1, tree type2) > case CPTK_IS_ENUM: > case CPTK_IS_UNION: > case CPTK_IS_SAME: > + case CPTK_IS_VOLATILE: > break; > > case CPTK_IS_LAYOUT_COMPATIBLE: > diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++= .dg/ext/has-builtin-1.C > index f343e153e56..7ad640f141b 100644 > --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C > +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C > @@ -146,3 +146,6 @@ > #if !__has_builtin (__remove_cvref) > # error "__has_builtin (__remove_cvref) failed" > #endif > +#if !__has_builtin (__is_volatile) > +# error "__has_builtin (__is_volatile) failed" > +#endif > diff --git a/gcc/testsuite/g++.dg/ext/is_volatile.C b/gcc/testsuite/g++.d= g/ext/is_volatile.C > new file mode 100644 > index 00000000000..004e397e5e7 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C > @@ -0,0 +1,19 @@ > +// { dg-do compile { target c++11 } } > + > +#include > + > +using namespace __gnu_test; > + > +#define SA(X) static_assert((X),#X) > + > +// Positive tests. > +SA(__is_volatile(volatile int)); > +SA(__is_volatile(const volatile int)); > +SA(__is_volatile(vClassType)); > +SA(__is_volatile(cvClassType)); > + > +// Negative tests. > +SA(!__is_volatile(int)); > +SA(!__is_volatile(const int)); > +SA(!__is_volatile(ClassType)); > +SA(!__is_volatile(cClassType)); > -- > 2.41.0 >