public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-2350] GTY: Repair 'enum gty_token', 'token_names' desynchronization
@ 2023-07-06 10:03 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-07-06 10:03 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:da5f6d9c88c3b6fd505fed06359e344b2892528d
commit r14-2350-gda5f6d9c88c3b6fd505fed06359e344b2892528d
Author: Thomas Schwinge <thomas@codesourcery.com>
Date: Wed Jul 5 11:10:55 2023 +0200
GTY: Repair 'enum gty_token', 'token_names' desynchronization
For example, for the following (made-up) changes:
--- gcc/ggc-tests.cc
+++ gcc/ggc-tests.cc
@@ -258 +258 @@ class GTY((tag("1"))) some_subclass : public example_base
-class GTY((tag("2"))) some_other_subclass : public example_base
+class GTY((tag(user))) some_other_subclass : public example_base
@@ -384 +384 @@ test_chain_next ()
-struct GTY((user)) user_struct
+struct GTY((user user)) user_struct
..., we get unexpected "have a param<N>_is option" diagnostics:
[...]
build/gengtype \
-S [...]/source-gcc/gcc -I gtyp-input.list -w tmp-gtype.state
[...]/source-gcc/gcc/ggc-tests.cc:258: parse error: expected a string constant, have a param<N>_is option
[...]/source-gcc/gcc/ggc-tests.cc:384: parse error: expected ')', have a param<N>_is option
make[2]: *** [Makefile:2888: s-gtype] Error 1
[...]
This traces back to 2012 "Support garbage-collected C++ templates", which got
incorporated in commit 0823efedd0fb8669b7e840954bc54c3b2cf08d67
(Subversion r190402), which did add 'USER_GTY' to what nowadays is known as
'enum gty_token', but didn't accordingly update
'gcc/gengtype-parse.c:token_names', leaving those out of sync. Updating
'gcc/gengtype-parse.c:token_value_format' wasn't necessary, as:
/* print_token assumes that any token >= FIRST_TOKEN_WITH_VALUE may have
a meaningful value to be printed. */
FIRST_TOKEN_WITH_VALUE = PARAM_IS
This, in turn, got further confused -- or "fixed" -- by later changes:
2014 commit 63f5d5b818319129217e41bcb23db53f99ff11b0 (Subversion r218558)
"remove gengtype support for param_is use_param, if_marked and splay tree allocators",
which reciprocally missed corresponding clean-up.
With that addressed via adding the missing '"user"' to 'token_names', and,
until that is properly fixed, a temporary 'UNUSED_PARAM_IS' (re-)added for use
with 'FIRST_TOKEN_WITH_VALUE', we then get the expected:
[...]/source-gcc/gcc/ggc-tests.cc:258: parse error: expected a string constant, have 'user'
[...]/source-gcc/gcc/ggc-tests.cc:384: parse error: expected ')', have 'user'
gcc/
* gengtype-parse.cc (token_names): Add '"user"'.
* gengtype.h (gty_token): Add 'UNUSED_PARAM_IS' for use with
'FIRST_TOKEN_WITH_VALUE'.
Diff:
---
gcc/gengtype-parse.cc | 3 +++
gcc/gengtype.h | 5 ++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/gcc/gengtype-parse.cc b/gcc/gengtype-parse.cc
index 19184d77899..2efbda04946 100644
--- a/gcc/gengtype-parse.cc
+++ b/gcc/gengtype-parse.cc
@@ -69,6 +69,7 @@ advance (void)
/* Diagnostics. */
/* This array is indexed by the token code minus CHAR_TOKEN_OFFSET. */
+/* Keep in sync with 'gengtype.h:enum gty_token'. */
static const char *const token_names[] = {
"GTY",
"typedef",
@@ -80,6 +81,7 @@ static const char *const token_names[] = {
"...",
"ptr_alias",
"nested_ptr",
+ "user",
"a param<N>_is option",
"a number",
"a scalar type",
@@ -91,6 +93,7 @@ static const char *const token_names[] = {
};
/* This array is indexed by token code minus FIRST_TOKEN_WITH_VALUE. */
+/* Keep in sync with 'gengtype.h:enum gty_token'. */
static const char *const token_value_format[] = {
"%s",
"'%s'",
diff --git a/gcc/gengtype.h b/gcc/gengtype.h
index 4e5df544fbf..2122373edf2 100644
--- a/gcc/gengtype.h
+++ b/gcc/gengtype.h
@@ -458,6 +458,8 @@ extern void parse_file (const char *name);
extern bool hit_error;
/* Token codes. */
+/* Keep 'gengtype-parse.cc:token_names', 'gengtype-parse.cc:token_value_format'
+ in sync. */
enum gty_token
{
EOF_TOKEN = 0,
@@ -476,6 +478,7 @@ enum gty_token
PTR_ALIAS,
NESTED_PTR,
USER_GTY,
+ UNUSED_PARAM_IS,
NUM,
SCALAR,
ID,
@@ -486,7 +489,7 @@ enum gty_token
/* print_token assumes that any token >= FIRST_TOKEN_WITH_VALUE may have
a meaningful value to be printed. */
- FIRST_TOKEN_WITH_VALUE = USER_GTY
+ FIRST_TOKEN_WITH_VALUE = UNUSED_PARAM_IS
};
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-06 10:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 10:03 [gcc r14-2350] GTY: Repair 'enum gty_token', 'token_names' desynchronization Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).