[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bug in glr2.cc
From: |
Jot Dot |
Subject: |
Bug in glr2.cc |
Date: |
Fri, 24 Dec 2021 15:38:52 -0700 (MST) |
I think I have found a bug when using glr2.cc
This does not occur when I switch to glr.cc
I am using:
bison (GNU Bison) 3.8.2
I have included my parser.y which causes a crash in the
generated parser code when I use certain input data.
The program crashes in yyremoveDeletes() on this line:
yylookaheadNeeds[j] = yylookaheadNeeds[i];
The vector 'yylookaheadNeeds' has size zero and the variable "i" is zero as
well,
thus a subscript out of range error occurs.
The relevant stack trace shows:
genCompileTest.exe!std::vector<bool,std::allocator<bool>>::operator[](unsigned
__int64 _Off) Line 2779 C++
genCompileTest.exe!`anonymous namespace'::glr_state_set::yyremoveDeletes() Line
959 C++
genCompileTest.exe!`anonymous namespace'::state_stack::reduceToOneStack() Line
1513 C++
genCompileTest.exe!gen::Parser::glr_stack::yyrecoverSyntaxError(gen::location *
yylocp) Line 2158 C++
genCompileTest.exe!gen::Parser::glr_stack::parse() Line 2034 C++
genCompileTest.exe!gen::Parser::parse() Line 3113 C++
.
.
[External Code]
I have spent a couple of hours slowly reducing my grammar to the point
where it is about as small as I can make it.
With the attached grammar, bison reports:
1>parser.y : warning : 2 shift/reduce conflicts [-Wconflicts-sr]
1>parser.y : warning : 2 reduce/reduce conflicts [-Wconflicts-rr]
It crashes with the input:
foo (*(*bar)())[]
[0:12-13] Error: syntax error, unexpected '(', expecting ')'
(Note: Yes, I know if 'foo' is a valid type, then the line should have been
valid grammar - that's why I was debugging it.)
If I comment out line 100 in the grammar file, I get:
1>parser.y : warning : 1 shift/reduce conflict [-Wconflicts-sr]
1>parser.y : warning : 2 reduce/reduce conflicts [-Wconflicts-rr]
The app doesn't crash anymore:
foo (*(*bar)())[]
[0:12-13] Error: syntax error, unexpected '(', expecting ')'
If we leave line 100 uncommented but comment out line 135 instead, we still
have 2 S/R and 2 R/R but the program runs as above without crashing.
(I have placed comments at the end of those two lines for easy locating.)
I think this is as far as I can go.
Oh, btw: Seasons Greetings? Happy Holidays? Merry Christmas? (pick one or add
one)
Sorry to find it today (Dec 24) as this is a busy time for many people.
Thanks
jotdot
PS: Ignore the mess in my yylex code - if you recall (Akim) I modified
it to pass information to my %merge routines instead of passing data
with global variables. Right now, in this sample code, I do not use
the %merge feature (but was planning on reintroducing it after).
I could remove this mess if we were able to make the %merge routines
as members of the Parser class. hint hint - just a gentle nudge :)
parser.y
Description: Text Data
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Bug in glr2.cc,
Jot Dot <=