Hi,
This patch fixes a regression introduced by PR 67784
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67784), where named
address space qualifiers (such as __memx on AVR or __seg_gs on x86)
cause a parser error if they occur in certain positions.
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, I figured the only
token kinds in c_id_kind that could get incorrectly classified are C_ID_ID
and C_ID_TYPENAME, so the patch modifies the check to reclassify only
those two token kinds.
Bootstrapped and regtested on x86_64-linux.
Ok for master?
Regards
Senthil
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.
diff --git gcc/c/c-parser.cc gcc/c/c-parser.cc
index 2949681663b..5ab3d84ea80 100644
--- gcc/c/c-parser.cc
+++ gcc/c/c-parser.cc
@@ -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 gcc/testsuite/gcc.target/avr/pr123583.c
gcc/testsuite/gcc.target/avr/pr123583.c
new file mode 100644
index 00000000000..1a6881ba56b
--- /dev/null
+++ gcc/testsuite/gcc.target/avr/pr123583.c
@@ -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 gcc/testsuite/gcc.target/i386/pr123583.c
gcc/testsuite/gcc.target/i386/pr123583.c
new file mode 100644
index 00000000000..4a724073d7a
--- /dev/null
+++ gcc/testsuite/gcc.target/i386/pr123583.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-std=gnu99 -w" } */
+
+void h() {
+ if(1)
+ ;
+ __seg_gs const int *x = 0;
+}