On Thu, Jul 9, 2026 at 9:44 AM Arsen Arsenović <[email protected]> wrote:
>
> ... in anticipation of a few coming patches implementing C++ Named
> Address Space support.
>
> gcc/c-family/ChangeLog:
>
>         * c-common.cc (addr_space_superset): Move here from
>         ../c/c-typeck.cc.
>         (c_register_addr_space): Move here from ../c/c-decl.cc.
>         * c-common.h (c_register_addr_space): Move into c-common.cc
>         section.
>         (addr_space_superset): Declare.
>         (c_make_keyword): New.  Marks ID as a keyword.  Implemented
>         by both FEs.
>         (c_unmake_keyword): New.  Unmarks ID as a keyword.  Implemented
>         by both FEs.
>
> gcc/c/ChangeLog:
>
>         * c-decl.cc (c_make_keyword): Implement.
>         (c_unmake_keyword): Ditto.
>         (c_register_addr_space): Move into ../c-family/c-common.cc.
>         * c-typeck.cc (addr_space_superset): Move into
>         ../c-family/c-common.cc.
>
> gcc/cp/ChangeLog:
>
>         * lex.cc (set_identifier_kind): Add comment referencing the two
>         functions mentioned below.
>         (c_make_keyword): Implement.
>         (c_unmake_keyword): Ditto.
>         * tree.cc (c_register_addr_space): Drop.  The implementation is
>         now in c-family.cc, so no stub is needed.
> ---
>  gcc/c-family/c-common.cc | 45 ++++++++++++++++++++++++++++++++++++++++
>  gcc/c-family/c-common.h  | 16 +++++++++++---
>  gcc/c/c-decl.cc          | 26 +++++++++++------------
>  gcc/c/c-typeck.cc        | 26 -----------------------
>  gcc/cp/lex.cc            | 23 ++++++++++++++++++++
>  gcc/cp/tree.cc           |  9 --------
>  6 files changed, 93 insertions(+), 52 deletions(-)
>
> diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
> index 3d7ef128f0d9..e05551e51192 100644
> --- a/gcc/c-family/c-common.cc
> +++ b/gcc/c-family/c-common.cc
> @@ -660,6 +660,32 @@ c_addr_space_name (addr_space_t as)
>    return IDENTIFIER_POINTER (ridpointers [rid]);
>  }
>
> +/* Return true if between two named address spaces, whether there is a 
> superset
> +   named address space that encompasses both address spaces.  If there is a
> +   superset, return which address space is the superset.  */
> +
> +bool
> +addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t* 
> common)
> +{
> +  if (as1 == as2)
> +    {
> +      *common = as1;
> +      return true;
> +    }
> +  else if (targetm.addr_space.subset_p (as1, as2))
> +    {
> +      *common = as2;
> +      return true;
> +    }
> +  else if (targetm.addr_space.subset_p (as2, as1))
> +    {
> +      *common = as1;
> +      return true;
> +    }
> +  else
> +    return false;
> +}
> +
>  /* Push current bindings for the function name VAR_DECLS.  */
>
>  void
> @@ -2899,6 +2925,25 @@ c_build_bitfield_integer_type (unsigned HOST_WIDE_INT 
> width, int unsignedp)
>    return build_nonstandard_integer_type (width, unsignedp);
>  }
>
> +/* Register reserved keyword WORD as qualifier for address space AS.  */
> +
> +void
> +c_register_addr_space (const char *word, addr_space_t as)
> +{
> +  int rid = RID_FIRST_ADDR_SPACE + as;
> +  tree id;
> +
> +  /* Address space qualifiers are only supported
> +     in C with GNU extensions enabled.  */
> +  if (c_dialect_objc () || flag_no_asm)
> +    return;
> +
> +  id = get_identifier (word);
> +  C_SET_RID_CODE (id, rid);
> +  c_make_keyword (id);
> +  ridpointers[rid] = id;
> +}
> +
>  /* The C version of the register_builtin_type langhook.  */
>
>  void
> diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
> index 40a4771a1f25..569edc064014 100644
> --- a/gcc/c-family/c-common.h
> +++ b/gcc/c-family/c-common.h
> @@ -43,6 +43,10 @@ never after.
>  #endif
>  #include "diagnostic-core.h"
>
> +#if CHECKING_P
> +# include "target.h"
> +#endif

I don't think we normally have includes depend on compiling
with/without checking.
Maybe include target.h from c-target.h instead.

> +
>  /* Usage of TREE_LANG_FLAG_?:
>     0: IDENTIFIER_MARKED (used by search routines).
>        C_MAYBE_CONST_EXPR_INT_OPERANDS (in C_MAYBE_CONST_EXPR, for C)
> @@ -843,12 +847,10 @@ extern const struct scoped_attribute_specs 
> c_common_format_attribute_table;
>
>  extern tree (*make_fname_decl) (location_t, tree, int);
>
> -/* In c-decl.cc and cp/tree.cc.  FIXME.  */
> -extern void c_register_addr_space (const char *str, addr_space_t as);
> -
>  /* In c-common.cc.  */
>  extern bool in_late_binary_op;
>  extern const char *c_addr_space_name (addr_space_t as);
> +extern bool addr_space_superset (addr_space_t, addr_space_t, addr_space_t *);
>  extern tree identifier_global_value (tree);
>  extern tree identifier_global_tag (tree);
>  extern int names_builtin_p (const char *);
> @@ -1002,6 +1004,7 @@ extern bool c_common_init (void);
>  extern void c_common_finish (void);
>  extern void c_common_parse_file (void);
>  extern alias_set_type c_common_get_alias_set (tree);
> +extern void c_register_addr_space (const char *, addr_space_t);
>  extern void c_register_builtin_type (tree, const char*);
>  extern bool c_promoting_integer_type_p (const_tree);
>  extern bool self_promoting_args_p (const_tree);
> @@ -1133,6 +1136,13 @@ extern tree lookup_name (tree);
>  extern bool lvalue_p (const_tree);
>  extern int maybe_adjust_arg_pos_for_attribute (const_tree);
>  extern bool instantiation_dependent_expression_p (tree);
> +/* Make ID into a keyword, in a front end specific manner.  Will only be 
> called
> +   on normal identifiers.  Used in c-common.cc.  */
> +extern void c_make_keyword (tree id);
> +/* Make ID into a regular identifier, in a front end specific manner.  Will
> +   only be called on identifiers previously given to c_make_keyword.  Used in
> +   c-common.cc.  */
> +extern void c_unmake_keyword (tree id);
>
>  extern bool vector_targets_convertible_p (const_tree t1, const_tree t2);
>  extern bool vector_types_convertible_p (const_tree t1, const_tree t2, bool 
> emit_lax_note);
> diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
> index 3c8050a6b13a..cd0601044da0 100644
> --- a/gcc/c/c-decl.cc
> +++ b/gcc/c/c-decl.cc
> @@ -13870,23 +13870,21 @@ c_parse_final_cleanups (void)
>    ext_block = NULL;
>  }
>
> -/* Register reserved keyword WORD as qualifier for address space AS.  */
> +/* c-common.cc uses these two when registering its own keywords.  */
> +void
> +c_make_keyword (tree id)
> +{
> +  gcc_checking_assert (!C_IS_RESERVED_WORD (id));
> +  C_IS_RESERVED_WORD (id) = 1;
> +}
>
>  void
> -c_register_addr_space (const char *word, addr_space_t as)
> +c_unmake_keyword (tree id)
>  {
> -  int rid = RID_FIRST_ADDR_SPACE + as;
> -  tree id;
> -
> -  /* Address space qualifiers are only supported
> -     in C with GNU extensions enabled.  */
> -  if (c_dialect_objc () || flag_no_asm)
> -    return;
> -
> -  id = get_identifier (word);
> -  C_SET_RID_CODE (id, rid);
> -  C_IS_RESERVED_WORD (id) = 1;
> -  ridpointers [rid] = id;
> +  /* We only expect to be clearing identifiers previously made into keywords 
> by
> +     c_make_keyword.  This is done primarily for self-tests.  */
> +  gcc_checking_assert (C_IS_RESERVED_WORD (id));
> +  C_IS_RESERVED_WORD (id) = 0;
>  }
>
>  /* Return identifier to look up for omp declare reduction.  */
> diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
> index 81ed46f3ed0c..11bf30917ddb 100644
> --- a/gcc/c/c-typeck.cc
> +++ b/gcc/c/c-typeck.cc
> @@ -316,32 +316,6 @@ c_type_promotes_to (tree type)
>    return type;
>  }
>
> -/* Return true if between two named address spaces, whether there is a 
> superset
> -   named address space that encompasses both address spaces.  If there is a
> -   superset, return which address space is the superset.  */
> -
> -static bool
> -addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t 
> *common)
> -{
> -  if (as1 == as2)
> -    {
> -      *common = as1;
> -      return true;
> -    }
> -  else if (targetm.addr_space.subset_p (as1, as2))
> -    {
> -      *common = as2;
> -      return true;
> -    }
> -  else if (targetm.addr_space.subset_p (as2, as1))
> -    {
> -      *common = as1;
> -      return true;
> -    }
> -  else
> -    return false;
> -}
> -
>  /* Return a variant of TYPE which has all the type qualifiers of LIKE
>     as well as those of TYPE.  */
>
> diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc
> index da40be0a5e06..d6fad67cd5b6 100644
> --- a/gcc/cp/lex.cc
> +++ b/gcc/cp/lex.cc
> @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "coretypes.h"
>  #include "cp-tree.h"
>  #include "stringpool.h"
> +#include "c-family/c-common.h"
>  #include "c-family/c-pragma.h"
>  #include "c-family/c-objc.h"
>  #include "gcc-rich-location.h"
> @@ -134,6 +135,7 @@ get_identifier_kind_name (tree id)
>  void
>  set_identifier_kind (tree id, cp_identifier_kind kind)
>  {
> +  /* See also below.  */
>    gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
>                        & !IDENTIFIER_KIND_BIT_1 (id)
>                        & !IDENTIFIER_KIND_BIT_0 (id));
> @@ -142,6 +144,27 @@ set_identifier_kind (tree id, cp_identifier_kind kind)
>    IDENTIFIER_KIND_BIT_0 (id) |= (kind >> 0) & 1;
>  }
>
> +/* c-common.cc uses these two when registering its own keywords.  */
> +void
> +c_make_keyword (tree id)
> +{
> +  set_identifier_kind (id, cik_keyword);
> +}
> +
> +void
> +c_unmake_keyword (tree id)
> +{
> +  /* We only expect to be clearing identifiers previously made into keywords 
> by
> +     c_make_keyword.  This is done primarily for self-tests.  */
> +  static_assert (cik_keyword == 1, "this assert assumes this value");
> +  gcc_checking_assert (IDENTIFIER_KIND_BIT_0 (id)
> +                      && !IDENTIFIER_KIND_BIT_1 (id)
> +                      && !IDENTIFIER_KIND_BIT_2 (id));
> +  IDENTIFIER_KIND_BIT_2 (id) = 0;
> +  IDENTIFIER_KIND_BIT_1 (id) = 0;
> +  IDENTIFIER_KIND_BIT_0 (id) = 0;
> +}
> +
>  /* Create and tag the internal operator name for the overloaded
>     operator PTR describes.  */
>
> diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
> index befdec3ae0de..86ba4fd4fd1a 100644
> --- a/gcc/cp/tree.cc
> +++ b/gcc/cp/tree.cc
> @@ -7041,15 +7041,6 @@ cp_free_lang_data (tree t)
>      DECL_CHAIN (t) = NULL_TREE;
>  }
>
> -/* Stub for c-common.  Please keep in sync with c-decl.cc.
> -   FIXME: If address space support is target specific, then this
> -   should be a C target hook.  But currently this is not possible,
> -   because this function is called via REGISTER_TARGET_PRAGMAS.  */
> -void
> -c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
> -{
> -}
> -
>  /* Return the number of operands in T that we care about for things like
>     mangling.  */
>
> --
> 2.55.0
>

Reply via email to