Commit graph

1516 commits

Author SHA1 Message Date
Max Brunsfeld
eccb3893eb Prune unneeded stack versions based on a depth criteria 2017-06-30 17:49:09 -07:00
Max Brunsfeld
d6579956f5 Enforce a hard version count limit during the recovery action 2017-06-30 17:49:09 -07:00
Max Brunsfeld
3e84b15204 Merge pull request #84 from tree-sitter/faster-error-recovery
Avoid hangs during error recovery
2017-06-29 16:53:52 -07:00
Max Brunsfeld
061fba6b92 🎨 Just call it 'inline' 2017-06-29 16:49:59 -07:00
Max Brunsfeld
a89322c5f1 Remove unneeded parameters from public interface of stack_iterate callback 2017-06-29 16:43:56 -07:00
Max Brunsfeld
009d6d1534 Improve heuristics for pruning parse versions based on errors
* Rewrite the error cost comparison in terms of explicit, discrete
conditions.
* Allow merging versions have different error costs.
* Store the depth of each stack version since the last error. Use this
state to prevent incorrect merging.
* Sort the stack versions in order of preference and put a hard limit on
the version count.
2017-06-29 15:00:20 -07:00
Max Brunsfeld
445be0736a Clean up ts_stack_push function 2017-06-29 15:00:20 -07:00
Max Brunsfeld
66be393b78 Stack - consider empty external token state identical to NULL 2017-06-29 15:00:20 -07:00
Max Brunsfeld
5e3818882b Merge pull request #83 from tree-sitter/ref-counts
Increase size of ref_counts and add assertions
2017-06-29 10:15:51 -07:00
Phil Turnbull
5ef9c4d6aa Increase size of ref_counts and add assertions
This bumps the size of the reference counts from 16- to 32-bit counters to make
it less likely to overflow. Also assert in the retain function that the
reference count didn't overflow.

32-bits seems big enough for non-pathological examples but a more fool-proof
fix may be to bump it to 64-bits.
2017-06-29 06:39:01 -07:00
Max Brunsfeld
839dc53bf2 Merge pull request #82 from tree-sitter/address-sanitizer
Use address sanitizer when running tests on mac, fix newly discovered bugs
2017-06-28 11:04:15 -07:00
Max Brunsfeld
dfd7b1f5f6 Consolidate memory management logic in Stack 2017-06-27 16:17:24 -07:00
Max Brunsfeld
ca4db76bb1 Override LINK to call clang++ w/ -fsanitize=address in test script
Signed-off-by: Philip Turnbull <philipturnbull@github.com>
2017-06-27 15:44:58 -07:00
Max Brunsfeld
0143bfdad4 Avoid use-after-free of external token states
Previously, it was possible for references to external token states to
outlive the trees to which those states belonged.

Now, instead of storing references to external token states in the Stack
and in the Lexer, we store references to the external token trees
themselves, and we retain the trees to prevent use-after-free.
2017-06-27 14:54:27 -07:00
Max Brunsfeld
f678018d3d Avoid use-after-free when copying stack iterators 2017-06-27 14:54:27 -07:00
Max Brunsfeld
0054272879 Record deallocations even when recording allocations is disabled 2017-06-27 14:54:27 -07:00
Max Brunsfeld
76e35fd037 Enable address sanitizer when running tests on mac
Signed-off-by: Philip Turnbull <philipturnbull@github.com>
2017-06-27 14:54:20 -07:00
Max Brunsfeld
076002a01e Merge pull request #78 from philipturnbull/update-utf8proc
Out of bounds read in utf8proc
2017-06-23 12:18:21 -07:00
Max Brunsfeld
f62ee5a0f3 Fix OOB reads at ends of chunks
Signed-off-by: Philip Turnbull <philipturnbull@github.com>
2017-06-23 12:09:16 -07:00
Max Brunsfeld
8ee3f96960 Fix formatting of non-ascii unexpected characters
Signed-off-by: Philip Turnbull <philipturnbull@github.com>
2017-06-23 12:08:50 -07:00
Max Brunsfeld
d6cd0ca4d0 Merge pull request #80 from tree-sitter/fix-another-parse-state-merging-problem
Fix another parse state merging problem
2017-06-22 16:12:30 -07:00
Max Brunsfeld
20982fdcb9 Mark tokens as non-reusable in states where shorter takes take precedence
This fixes some randomized test failures in the C grammar, relating to Object-like macros.
The object-like macro rule relies on a whitespace token in order to distinguish object-like
macros whose values begin with a '(' from function-like macros. The presence of that
whitespace token means that other nodes should not be reusable in that state.
2017-06-22 16:04:42 -07:00
Max Brunsfeld
8517313a45 🎨 2017-06-22 15:33:07 -07:00
Max Brunsfeld
8157b81b68 Improve logic for short-circuiting trivial lexing conflict detection 2017-06-22 15:33:01 -07:00
Max Brunsfeld
2c043803f1 Be more conservative about avoiding lexing conflicts when merging states
This fixes a bug in the C++ grammar where the `>>` token was merged into
a state where it was previously not valid, but the `>` token *was*
valid. This caused nested templates like -

std::vector<std::pair<int, int>>

to not parse correctly.
2017-06-22 15:32:13 -07:00
Max Brunsfeld
6db12ab44e Adjust C error recovery tests to reflect grammar changes 2017-06-21 16:58:40 -07:00
Max Brunsfeld
0cc1090001 Read grammar tests from corpus dir instead of grammar_test dir 2017-06-21 16:31:25 -07:00
Phil Turnbull
8a15da90fb Update utf8proc dependency to v2.1
This includes JuliaLang/utf8proc#66 which is an out-of-bounds read when parsing
malformed utf8 characters.
2017-06-21 09:55:13 -04:00
Max Brunsfeld
513edec7c1 Merge pull request #77 from philipturnbull/scan-build-fixes
Fix errors found by scan-build
2017-06-20 10:15:20 -07:00
Phil Turnbull
7bdb0917d3 Revert "Add standalone scan-build script"
This reverts commit 9135d14b81.
2017-06-19 10:24:40 -04:00
Phil Turnbull
1b9e78add2 Fix formatting and use '-n' 2017-06-19 10:24:08 -04:00
Phil Turnbull
e9bf794cd9 Remove unneeded build step 2017-06-19 10:23:54 -04:00
Phil Turnbull
ee3caafe7b Use -j2 on the CI boxes
The travis-ci trusty container has two cores.
2017-06-16 15:16:40 -04:00
Phil Turnbull
9135d14b81 Add standalone scan-build script
For running scan-build outside of CI, e.g. `./script/scan-build -j4`
2017-06-16 15:16:40 -04:00
Phil Turnbull
7171664eec Disable DeadStores scan-build checker
This silences a true, but minor, bug in the external json-parser:

externals/json-parser/json.c:653:37: warning: Value stored to 'b' is never read
                                    b = 0;
                                    ^   ~
2017-06-16 15:16:40 -04:00
Phil Turnbull
97cdd8b738 Run scan-build during CI
This bumps the travis-ci container image to Trusty so that we have a version of
clang that includes proper support for C++14.
2017-06-16 15:16:29 -04:00
Max Brunsfeld
f29c41b7e8 Merge pull request #71 from tree-sitter/update-fixture-grammars
Run randomized tests against the latest Javascript grammar
2017-06-15 17:29:39 -07:00
Max Brunsfeld
e19393eff5 🎨 2017-06-15 17:25:21 -07:00
Max Brunsfeld
932feb2498 Fix gcc warning in test helper file 2017-06-15 17:13:01 -07:00
Max Brunsfeld
fa81a764fb Cache test grammar directory on Travis 2017-06-15 17:12:14 -07:00
Max Brunsfeld
599367d36d Always recur into error nodes when reporting changed ranges 2017-06-15 17:06:48 -07:00
Max Brunsfeld
c66fddd3aa Add TSInput option to measure columns in bytes not characters 2017-06-15 16:35:34 -07:00
Phil Turnbull
cfca764d48 Root can never be NULL in this context 2017-06-15 07:47:16 -04:00
Max Brunsfeld
b862db766e Merge remote-tracking branch 'origin/master' into update-fixture-grammars 2017-06-14 17:11:44 -07:00
Phil Turnbull
18f261ad51 Initialise all fields of TSParseOptions in tests
This should prevent any confusing failures in the unit tests:

test/runtime/document_test.cc:381:7: warning: Passed-by-value struct argument contains uninitialized data (e.g., field: 'changed_range_count')
      ts_document_parse_with_options(document, options);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test/runtime/document_test.cc:408:7: warning: Passed-by-value struct argument contains uninitialized data (e.g., field: 'changed_range_count')
      ts_document_parse_with_options(document, options);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-06-14 11:12:06 -04:00
Phil Turnbull
aa6e93820c Silence false-positive warning in ts_record_free
This is safe but I think it is technically undefined behaviour to use a pointer
after it has been freed:

test/helpers/record_alloc.cc:75:3: warning: Use of memory after it is freed
  record_deallocation(pointer);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-06-14 11:12:06 -04:00
Phil Turnbull
d1b19e8196 Prevent NULL pointer dereference in parser__accept
parser__select_tree can return true if 'left != NULL' and 'right == NULL' which
will later cause a NULL ptr deref:

src/runtime/parser.c:842:14: warning: Access to field 'ref_count' results in a dereference of a null pointer (loaded from variable 'root')
      assert(root->ref_count > 0);
             ^~~~~~~~~~~~~~~
2017-06-14 11:12:06 -04:00
Phil Turnbull
da099d0bbe Prevent NULL pointer dereference in parser__repair_error_callback
Because repair_reduction_count is unsigned, the default of '-1' is 0xffffffff
and will cause the loop to be entered if repair_reduction_count is NULL:

src/runtime/parser.c:691:11: warning: Dereference of null pointer
      if (repair_reductions[j].params.symbol == repair->symbol) {
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-06-14 11:12:06 -04:00
Phil Turnbull
fdd8792ebc Correctly set is_first
From scan-build: Value stored to 'is_first' is never read
2017-06-14 11:12:06 -04:00
Max Brunsfeld
040e225a54 Merge pull request #76 from philipturnbull/remove-duplicates-oob
OOB-read in remove_duplicate_parse_states
2017-06-14 07:20:09 -07:00