Hi!

On 2026-05-15T14:17:10+0200, Thomas Schwinge <[email protected]> wrote:
> I've now rebased [Paul's v4] onto recent GCC trunk, [...]

Regarding 'c_register_addr_space':

> --- a/gcc/c-family/c-common.cc
> +++ b/gcc/c-family/c-common.cc

> @@ -2894,6 +2921,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);
> +  TREE_LANG_FLAG_0 (id) = 1;
> +  ridpointers[rid] = id;
> +}
> +
>  /* The C version of the register_builtin_type langhook.  */
>  
>  void

> --- a/gcc/c-family/c-common.h
> +++ b/gcc/c-family/c-common.h
> @@ -840,12 +840,11 @@ 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.  */
> @@ -996,6 +995,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);

> --- a/gcc/c/c-decl.cc
> +++ b/gcc/c/c-decl.cc
> @@ -13856,25 +13856,6 @@ c_parse_final_cleanups (void)
>    ext_block = NULL;
>  }
>  
> -/* 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_IS_RESERVED_WORD (id) = 1;
> -  ridpointers [rid] = id;
> -}
> -
>  /* Return identifier to look up for omp declare reduction.  */
>  
>  tree

> --- a/gcc/cp/tree.cc
> +++ b/gcc/cp/tree.cc

> @@ -6828,15 +6831,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.  */

The original C front end 'c_register_addr_space' code had:

    C_IS_RESERVED_WORD (id) = 1;

Now we're using:

    TREE_LANG_FLAG_0 (id) = 1;

(That's the 'gcc/c/c-tree.h' definition of 'C_IS_RESERVED_WORD' expanded.)

That happens to work for C++ front end, but only by chance; as of
Subversion r249571 (Git commit 84c0088f38ce49f390401d11a581cd1a57a008d5)
"Reorder IDENTIFIER flags", the correct incantation for the C++ front end
is:

    set_identifier_kind (id, cik_keyword);

Therefore, 'c_register_addr_space' can no longer be in
'gcc/c-family/c-common.cc' (at least not without further surgery), and so
I'm restoring the original definitions in 'gcc/c/c-decl.cc' and
'gcc/cp/tree.cc', and then implement it properly in the latter.

See the attached (incremental to Paul's v4)
"c++: parser - Support for target address spaces in C++: 
'c_register_addr_space'",
which I intend to merge into the v5 of this patch, unless there's any
objection, of course.  With this, the changes related to
'c_register_addr_space' of trunk vs. upcoming v5 are just:

    --- gcc/c-family/c-common.h
    +++ gcc/c-family/c-common.h
    @@ -841,12 +841,13 @@ 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.  */
    +/* In c-decl.cc and cp/tree.cc.  */
     extern void c_register_addr_space (const char *str, addr_space_t as);
     
     /* In c-common.cc.  */
    
    --- gcc/cp/tree.cc
    +++ gcc/cp/tree.cc
    
    @@ -6991,13 +6999,23 @@ 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.  */
    +/* Register reserved keyword WORD as qualifier for address space AS.  */
    +
     void
    -c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
    +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);
    +  set_identifier_kind (id, cik_keyword);
    +  ridpointers [rid] = id;
     }
     
     /* Return the number of operands in T that we care about for things like
    
    --- gcc/doc/tm.texi.in
    +++ gcc/doc/tm.texi.in
    @@ -7374,7 +7374,7 @@ Internally, address spaces are represented as a small 
integer in the
     range 0 to 15 with address space 0 being reserved for the generic
     address space.
     
    -To register a named address space qualifier keyword with the C front end,
    +To register a named address space qualifier keyword for GNU C and GNU C++,
     the target may call the @code{c_register_addr_space} routine.  For example,
     the SPU port uses the following to declare @code{__ea} as the keyword for
     named address space #1:

(For avoidance of doubt: 'C_SET_RID_CODE (id, rid);' remains valid for
both the C and C++ front ends.)

For simplicity of the patch, I've not changed the 'c_' prefix of
'c_register_addr_space', to make it generic ('register_named_addr_space'
maybe?), but I'm happy to do that, if that's better?


Grüße
 Thomas


>From d7f218e5120826382919f3c4528c9809c3717971 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <[email protected]>
Date: Thu, 18 Jun 2026 19:46:31 +0200
Subject: [PATCH] c++: parser - Support for target address spaces in C++:
 'c_register_addr_space'

The original C front end 'c_register_addr_space' code had:

    C_IS_RESERVED_WORD (id) = 1;

Now we're using:

    TREE_LANG_FLAG_0 (id) = 1;

(That's the 'gcc/c/c-tree.h' definition of 'C_IS_RESERVED_WORD' expanded.)

That happens to work for C++ front end, but only by chance; as of
Subversion r249571 (Git commit 84c0088f38ce49f390401d11a581cd1a57a008d5)
"Reorder IDENTIFIER flags", the correct incantation for the C++ front end
is:

    set_identifier_kind (id, cik_keyword);

Therefore, 'c_register_addr_space' can no longer be in
'gcc/c-family/c-common.cc' (at least not without further surgery), and so
I'm restoring the original definitions in 'gcc/c/c-decl.cc' and
'gcc/cp/tree.cc', and then implement it properly in the latter.

(For avoidance of doubt: 'C_SET_RID_CODE (id, rid);' remains valid for
both the C and C++ front ends.)

For simplicity of the patch, I've not changed the 'c_' prefix of
'c_register_addr_space', to make it generic ('register_named_addr_space'
maybe?), but I'm happy to do that, if that's better?
---
 gcc/c-family/c-common.cc | 19 -------------------
 gcc/c-family/c-common.h  |  4 +++-
 gcc/c/c-decl.cc          | 19 +++++++++++++++++++
 gcc/cp/tree.cc           | 19 +++++++++++++++++++
 gcc/doc/tm.texi          |  2 +-
 gcc/doc/tm.texi.in       |  2 +-
 6 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 5c7ab0c1fa13..441463dc8a85 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -2926,25 +2926,6 @@ 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);
-  TREE_LANG_FLAG_0 (id) = 1;
-  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 90f81616b5b3..234c18677cc5 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -841,6 +841,9 @@ 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.  */
+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);
@@ -995,7 +998,6 @@ 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);
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 37db0a7e62e4..1b2f2b4edece 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -13867,6 +13867,25 @@ c_parse_final_cleanups (void)
   ext_block = NULL;
 }
 
+/* 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_IS_RESERVED_WORD (id) = 1;
+  ridpointers [rid] = id;
+}
+
 /* Return identifier to look up for omp declare reduction.  */
 
 tree
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 2034782a373b..77f2c7161b6f 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -6999,6 +6999,25 @@ cp_free_lang_data (tree t)
     DECL_CHAIN (t) = NULL_TREE;
 }
 
+/* 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);
+  set_identifier_kind (id, cik_keyword);
+  ridpointers [rid] = id;
+}
+
 /* Return the number of operands in T that we care about for things like
    mangling.  */
 
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 3ea366e13993..46449d1c9a36 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -11488,7 +11488,7 @@ Internally, address spaces are represented as a small integer in the
 range 0 to 15 with address space 0 being reserved for the generic
 address space.
 
-To register a named address space qualifier keyword with the C front end,
+To register a named address space qualifier keyword for GNU C and GNU C++,
 the target may call the @code{c_register_addr_space} routine.  For example,
 the SPU port uses the following to declare @code{__ea} as the keyword for
 named address space #1:
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 12700e4ad8a4..97d62e111ad4 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -7374,7 +7374,7 @@ Internally, address spaces are represented as a small integer in the
 range 0 to 15 with address space 0 being reserved for the generic
 address space.
 
-To register a named address space qualifier keyword with the C front end,
+To register a named address space qualifier keyword for GNU C and GNU C++,
 the target may call the @code{c_register_addr_space} routine.  For example,
 the SPU port uses the following to declare @code{__ea} as the keyword for
 named address space #1:
-- 
2.34.1

Reply via email to