<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Mar 21, 2013, at 2:33 PM, Erik Verbruggen <<a href="mailto:erik.verbruggen@me.com">erik.verbruggen@me.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Maybe a bit of explanation might be needed here to explain the "why" part..</div><div><br></div><div>What is done in that patch is to</div><div>a) iterate over all tokens, and select (copy) all those that are of the CXToken_Identifier kind into another array, and then</div><div>b) call clang_annotateTokens with that specific array</div><div><br></div><div>So not all tokens are queried, but only the identifiers, which somehow seems to trigger the assert.</div></div></blockquote><div><br></div><div>Ok I see.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>The reason is that when doing semantic highlighting for C/C++/ObjC/ObjC++, only identifiers can get a different meaning/use when the preprocessor is involved, or be marked with their specific kind of declaration. The reason for selecting only the identifiers is that querying only for these tokens already flagged up as a significant cost when doing time profiling (back in the (I think) 3.0 days).</div></div></blockquote><div><br></div><div>Hmm, there were improvements and I'd be surprised if it makes much difference now.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>I could change the code to ask for all tokens and skip the less interesting ones, but I was wondering if that would be band-aid to work around a bug in clang_annotateTokens or not. Hence my question on what that assert actually checks.</div><div><br></div><div>That said, I do have to come back to my remark about removing the assert and that showing no impact. After using it like that for some real code-editing, I noticed that the first couple (10? 20? 50?) identifiers do not get annotated correctly. Well, not at all. Which would actually be kinda fine with me, but then I'm wondering why the clang_annotateTokens function takes a list of tokens, instead of, say, a TU.</div><div><br></div><div>I'm kind of curious about that assert, and might find some time to look into it, but I'd appreciate some help/explanation on what's being checked there before I do that.</div></div></blockquote><div><br></div><div>The function annotatePreprocessorTokens in CIndex.cpp assumes that the array given to it came from clang_tokenize so it doesn't try to skip tokens and it asserts to make sure its token index points to the right token in the given array.</div><div>It should be modified to only assume that the given tokens are in source order.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>-- Erik.</div><div><br></div><br><div><div>On Mar 19, 2013, at 14:56, Erik Verbruggen <<a href="mailto:erik.verbruggen@me.com">erik.verbruggen@me.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Mar 19, 2013, at 0:07, Argyrios Kyrtzidis <<a href="mailto:kyrtzidis@apple.com">kyrtzidis@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Mar 17, 2013, at 8:35 AM, Erik Verbruggen <<a href="mailto:erik.verbruggen@me.com">erik.verbruggen@me.com</a>> wrote:<br><div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br>On Mar 16, 2013, at 18:56, Argyrios Kyrtzidis <<a href="mailto:kyrtzidis@apple.com">kyrtzidis@apple.com</a>> wrote:<br><br><blockquote type="cite"><br>On Mar 16, 2013, at 10:48 AM, Argyrios Kyrtzidis <<a href="mailto:kyrtzidis@apple.com">kyrtzidis@apple.com</a>> wrote:<br><br><blockquote type="cite">On Mar 16, 2013, at 3:09 AM, Erik Verbruggen <<a href="mailto:erik.verbruggen@me.com">erik.verbruggen@me.com</a>> wrote:<br><br><blockquote type="cite">Hi,<br><br>When using libclang's clang_annotateTokens, I have a consistently failing assert in CIndex.cpp, line 5429. This is for both 3.2 and trunk. When I comment the assert out, everything looks to be fine. Is this assert valid, and if so, what is it checking?<span class="Apple-converted-space"> </span><br></blockquote><br>It makes sure that when lexing for preprocessor directives tokens, that any cursors produced will refer to the correct clang_tokenize'd token.<br>Are you able to provide a preprocessed file for testing ?<br><br></blockquote><br>You can use "-E -frewrite-includes" to preserve preprocessor directives.<br></blockquote><br>See attachment.<br></div></blockquote><div><br></div><div>I can't reproduce using:</div><div><br></div><div>$ c-index-test -test-annotate-tokens=main.pp:1:1:100000:1 -x c++ main.pp > /dev/null</div><div><br></div><div>Does it occur with a particular source range ? What is the file whose tokens you are annotating ? Does using c-index-test on it reproduce the assertion hit ?</div><div>If yes, could you separate the includes of that file, for example:</div><div><br></div><div>#include "a.h"</div>#include "b.h"</div><div>#include "c.h"</div><div><br></div><div><code></div><div><br></div><div>====></div><div><br></div><div>#include "preprocessed-headers.h"</div><div><br></div><div><code></div></div></blockquote><br></div><div>I cannot reproduce it either with c-index-test, so I modified it to do it in the same way as I use the annotation. Patch is attached. With that patch, I get:</div><div><br></div><div><div><div>erik@Road-Warrior:untitled6$ ~/dev/builds/llvm-release-build/bin/c-index-test -test-annotate-tokens=main.pp:62024:1:1000000:1 -std=gnu++98 -x c++ main.pp</div><div>Assertion failed: (Tok.getLocation() == SourceLocation::getFromRawEncoding(Tokens[TokIdx].int_data[1])), function annotatePreprocessorTokens, file /Users/erik/dev/clang-llvm/llvm-git/tools/clang/tools/libclang/CIndex.cpp, line 5429.</div><div>libclang: crash detected while annotating tokens</div><div>Identifier: "std" [62025:17 - 62025:20]</div><div>Identifier: "main" [62027:5 - 62027:9]</div><div>Identifier: "cout" [62029:5 - 62029:9]</div><div>Identifier: "endl" [62029:31 - 62029:35]</div><div><br></div></div><div>When I move everything up to (and including) line 62022 into the a header file (like you mentioned above), and include that file, I get exactly the same crash.</div><div><br></div><div></div></div></div><span><my-c-indexing.patch></span><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div></div></div>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br></blockquote></div><br></div>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev<br></blockquote></div><br></body></html>