This is an archive of the discontinued LLVM Phabricator instance.

libclang: Avoid returning an extra token in clang_tokenize
ClosedPublic

Authored by emilio on Nov 9 2016, 3:52 AM.

Details

Reviewers
akyrtzi
gbenyei
Summary

This is a bug that has hit me, and apparently more people (see [1]). There's a
bug open on this since 2011[2] with a patch attached, but got no attention, so I
rebased the patch and added a test for it.

[1]: https://github.com/servo/rust-bindgen/pull/219#discussion_r86691290
[2]: https://llvm.org/bugs/show_bug.cgi?id=9069

Diff Detail

Repository
rL LLVM

Event Timeline

emilio updated this revision to Diff 77331.Nov 9 2016, 3:52 AM
emilio retitled this revision from to libclang: Avoid returning an extra token in clang_tokenize.
emilio updated this object.
emilio added a reviewer: gbenyei.
emilio set the repository for this revision to rL LLVM.
emilio added a subscriber: Restricted Project.

Guy, I added you as a reviewer looking at the blame log, feel free to redirect since it's my first patch to LLVM. Thanks!

akyrtzi edited edge metadata.Nov 9 2016, 10:24 AM

The fix is correct, the comment for CXSourceRange says that it "Identifies a half-open character range in the source code".
But you don't need the other changes to test this. Here's an example:

$ cat /tmp/t.c
int gv = 0;
$ c-index-test -test-annotate-tokens=/tmp/t.c:1:10:1:11 /tmp/t.c
Literal: "0" [1:10 - 1:11] IntegerLiteral=
Punctuation: ";" [1:11 - 1:12]

All you have to do is a similar invocation with a character range for a token, CHECK that the token shows up and CHECK-NOT that the following token does not show up.
And add this to an existing test file that tests -test-annotate-tokens no need to add an additional test file.

I thought the extra test would be helpful since I'm not aware of any test that used clang_getCursorExtent + clang_tokenize, but I guess I can revert that, no problem. Thanks for the review! :)

emilio updated this revision to Diff 77383.Nov 9 2016, 12:07 PM
emilio edited edge metadata.

Updated per comments, let me know if I can do anything else, thanks!

Committed in r286421, thank you!

akyrtzi accepted this revision.Nov 9 2016, 4:15 PM
akyrtzi edited edge metadata.
This revision is now accepted and ready to land.Nov 9 2016, 4:15 PM
Eugene.Zelenko closed this revision.Nov 9 2016, 5:48 PM

Thanks for commiting the patch @akyrtzi (and for fixing up the test path, I kind of suspected there had to be a better place for it but didn't look too close apparently :P).

Thanks again!

This patch breaks python binding tests (which I fixes just now).
Please, next time launch python tests too

emilio added a comment.Dec 3 2016, 7:56 AM

Sorry @skalinichev, didn't know about those. Thanks for fixing.