[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 0/3] yacc: compute the best type for the state number
From: |
Akim Demaille |
Subject: |
Re: [PATCH 0/3] yacc: compute the best type for the state number |
Date: |
Sun, 6 Oct 2019 13:57:02 +0200 |
> Le 5 oct. 2019 à 09:28, Akim Demaille <address@hidden> a écrit :
>
> I can't wait: these errors are blocking from me from pushing other changes
> that I was about to send.
With the appended commits, the CI is green again, and I was able to push my
other changes.
commit 4246cd81df3101b1abef3f5914f6b3fa7d1b44de
Author: Akim Demaille <address@hidden>
Date: Sat Oct 5 17:28:51 2019 +0200
tests: avoid a GCC 4.8 warning
GCC 4.8 reports:
input.y:57:33: error: conversion to 'int' from 'long unsigned int'
may alter its value [-Werror=conversion]
int input_elts = sizeof input / sizeof input[0];
^
* tests/local.at (AT_YYLEX_DEFINE(c)): Add a cast (sorry, Paul!).
diff --git a/tests/local.at b/tests/local.at
index 17759b2f..579b85c3 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -558,7 +558,7 @@ static
static int toknum = 0;
int res;
]AT_USE_LEX_ARGS[
- int input_elts = sizeof input / sizeof input[0];
+ int input_elts = (int) (sizeof input / sizeof input[0]);
(void) input_elts;
assert (0 <= toknum && toknum < input_elts);
res = input[toknum++];
commit 5973d763c0867924830fa90f6560078f745d45a7
Author: Akim Demaille <address@hidden>
Date: Sat Oct 5 17:35:40 2019 +0200
yacc.c: work around warnings from Clang++ 3.3 and 3.4
When we run the test suite with these C++ compilers to compile C code,
we get:
239. synclines.at:440: testing syncline escapes: yacc.c ...
../../tests/synclines.at:440: $CC $CFLAGS $CPPFLAGS \"\\\"\".c -o
\"\\\"\" ||
exit 77
stderr:
stdout:
../../tests/synclines.at:440: COLUMNS=1000; export COLUMNS; bison
--color=no -fno-caret -o \"\\\"\".c \"\\\"\".y
../../tests/synclines.at:440: $CC $CFLAGS $CPPFLAGS $LDFLAGS -o
\"\\\"\" \"\\\"\".c $LIBS
stderr:
"\"".c:1102:41: error: implicit conversion loses integer precision:
'long' to 'int' [-Werror,-Wshorten-64-to-32]
YYPTRDIFF_T yysize = yyssp - yyss + 1;
~~~~~~ ~~~~~~~~~~~~~^~~
1 error generated.
193. conflicts.at:545: testing parse.error=verbose and consistent
errors: lr.type=canonical-lr parse.lac=full ...
input.c:737:75: error: implicit conversion loses integer precision:
'long' to 'int'
[-Werror,-Wshorten-64-to-32]
YYPTRDIFF_T yysize_old = *yytop == yytop_empty ? 0 : *yytop -
*yybottom + 1;
~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~^~~
input.c:901:48: error: implicit conversion loses integer precision:
'long' to 'int'
[-Werror,-Wshorten-64-to-32]
YYPTRDIFF_T yysize = yyesp - *yyes + 1;
~~~~~~ ~~~~~~~~~~~~~~^~~
* data/skeletons/yacc.c: Add more casts.
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index fdf4ba6d..e4705735 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -856,7 +856,8 @@ yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T
yyadd,
yy_state_num *yybottom_no_free,
yy_state_num **yytop, yy_state_num *yytop_empty)
{
- YYPTRDIFF_T yysize_old = *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
+ YYPTRDIFF_T yysize_old =
+ *yytop == yytop_empty ? 0 : (YYPTRDIFF_T) (*yytop - *yybottom + 1);
YYPTRDIFF_T yysize_new = yysize_old + yyadd;
if (*yycapacity < yysize_new)
{
@@ -1023,7 +1024,7 @@ yy_lac (yy_state_num *yyesa, yy_state_num **yyes,
YYDPRINTF ((stderr, " R%d", yyrule - 1));
if (yyesp != yyes_prev)
{
- YYPTRDIFF_T yysize = yyesp - *yyes + 1;
+ YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyesp - *yyes + 1);
if (yylen < yysize)
{
yyesp -= yylen;
@@ -1534,7 +1535,7 @@ yysetstate:
#else
{
/* Get the current used size of the three stacks, in elements. */
- YYPTRDIFF_T yysize = yyssp - yyss + 1;
+ YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyssp - yyss + 1);
# if defined yyoverflow
{
commit 32e5a91a91bc034a3f596c056569c0eaa09ca7e1
Author: Akim Demaille <address@hidden>
Date: Sat Oct 5 22:51:16 2019 +0200
yacc.c: work around warnings from G++ 4.8
input.c: In function 'int yyparse()':
input.c: error: conversion to 'long int' from 'long unsigned int'
may change the sign of the result [-Werror=sign-conversion]
yyes_capacity = sizeof yyesa / sizeof *yyes;
^
cc1plus: all warnings being treated as errors
* data/skeletons/yacc.c: here.
diff --git a/TODO b/TODO
index f0ec27da..d99954e0 100644
--- a/TODO
+++ b/TODO
@@ -128,6 +128,25 @@ Rename these guys as "diagnostics.*" (or "diagnose.*"),
since that's the
name they have in gcc, clang, etc. Likewise for the complain_* series of
functions.
+* Modernization
+Remove some casts made for old compilers, such as Clang++ 3.3 and 3.4 when
+compiling yacc.c code:
+
+ YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyssp - yyss + 1);
+
+ YYPTRDIFF_T yysize_old =
+ *yytop == yytop_empty ? 0 : (YYPTRDIFF_T) (*yytop - *yybottom + 1);
+
+ YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyesp - *yyes + 1);
+
+Or G++ 4.8
+
+ yyes_capacity = (YYPTRDIFF_T) (sizeof yyesa / sizeof *yyes);
+
+Or GCC 4.8
+
+ int input_elts = (int) (sizeof input / sizeof input[0]);
+
* Completion
Several features are not available in all the backends.
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index e4705735..abe20a5f 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -1154,10 +1154,10 @@ yytnamerr (char *yyres, const char *yystr)
do_not_strip_quotes: ;
}
- if (! yyres)
+ if (yyres)
+ return (YYPTRDIFF_T) (yystpcpy (yyres, yystr) - yyres);
+ else
return yystrlen (yystr);
-
- return yystpcpy (yyres, yystr) - yyres;
}
# endif
@@ -1490,7 +1490,7 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[
yystacksize = YYINITDEPTH;]b4_lac_if([[
yyes = yyesa;
- yyes_capacity = sizeof yyesa / sizeof *yyes;
+ yyes_capacity = (YYPTRDIFF_T) (sizeof yyesa / sizeof *yyes);
if (YYMAXDEPTH < yyes_capacity)
yyes_capacity = YYMAXDEPTH;]])[
- Re: [PATCH 0/3] yacc: compute the best type for the state number, (continued)
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Kaz Kylheku, 2019/10/02
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Paul Eggert, 2019/10/02
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Akim Demaille, 2019/10/03
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Paul Eggert, 2019/10/03
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Akim Demaille, 2019/10/03
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Akim Demaille, 2019/10/04
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Akim Demaille, 2019/10/05
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Paul Eggert, 2019/10/05
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Akim Demaille, 2019/10/05
- Re: [PATCH 0/3] yacc: compute the best type for the state number,
Akim Demaille <=
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Paul Eggert, 2019/10/06
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Paul Eggert, 2019/10/05
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Akim Demaille, 2019/10/05
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Paul Eggert, 2019/10/05
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Paul Eggert, 2019/10/05
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Akim Demaille, 2019/10/05
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Akim Demaille, 2019/10/05
- Re: [PATCH 0/3] yacc: compute the best type for the state number, Paul Eggert, 2019/10/05
Re: [PATCH 0/3] yacc: compute the best type for the state number, Paul Eggert, 2019/10/05