bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 05/22] tables: avoid warnings and save bits


From: Akim Demaille
Subject: [PATCH 05/22] tables: avoid warnings and save bits
Date: Sat, 23 Jan 2021 15:55:44 +0100

The yydefgoto table uses -1 as an invalid for an impossible case (we
never use yydefgoto[0], since it corresponds to the reduction to
$accept, which never happens).  Since yydefgoto is a table of state
numbers, this -1 forces a signed type uselessly, which (1) might
trigger compiler warnings when storing a value from yydefgoto into a
state number (nonnegative), and (2) wastes bits which might result in
using a int16 where a uint8 suffices.

Reported by Jot Dot <jotdot@shaw.ca>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00027.html

* src/tables.c (default_goto): Use 0 rather than -1 as invalid value.
* tests/regression.at: Adjust.
---
 src/parse-gram.c    | 26 +++++++++++++++++++-------
 src/parse-gram.h    |  2 +-
 src/tables.c        |  9 ++++++++-
 tests/regression.at |  2 +-
 4 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/src/parse-gram.c b/src/parse-gram.c
index cfca03b53..3071f8038 100644
--- a/src/parse-gram.c
+++ b/src/parse-gram.c
@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 3.7.3.7-d831b.  */
+/* A Bison parser, made by GNU Bison 3.7.4.6-89d2b-dirty.  */
 
 /* Bison implementation for Yacc-like parsers in C
 
@@ -45,11 +45,11 @@
    define necessary library symbols; they are noted "INFRINGES ON
    USER NAME SPACE" below.  */
 
-/* Identify Bison output.  */
-#define YYBISON 30703
+/* Identify Bison output, and Bison version.  */
+#define YYBISON 30704
 
-/* Bison version.  */
-#define YYBISON_VERSION "3.7.3.7-d831b"
+/* Bison version string.  */
+#define YYBISON_VERSION "3.7.4.6-89d2b-dirty"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
@@ -365,6 +365,18 @@ typedef int_least16_t yytype_int16;
 typedef short yytype_int16;
 #endif
 
+/* Work around bug in HP-UX 11.23, which defines these macros
+   incorrectly for preprocessor constants.  This workaround can likely
+   be removed in 2023, as HPE has promised support for HP-UX 11.23
+   (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
+   <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>.  */
+#ifdef __hpux
+# undef UINT_LEAST8_MAX
+# undef UINT_LEAST16_MAX
+# define UINT_LEAST8_MAX 255
+# define UINT_LEAST16_MAX 65535
+#endif
+
 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
@@ -791,9 +803,9 @@ static const yytype_int16 yypgoto[] =
 };
 
   /* YYDEFGOTO[NTERM-NUM].  */
-static const yytype_int16 yydefgoto[] =
+static const yytype_uint8 yydefgoto[] =
 {
-      -1,     1,     2,    43,    82,   115,    77,    45,    84,    46,
+       0,     1,     2,    43,    82,   115,    77,    45,    84,    46,
       50,    49,    47,   156,   120,   121,   122,    97,    93,    94,
       95,   128,   141,    87,    88,    89,    55,    56,    78,    79,
       80,   135,   144,   145,   113,    63,   106,    57,    81,    58,
diff --git a/src/parse-gram.h b/src/parse-gram.h
index ad4534ff8..fcab0ce62 100644
--- a/src/parse-gram.h
+++ b/src/parse-gram.h
@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 3.7.3.7-d831b.  */
+/* A Bison parser, made by GNU Bison 3.7.4.6-89d2b-dirty.  */
 
 /* Bison interface for Yacc-like parsers in C
 
diff --git a/src/tables.c b/src/tables.c
index 052e96e6f..d26a4a971 100644
--- a/src/tables.c
+++ b/src/tables.c
@@ -512,7 +512,14 @@ default_goto (symbol_number sym, size_t state_count[])
 {
   const goto_number begin = goto_map[sym - ntokens];
   const goto_number end = goto_map[sym - ntokens + 1];
-  state_number res = -1;
+
+  /* In the case this symbol is never reduced to ($accept), use state
+     0.  We used to use -1, but as a result the yydefgoto table must
+     be signed, which (1) might trigger compiler warnings when storing
+     a value from yydefgoto into a state number (nonnegative), and (2)
+     wastes bits which might result in using a int16 where a uint8
+     suffices. */
+  state_number res = 0;
 
   if (begin != end)
     {
diff --git a/tests/regression.at b/tests/regression.at
index 099b39a09..20b5f7395 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -737,7 +737,7 @@ static const yytype_int8 yypgoto[] =
 };
 static const yytype_int8 yydefgoto[] =
 {
-      -1,     2,     3,     4,     8
+       0,     2,     3,     4,     8
 };
 static const yytype_int8 yytable[] =
 {
-- 
2.30.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]