From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by sourceware.org (Postfix) with ESMTPS id 5C7883858D20 for ; Wed, 13 Sep 2023 19:37:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C7883858D20 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gdcproject.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gdcproject.org Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4Rm9gv4wm2z9sxR for ; Wed, 13 Sep 2023 21:36:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gdcproject.org; s=MBO0001; t=1694633819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZUIDSRvOLaTL0SAhNRxmLQFzVAWMiOcu8ZReRkmxpYI=; b=tcW7nyNjgGhTb4M4HBO1BKZh9dQICUOFzJfgoqPns5d5a6ek0eeA85MCeoGS9yTRwydcBw AfCQ+3+DQh7Ez6Pf5VrSc4Xr+DSCz96xZxtcdO+nDB86ux4hPuqibg2XrHmz+9FqJgP3Yi rv9O4+944fh0UQ5J3Dy5RJCGqGKJfd/iVsF5kvjk7VsDi2/asAcf2x1niJsRpNOv5YRwIk f9SNQ4O4P4jGP2hF+QmE2N7NUO7I5ExOrv1UCJu2W4tOGq60KhixcCSQ2j3aiLHw/Axsk0 lZo6ORE4RPV9SyJcRQ+PQXve1fGuGMyFDXykkfVGlMAxRXie6Lftn7HSWBst9w== Date: Wed, 13 Sep 2023 21:36:56 +0200 From: Iain Buclaw Subject: Re: [PATCH] Allow target attributes in non-gnu namespaces To: Richard Sandiford via Gcc-patches References: In-Reply-To: MIME-Version: 1.0 Message-Id: <1694633230.kxcag5xcmj.astroid@pulse.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4Rm9gv4wm2z9sxR X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,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: Excerpts from Richard Sandiford via Gcc-patches's message of September 8, 2= 023 6:29 pm: > Currently there are four static sources of attributes: >=20 > - LANG_HOOKS_ATTRIBUTE_TABLE > - LANG_HOOKS_COMMON_ATTRIBUTE_TABLE > - LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE > - TARGET_ATTRIBUTE_TABLE >=20 > All of the attributes in these tables go in the "gnu" namespace. > This means that they can use the traditional GNU __attribute__((...)) > syntax and the standard [[gnu::...]] syntax. >=20 > Standard attributes are registered dynamically with a null namespace. > There are no supported attributes in other namespaces (clang, vendor > namespaces, etc.). >=20 > This patch tries to generalise things by making the namespace > part of the attribute specification. >=20 > It's usual for multiple attributes to be defined in the same namespace, > so rather than adding the namespace to each individual definition, > it seemed better to group attributes in the same namespace together. > This would also allow us to reuse the same table for clang attributes > that are written with the GNU syntax, or other similar situations > where the attribute can be accessed via multiple "spellings". >=20 > The patch therefore adds a scoped_attribute_specs that contains > a namespace and a list of attributes in that namespace. >=20 Changes to the D front-end in this patch look reasonable to me. Regards, Iain. >=20 >=20 > gcc/d/ > * d-tree.h (d_langhook_attribute_table): Replace with... > (d_langhook_gnu_attribute_table): ...this. > (d_langhook_common_attribute_table): Change type to > scoped_attribute_specs. > * d-attribs.cc (d_langhook_common_attribute_table): Change type to > scoped_attribute_specs, using... > (d_langhook_common_attributes): ...this as the underlying array. > (d_langhook_attribute_table): Replace with... > (d_langhook_gnu_attributes, d_langhook_gnu_attribute_table): ...these > new globals. > (uda_attribute_p): Update accordingly, and update for new > targetm.attribute_table type. > * d-lang.cc (d_langhook_attribute_table): New global. > (LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): Delete. >=20 > --- > gcc/d/d-attribs.cc | 35 ++--- > gcc/d/d-lang.cc | 8 +- > gcc/d/d-tree.h | 4 +- >=20 > diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc > index cc46220ddc2..78215bc88bc 100644 > --- a/gcc/d/d-attribs.cc > +++ b/gcc/d/d-attribs.cc > @@ -162,7 +162,7 @@ extern const struct attribute_spec::exclusions attr_c= old_hot_exclusions[] =3D > =20 > /* Table of machine-independent attributes. > For internal use (marking of built-ins) only. */ > -const attribute_spec d_langhook_common_attribute_table[] =3D > +static const attribute_spec d_langhook_common_attributes[] =3D > { > ATTR_SPEC ("noreturn", 0, 0, true, false, false, false, > handle_noreturn_attribute, attr_noreturn_exclusions), > @@ -190,11 +190,15 @@ const attribute_spec d_langhook_common_attribute_ta= ble[] =3D > handle_fnspec_attribute, NULL), > ATTR_SPEC ("omp declare simd", 0, -1, true, false, false, false, > handle_omp_declare_simd_attribute, NULL), > - ATTR_SPEC (NULL, 0, 0, false, false, false, false, NULL, NULL), > +}; > + > +const scoped_attribute_specs d_langhook_common_attribute_table =3D > +{ > + "gnu", d_langhook_common_attributes > }; > =20 > /* Table of D language attributes exposed by `gcc.attribute' UDAs. */ > -const attribute_spec d_langhook_attribute_table[] =3D > +static const attribute_spec d_langhook_gnu_attributes[] =3D > { > ATTR_SPEC ("noinline", 0, 0, true, false, false, false, > d_handle_noinline_attribute, attr_noinline_exclusions), > @@ -238,9 +242,12 @@ const attribute_spec d_langhook_attribute_table[] = =3D > d_handle_used_attribute, NULL), > ATTR_SPEC ("visibility", 1, 1, false, false, false, false, > d_handle_visibility_attribute, NULL), > - ATTR_SPEC (NULL, 0, 0, false, false, false, false, NULL, NULL), > }; > =20 > +const scoped_attribute_specs d_langhook_gnu_attribute_table =3D > +{ > + "gnu", d_langhook_gnu_attributes > +}; > =20 > /* Insert the type attribute ATTRNAME with value VALUE into TYPE. > Returns a new variant of the original type declaration. */ > @@ -283,20 +290,14 @@ uda_attribute_p (const char *name) > =20 > /* Search both our language, and target attribute tables. > Common and format attributes are kept internal. */ > - for (const attribute_spec *p =3D d_langhook_attribute_table; p->name; = p++) > - { > - if (get_identifier (p->name) =3D=3D ident) > - return true; > - } > + for (const attribute_spec &p : d_langhook_gnu_attributes) > + if (get_identifier (p.name) =3D=3D ident) > + return true; > =20 > - if (targetm.attribute_table) > - { > - for (const attribute_spec *p =3D targetm.attribute_table; p->name;= p++) > - { > - if (get_identifier (p->name) =3D=3D ident) > - return true; > - } > - } > + for (auto scoped_attributes : targetm.attribute_table) > + for (const attribute_spec &p : scoped_attributes->attributes) > + if (get_identifier (p.name) =3D=3D ident) > + return true; > =20 > return false; > } > diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc > index 10b9000119e..90699f6d36b 100644 > --- a/gcc/d/d-lang.cc > +++ b/gcc/d/d-lang.cc > @@ -1919,6 +1919,12 @@ d_get_sarif_source_language (const char *) > return "d"; > } > =20 > +const scoped_attribute_specs *const d_langhook_attribute_table[] =3D > +{ > + &d_langhook_gnu_attribute_table, > + &d_langhook_common_attribute_table, > +}; > + > /* Definitions for our language-specific hooks. */ > =20 > #undef LANG_HOOKS_NAME > @@ -1930,7 +1936,6 @@ d_get_sarif_source_language (const char *) > #undef LANG_HOOKS_HANDLE_OPTION > #undef LANG_HOOKS_POST_OPTIONS > #undef LANG_HOOKS_PARSE_FILE > -#undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE > #undef LANG_HOOKS_ATTRIBUTE_TABLE > #undef LANG_HOOKS_GET_ALIAS_SET > #undef LANG_HOOKS_TYPES_COMPATIBLE_P > @@ -1963,7 +1968,6 @@ d_get_sarif_source_language (const char *) > #define LANG_HOOKS_HANDLE_OPTION d_handle_option > #define LANG_HOOKS_POST_OPTIONS d_post_options > #define LANG_HOOKS_PARSE_FILE d_parse_file > -#define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE d_langhook_common_attribute_= table > #define LANG_HOOKS_ATTRIBUTE_TABLE d_langhook_attribute_table > #define LANG_HOOKS_GET_ALIAS_SET d_get_alias_set > #define LANG_HOOKS_TYPES_COMPATIBLE_P d_types_compatible_p > diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h > index b64a6fb46f9..021d3409b0a 100644 > --- a/gcc/d/d-tree.h > +++ b/gcc/d/d-tree.h > @@ -508,8 +508,8 @@ extern tree insert_decl_attribute (tree, const char *= , tree =3D NULL_TREE); > extern void apply_user_attributes (Dsymbol *, tree); > =20 > /* In d-builtins.cc. */ > -extern const attribute_spec d_langhook_attribute_table[]; > -extern const attribute_spec d_langhook_common_attribute_table[]; > +extern const struct scoped_attribute_specs d_langhook_gnu_attribute_tabl= e; > +extern const struct scoped_attribute_specs d_langhook_common_attribute_t= able; > extern Type *build_frontend_type (tree); > =20 > extern tree d_builtin_function (tree); > --=20 > 2.25.1 >=20 >=20