[PATCH] glr2.cc: bug in ~glr_state if YYDEBUG is 0
Sergei Kurtov <[email protected]> Wed, 26 Mar 2025 22:37:52 +0700
| Newsgroups | gmane.comp.parsers.bison.patches |
|---|---|
| Message-ID | <CAE1vwgfH5svsN7kaP3omieR_aeNcuoRk9VJ7bP2DZJPa+MERiA@mail.gmail.com> |
--000000000000b055b10631409f3a
Content-Type: text/plain; charset="UTF-8"
Hello,
A problem was detected.
If
%define parse.trace
is not specified in the grammar file then
the assertion is failed in value_type::~value_type.
Bison version: 3.8.2
Command-line:
bison -d -o @OUTPUT0@ --header=@OUTPUT1@ @INPUT@ --verbose
Grammar file:
%skeleton "glr2.cc"
%glr-parser
%language "c++"
%define api.value.type variant
%define api.token.constructor
%define parse.assert
%locations
%define parse.error verbose
In the generated parser, usually
value_type::destroy
is called before
value_type::~value_type
Otherwise, the assertion in value_type::~value_type may fail.
Incorrect behavior occurs in ~glr_state after initialization of
symbol_kind_type yykind = yy_accessing_symbol (yylrState);
The value of yykind is 0 (because yylrState is 0) and in the following
switch (yykind)
it goes to the 'default' were yyval.destroy is not called.
The correct value to yylrState is assigned in yyfillin,
but this happens if '%define parse.trace' was specified:
#if YYDEBUG
yys.yylrState = s->yylrState;
#endif
The following fix to glr2.cc resolves the problem.
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -1913,9 +1913,7 @@
for (int i = yylow0-1; i >= yylow1; i -= 1, s = s->pred())
{
glr_state& yys = yyvsp[i].getState();
-#if ]b4_api_PREFIX[DEBUG
yys.yylrState = s->yylrState;
-#endif
yys.yyresolved = s->yyresolved;
if (s->yyresolved)
{]b4_variant_if([[
--000000000000b055b10631409f3a
Content-Type: application/octet-stream; name="glr2.cc.patch"
Content-Disposition: attachment; filename="glr2.cc.patch"
Content-Transfer-Encoding: base64
Content-ID: <f_m8q31ym10>
X-Attachment-Id: f_m8q31ym10
LS0tIGEvZGF0YS9za2VsZXRvbnMvZ2xyMi5jYworKysgYi9kYXRhL3NrZWxldG9ucy9nbHIyLmNj
CkBAIC0xOTEzLDkgKzE5MTMsNyBAQAogICAgICAgZm9yIChpbnQgaSA9IHl5bG93MC0xOyBpID49
IHl5bG93MTsgaSAtPSAxLCBzID0gcy0+cHJlZCgpKQogICAgICAgICB7CiAgICAgICAgICAgZ2xy
X3N0YXRlJiB5eXMgPSB5eXZzcFtpXS5nZXRTdGF0ZSgpOwotI2lmIF1iNF9hcGlfUFJFRklYW0RF
QlVHCiAgICAgICAgICAgeXlzLnl5bHJTdGF0ZSA9IHMtPnl5bHJTdGF0ZTsKLSNlbmRpZgogICAg
ICAgICAgIHl5cy55eXJlc29sdmVkID0gcy0+eXlyZXNvbHZlZDsKICAgICAgICAgICBpZiAocy0+
eXlyZXNvbHZlZCkKICAgICAgICAgICAgIHtdYjRfdmFyaWFudF9pZihbWwo=
--000000000000b055b10631409f3a--