-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bison crash on counterexamples report #71
Comments
This is the grammar file: // parser.yc
%left IDENTIFIER
%left '-'
%%
Start
: '(' FunctionFormalParList IDENTIFIER {}
;
FunctionFormalParList
: FunctionFormalPar {}
| FunctionFormalParList ',' FunctionFormalPar {}
;
FunctionFormalPar
: IDENTIFIER IDENTIFIER ":=" SingleExpression {}
| IDENTIFIER IDENTIFIER ":=" '-' {}
;
IdOrIdId
: IDENTIFIER {}
;
TypeParams_front
: '<' IDENTIFIER {}
;
ActualParams_back
: ActualParList ')' {}
;
ActualParList
: SingleExpression {}
| ActualParList ',' SingleExpression {}
;
SingleExpression
: SingleExpression '<' SingleExpression {}
| '-' SingleExpression {}
| IDENTIFIER {}
| IdOrIdId TypeParams_front ">(" ActualParams_back {}
; I noticed couple things There is no crash if either of the %left directives is commented out - also there is no crash if the IdOrIdId rule is removed - of course both these changes require some minor adjustments for bison to work $ bison --report=counterexamples -Wcounterexamples parser.yc
parser.yc: warning: 3 shift/reduce conflicts [-Wconflicts-sr]
parser.yc: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
parser.yc: warning: reduce/reduce conflict on token '<' [-Wcounterexamples]
Example: IDENTIFIER •
First reduce derivation
IdOrIdId
↳ 6: IDENTIFIER •
Second reduce derivation
SingleExpression
↳ 13: IDENTIFIER •
parser.yc: warning: shift/reduce conflict on token IDENTIFIER [-Wcounterexamples]
Productions leading up to the conflict state found. Still finding a possible unifying counterexample...time limit exceeded: 6.000000
First example: ":=" '-' • IDENTIFIER SingleExpression IDENTIFIER
Shift derivation
Start
↳ 1: ":=" FunctionFormalParList IDENTIFIER
↳ 2: FunctionFormalPar
↳ 4: '-' IdOrIdId SingleExpression
↳ 6: • IDENTIFIER
Second example: IDENTIFIER IDENTIFIER ":=" '-' • IDENTIFIER
Reduce derivation
Start
↳ 1: FunctionFormalParList IDENTIFIER
↳ 2: FunctionFormalPar
↳ 5: IDENTIFIER IDENTIFIER ":=" '-' •
parser.yc: warning: shift/reduce conflict on token IDENTIFIER [-Wcounterexamples]
Productions leading up to the conflict state found. Still finding a possible unifying counterexample...time limit exceeded: 6.000000
First example: IDENTIFIER IDENTIFIER ":=" '-' • IDENTIFIER IDENTIFIER
Shift derivation
Start
↳ 1: FunctionFormalParList IDENTIFIER
↳ 2: FunctionFormalPar
↳ 4: IDENTIFIER IDENTIFIER ":=" SingleExpression
↳ 12: '-' SingleExpression
↳ 13: • IDENTIFIER
Second example: IDENTIFIER IDENTIFIER ":=" '-' • IDENTIFIER
Reduce derivation
Start
↳ 1: FunctionFormalParList IDENTIFIER
↳ 2: FunctionFormalPar
↳ 5: IDENTIFIER IDENTIFIER ":=" '-' •
parser.yc: warning: shift/reduce conflict on token '<' [-Wcounterexamples]
Example: '-' SingleExpression • '<' SingleExpression
Shift derivation
SingleExpression
↳ 12: '-' SingleExpression
↳ 11: SingleExpression • '<' SingleExpression
Reduce derivation
SingleExpression
↳ 11: SingleExpression '<' SingleExpression
↳ 12: '-' SingleExpression •
parser.yc: warning: shift/reduce conflict on token '<' [-Wcounterexamples]
Example: SingleExpression '<' SingleExpression • '<' SingleExpression
Shift derivation
SingleExpression
↳ 11: SingleExpression '<' SingleExpression
↳ 11: SingleExpression • '<' SingleExpression
Reduce derivation
SingleExpression
↳ 11: SingleExpression '<' SingleExpression
↳ 11: SingleExpression '<' SingleExpression •
Productions leading up to the conflict state found. Still finding a possible unifying counterexample...time limit exceeded: 6.000000
Productions leading up to the conflict state found. Still finding a possible unifying counterexample...time limit exceeded: 6.000000 |
This fix seems reasonable - can I make a PR to this repo? Or do you prefer a patch to bug-bison? $ git diff lssi.c
diff --git a/src/lssi.c b/src/lssi.c
index 245461a9..045772d3 100644
--- a/src/lssi.c
+++ b/src/lssi.c
@@ -139,7 +139,11 @@ eligible_state_items (state_item *target)
bitset_iterator biter;
state_item_number sin;
BITSET_FOR_EACH (biter, rsi, sin, 0)
- gl_list_add_last (queue, &state_items[sin]);
+ {
+ if (SI_DISABLED(sin))
+ continue;
+ gl_list_add_last (queue, &state_items[sin]);
+ }
}
gl_list_free (queue);
return result; No crash $ bison --report=counterexamples -Wcounterexamples parser.yc
parser.yc: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
parser.yc: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
parser.yc: warning: reduce/reduce conflict on token '<' [-Wcounterexamples]
Example: IDENTIFIER •
First reduce derivation
IdOrIdId
↳ 6: IDENTIFIER •
Second reduce derivation
SingleExpression
↳ 13: IDENTIFIER •
parser.yc: warning: shift/reduce conflict on token '<' [-Wcounterexamples]
Example: '-' SingleExpression • '<' SingleExpression
Shift derivation
SingleExpression
↳ 12: '-' SingleExpression
↳ 11: SingleExpression • '<' SingleExpression
Reduce derivation
SingleExpression
↳ 11: SingleExpression '<' SingleExpression
↳ 12: '-' SingleExpression •
parser.yc: warning: shift/reduce conflict on token '<' [-Wcounterexamples]
Example: SingleExpression '<' SingleExpression • '<' SingleExpression
Shift derivation
SingleExpression
↳ 11: SingleExpression '<' SingleExpression
↳ 11: SingleExpression • '<' SingleExpression
Reduce derivation
SingleExpression
↳ 11: SingleExpression '<' SingleExpression
↳ 11: SingleExpression '<' SingleExpression • |
That's not the issue. The state-item pruning is misbehaving, I'm working on it |
ok - good to hear |
There were several bugs in pruning that would leave the state-item graph in an inconsistent state which could cause crashes later on: - Pruning now happens in one pass instead of two. - Disabled state-items no longer prune the state-items they transition to if that state-item has other states that transition to it. - State-items that transition to disabled state-items are always pruned even if they have productions. Reported by Michal Bartkowiak <michal.bartkowiak@nokia.com> https://lists.gnu.org/r/bug-bison/2021-01/msg00000.html and Zartaj Majeed #71 * src/state-item.c (prune_forward, prune_backward): Fuse into... (prune_state_item): this. Adjust callers.
There were several bugs in pruning that would leave the state-item graph in an inconsistent state which could cause crashes later on: - Pruning now happens in one pass instead of two. - Disabled state-items no longer prune the state-items they transition to if that state-item has other states that transition to it. - State-items that transition to disabled state-items are always pruned even if they have productions. Reported by Michal Bartkowiak <michal.bartkowiak@nokia.com> https://lists.gnu.org/r/bug-bison/2021-01/msg00000.html and Zartaj Majeed #71 * src/state-item.c (prune_forward, prune_backward): Fuse into... (prune_state_item): this. Adjust callers.
Released in 3.7.5. |
This bug was originally reported on the bug-bison mailing list by Michal Bartkowiak on 5 Jan 2021 - https://lists.gnu.org/archive/html/bug-bison/2021-01/msg00000.html
I've investigated it and am opening an issue here for ease of tracking - many thanks Akim btw for creating this github mirror!
Here's what happens with the grammar file parser.yc.gz provided by Michal:
$ bison --report=counterexamples parser.yc parser.yc: warning: 2 shift/reduce conflicts [-Wconflicts-sr] parser.yc: warning: 1 reduce/reduce conflict [-Wconflicts-rr] parser.yc: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples Segmentation fault (core dumped)
This is bison built from master
Here's the stack at the crash:
This is the source in lssi.c
The reason is the bitset rsi passed to BITSET_FOR_EACH is from a disabled state_item si - meaning the bitset was previously freed and has garbage vtable pointers - in particular the list function pointer which is accessed by gl_list_add_last causing the segv
This is the disabled state_item
The state_item was disabled and the bitset was freed by prune_backward in state-items.c:
Clearly the loop in eligible_state_items should not be accessing a disabled state_item - but I don't know enough to say if the loop should avoid adding a disabled state_item to the queue in the first place
I have some comments on the grammar below
The text was updated successfully, but these errors were encountered: