mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
glr.c: beware of portability issues with PTRDIFF_MAX
For instance test 386, "glr.cc api.value.type={double}":
types.at:366: $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o test test.cc $LIBS
stderr:
test.cc: In function 'ptrdiff_t yysplitStack(yyGLRStack*, ptrdiff_t)':
test.cc:490:4: error: 'PTRDIFF_MAX' was not declared in this scope
(PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : YY_CAST (ptrdiff_t, SIZE_MAX))
^
test.cc:1805:37: note: in expansion of macro 'YYSIZEMAX'
ptrdiff_t half_max_capacity = YYSIZEMAX / 2 / state_size;
^~~~~~~~~
test.cc:490:4: note: suggested alternative: '__PTRDIFF_MAX__'
(PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : YY_CAST (ptrdiff_t, SIZE_MAX))
^
test.cc:1805:37: note: in expansion of macro 'YYSIZEMAX'
ptrdiff_t half_max_capacity = YYSIZEMAX / 2 / state_size;
^~~~~~~~~
The failing tests are using glr.cc only, which I don't understand, the
problem is rather in glr.c, so I would expect glr.c tests to also fail.
Reported by Bruno Haible.
https://lists.gnu.org/archive/html/bug-bison/2020-05/msg00053.html
* data/skeletons/yacc.c: Move the block that defines
YYPTRDIFF_T/YYPTRDIFF_MAXIMUM, YYSIZE_T/YYSIZE_MAXIMUM, and
YYSIZEOF to...
* data/skeletons/c.m4 (b4_sizes_types_define): Here.
(b4_c99_int_type): Also take care of the #undefinition of short.
* data/skeletons/yacc.c, data/skeletons/glr.c: Use
b4_sizes_types_define.
* data/skeletons/glr.c: Adjust to use YYPTRDIFF_T/YYPTRDIFF_MAXIMUM,
YYSIZE_T/YYSIZE_MAXIMUM.
This commit is contained in:
@@ -205,7 +205,11 @@ m4_define([b4_c99_int_type],
|
||||
# Define private types suitable for holding small integers in C99 or later.
|
||||
m4_define([b4_c99_int_type_define],
|
||||
[m4_copy_force([b4_c99_int_type], [b4_int_type])dnl
|
||||
[/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
|
||||
[#ifdef short
|
||||
# undef short
|
||||
#endif
|
||||
|
||||
/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
|
||||
<limits.h> and (if available) <stdint.h> are included
|
||||
so that the code can choose integer types of a good width. */
|
||||
|
||||
@@ -261,6 +265,50 @@ typedef int yytype_uint16;
|
||||
#endif]])
|
||||
|
||||
|
||||
# b4_sizes_types_define
|
||||
# ---------------------
|
||||
# Define YYPTRDIFF_T/YYPTRDIFF_MAXIMUM, YYSIZE_T/YYSIZE_MAXIMUM,
|
||||
# and YYSIZEOF.
|
||||
m4_define([b4_sizes_types_define],
|
||||
[[#ifndef YYPTRDIFF_T
|
||||
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
|
||||
# define YYPTRDIFF_T __PTRDIFF_TYPE__
|
||||
# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
|
||||
# elif defined PTRDIFF_MAX
|
||||
# ifndef ptrdiff_t
|
||||
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
|
||||
# endif
|
||||
# define YYPTRDIFF_T ptrdiff_t
|
||||
# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
|
||||
# else
|
||||
# define YYPTRDIFF_T long
|
||||
# define YYPTRDIFF_MAXIMUM LONG_MAX
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef YYSIZE_T
|
||||
# ifdef __SIZE_TYPE__
|
||||
# define YYSIZE_T __SIZE_TYPE__
|
||||
# elif defined size_t
|
||||
# define YYSIZE_T size_t
|
||||
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
|
||||
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
|
||||
# define YYSIZE_T size_t
|
||||
# else
|
||||
# define YYSIZE_T unsigned
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define YYSIZE_MAXIMUM \
|
||||
YY_CAST (YYPTRDIFF_T, \
|
||||
(YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
|
||||
? YYPTRDIFF_MAXIMUM \
|
||||
: YY_CAST (YYSIZE_T, -1)))
|
||||
|
||||
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
|
||||
]])
|
||||
|
||||
|
||||
# b4_int_type_for(NAME)
|
||||
# ---------------------
|
||||
# Return a narrow int type able to handle numbers ranging from
|
||||
|
||||
Reference in New Issue
Block a user