]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Fix parser error on address space names [PR 123583]
authorSenthil Kumar Selvaraj <saaadhu@gcc.gnu.org>
Wed, 28 Jan 2026 08:29:55 +0000 (13:59 +0530)
committerSenthil Kumar Selvaraj <saaadhu@gcc.gnu.org>
Wed, 28 Jan 2026 14:05:44 +0000 (19:35 +0530)
This patch fixes a regression introduced by PR 67784
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67784) - it broke
recognition of named address space qualifiers (such as __memx on
AVR or __seg_gs on x86) after certain statements.

The fix for PR 67784 attempts to reclassify tokens whose
token->id_kind could have been set incorrectly (because of possibly
wrong scope when peeking ahead). c_parser_maybe_reclassify_token
only skips reclassification for C_ID_CLASSNAME though - a token with
id_kind = C_ID_ADDRSPACE ends up getting reclassified as C_ID_ID,
eventually causing a ": error: '<address space name>' undeclared"
error later down the line.

Rather than explicitly excluding C_ID_ADDRSPACE, the patch modifies
the check to reclassify only tokens kinds that could potentially get
incorrectly classified - C_ID_ID and C_ID_TYPENAME.

Bootstrapped and regtested on x86_64-linux.

PR c/123583

gcc/c/ChangeLog:

* c-parser.cc (c_parser_maybe_reclassify_token): Reclassify only
C_ID_ID and C_ID_TYPENAME tokens.

gcc/testsuite/ChangeLog:

* gcc.target/avr/pr123583.c: New test.
* gcc.target/i386/pr123583.c: New test.

gcc/c/c-parser.cc
gcc/testsuite/gcc.target/avr/pr123583.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr123583.c [new file with mode: 0644]

index 2949681663bf031ce0ef35bc48054ff68cae2b26..5ab3d84ea80cc3e7ccf2ff6f5635ada9302804d3 100644 (file)
@@ -2323,7 +2323,7 @@ c_parser_maybe_reclassify_token (c_parser *parser)
     {
       c_token *token = c_parser_peek_token (parser);
 
-      if (token->id_kind != C_ID_CLASSNAME)
+      if (token->id_kind == C_ID_ID || token->id_kind == C_ID_TYPENAME)
        {
          tree decl = lookup_name (token->value);
 
diff --git a/gcc/testsuite/gcc.target/avr/pr123583.c b/gcc/testsuite/gcc.target/avr/pr123583.c
new file mode 100644 (file)
index 0000000..1a6881b
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile { target { ! avr_tiny } } } */
+/* { dg-additional-options "-std=gnu99 -w" } */
+
+void h() {
+    if(1)
+      ;
+  __memx const int *x = 0;
+}
+
diff --git a/gcc/testsuite/gcc.target/i386/pr123583.c b/gcc/testsuite/gcc.target/i386/pr123583.c
new file mode 100644 (file)
index 0000000..4a72407
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-std=gnu99 -w" } */
+
+void h() {
+    if(1)
+      ;
+  __seg_gs const int *x = 0;
+}