Skip to content

Commit

Permalink
Allocate the reachability_mask bitset to the correct size.
Browse files Browse the repository at this point in the history
The reachability_mask_width function computes the number of 32-bit integers
needed to represent the reachability mask in the generated parser.  But the
actual bitset in the generator needs enough bits for every transition.

Since the bitset is allocated in 64-bit chunks, things only start to go wrong
when there are more than 64 distinct bracket transition symbols.  Add a test
case (generated by https://github.com/Luctia/owl_perftest) that has enough
nesting to generate this many bracket transitions.

Thanks to Luc Timmerman for finding this bug.
  • Loading branch information
ianh committed Jul 20, 2022
1 parent 6c98928 commit 8e401a6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/6a-generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ void generate(struct generator *gen)
}
output_line(out, " %%token-type token = run->tokens[token_index];");
output_line(out, " switch (token) {");
struct bitset reachability_mask = bitset_create_empty(reachability_mask_width(gen));
struct bitset reachability_mask = bitset_create_empty(gen->deterministic->transitions.number_of_transitions);
for (uint32_t j = 0; j < s.number_of_transitions; ++j) {
struct transition t = s.transitions[j];
if (t.symbol >= gen->combined->number_of_tokens) {
Expand Down
72 changes: 72 additions & 0 deletions test/nested-reachability-mask-crash.owltest
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---nested71 = [ '(' nested70 ')' ]
nested70 = [ '(' nested69 ')' ]
nested69 = [ '(' nested68 ')' ]
nested68 = [ '[' nested67 ']' ]
nested67 = [ '{' nested66 '}' ]
nested66 = [ '(' nested65 ')' ]
nested65 = [ '[' nested64 ']' ]
nested64 = [ '[' nested63 ']' ]
nested63 = [ '[' nested62 ']' ]
nested62 = [ '[' nested61 ']' ]
nested61 = [ '(' nested60 ')' ]
nested60 = [ '{' nested59 '}' ]
nested59 = [ '{' nested58 '}' ]
nested58 = [ '(' nested57 ')' ]
nested57 = [ '[' nested56 ']' ]
nested56 = [ '{' nested55 '}' ]
nested55 = [ '[' nested54 ']' ]
nested54 = [ '(' nested53 ')' ]
nested53 = [ '{' nested52 '}' ]
nested52 = [ '{' nested51 '}' ]
nested51 = [ '[' nested50 ']' ]
nested50 = [ '[' nested49 ']' ]
nested49 = [ '(' nested48 ')' ]
nested48 = [ '[' nested47 ']' ]
nested47 = [ '(' nested46 ')' ]
nested46 = [ '[' nested45 ']' ]
nested45 = [ '[' nested44 ']' ]
nested44 = [ '{' nested43 '}' ]
nested43 = [ '[' nested42 ']' ]
nested42 = [ '[' nested41 ']' ]
nested41 = [ '[' nested40 ']' ]
nested40 = [ '{' nested39 '}' ]
nested39 = [ '[' nested38 ']' ]
nested38 = [ '[' nested37 ']' ]
nested37 = [ '{' nested36 '}' ]
nested36 = [ '{' nested35 '}' ]
nested35 = [ '{' nested34 '}' ]
nested34 = [ '(' nested33 ')' ]
nested33 = [ '(' nested32 ')' ]
nested32 = [ '{' nested31 '}' ]
nested31 = [ '(' nested30 ')' ]
nested30 = [ '[' nested29 ']' ]
nested29 = [ '[' nested28 ']' ]
nested28 = [ '[' nested27 ']' ]
nested27 = [ '[' nested26 ']' ]
nested26 = [ '[' nested25 ']' ]
nested25 = [ '(' nested24 ')' ]
nested24 = [ '[' nested23 ']' ]
nested23 = [ '[' nested22 ']' ]
nested22 = [ '[' nested21 ']' ]
nested21 = [ '[' nested20 ']' ]
nested20 = [ '[' nested19 ']' ]
nested19 = [ '[' nested18 ']' ]
nested18 = [ '[' nested17 ']' ]
nested17 = [ '{' nested16 '}' ]
nested16 = [ '(' nested15 ')' ]
nested15 = [ '(' nested14 ')' ]
nested14 = [ '{' nested13 '}' ]
nested13 = [ '[' nested12 ']' ]
nested12 = [ '[' nested11 ']' ]
nested11 = [ '{' nested10 '}' ]
nested10 = [ '(' nested9 ')' ]
nested9 = [ '(' nested8 ')' ]
nested8 = [ '(' nested7 ')' ]
nested7 = [ '[' nested6 ']' ]
nested6 = [ '{' nested5 '}' ]
nested5 = [ '[' nested4 ']' ]
nested4 = [ '[' nested3 ']' ]
nested3 = [ '[' nested2 ']' ]
nested2 = [ '(' nested1 ')' ]
nested1 = [ '(' nested0 ')' ]
nested0 = string | number
2 changes: 2 additions & 0 deletions test/results/nested-reachability-mask-crash.owltest.cc-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parse error: more input needed
error: 'test executable' exited with status 255
Empty file.
3 changes: 3 additions & 0 deletions test/results/nested-reachability-mask-crash.owltest.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
error: expected more text after the last token


Empty file.

0 comments on commit 8e401a6

Please sign in to comment.