<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;">On Apr 9, 2013, at 10:38 PM, Oliver <<a href="mailto:ogtifs@gmail.com">ogtifs@gmail.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-stroke-width: 0px;">With displayDiagnostics, I get the following output on stderr:<br>error: error reading main.cpp<br><br>There is no main.cpp, the whole point is to have an in-memory document. I tried setting the string "main.cpp" in the call to clang_parseTranslationUnit to both an empty string and NULL, both of which cause the error to be suppressed but still return a null TU<br></div></blockquote><div><br></div><div>In the source sample that you posted originally, you pass the CXUnsavedFile to clang_reparseTranslationUnit, not clang_parseTranslationUnit. I find it unlikely that this would work without a main.cpp file already present in the file system.</div><br><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-stroke-width: 0px;"><br>Oliver <br><br>On Tue, Apr 9, 2013 at 11:33 , Argyrios Kyrtzidis <<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>> wrote:<br><blockquote type="cite">On Apr 9, 2013, at 12:56 AM, Oliver <<a href="mailto:ogtifs@gmail.com">ogtifs@gmail.com</a>> wrote:<br><blockquote type="cite">I think maybe this message got lost somewhere, resending:<br>It seems that in the case of my example, the TU is null; indicating parsing has failed? What does it mean in this case for parsing to fail and why should it fail on such a case? Is there a new way to use this API? This example worked correctly in clang 3.1.<br></blockquote>Try calling clang_createIndex with second parameter set to 1 (for 'displayDiagnostics') and check the stderr output.<br><blockquote type="cite">I don't know whether there is a policy to fail gracefully when a null TU is passed, but FWIW my null TU also causes a segfault with this basic block<br></blockquote>Thanks, fixed in r179121.<br><blockquote type="cite">for(unsigned i=0, n = clang_getNumDiagnostics(tu); i!=n; ++i) {<br> CXDiagnostic diag = clang_getDiagnostic(tu, i);<br> CXDiagnosticSeverity sev = clang_getDiagnosticSeverity(diag);<br> CXSourceLocation loc = clang_getDiagnosticLocation(diag);<br> CXString str = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions());<br>}<br>Regards,<br>Oliver<br>On Fri, Apr 5, 2013 at 1:45 , Argyrios Kyrtzidis <<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>> wrote:<br><blockquote type="cite">On Apr 4, 2013, at 12:14 AM, Oliver Giles <<a href="mailto:ogtifs@gmail.com">ogtifs@gmail.com</a>> wrote:<br><blockquote type="cite">I just tried this again with the latest clang from svn. The original snippet works but the next lines in my original code are:<br>CXCursor cursor = clang_getTranslationUnitCursor(tu);<br>CXSourceRange sr = clang_getCursorExtent(cursor);<br>CXToken* tokens;<br>unsigned numtokens;<br>clang_tokenize(tu, sr, &tokens, &numtokens);<br>CXCursor* cursors = new CXCursor[numtokens];<br>clang_annotateTokens(tu, tokens, numtokens, cursors);<br>Appending even the first line of this (clang_getTranslationUnitCursor) to the example I gave earlier causes a segfault in the clang 3.3 library.<br></blockquote>Fixed in r178800. FYI, it looks like the CXTranslationUnit object that you get is null, so there was a problem during parsing.<br><blockquote type="cite">Oliver<br>On 2013-01-16 20:14, Argyrios Kyrtzidis wrote:<br><blockquote type="cite">Fixed in r172632, thanks!<br>On Jan 15, 2013, at 9:36 PM, Oliver <<a href="mailto:ogtifs@gmail.com">ogtifs@gmail.com</a>> wrote:<br><blockquote type="cite">Hi,<br>Some example code for document editing I was using with clang 3.1 now segfaults on clang 3.2:<br>#include <clang-c/Index.h><br>#include <string.h><br>char DOCUMENT[] = "int main() { return 0; }\n";<br>int main(int argc, char** argv) {<br><span class="Apple-tab-span" style="white-space: pre;"> </span>const char* args;<br><span class="Apple-tab-span" style="white-space: pre;">       </span>CXIndex ci = clang_createIndex(0,0);<br><span class="Apple-tab-span" style="white-space: pre;">    </span>CXTranslationUnit tu =<br><span class="Apple-tab-span" style="white-space: pre;">  </span><span class="Apple-tab-span" style="white-space: pre;">  </span><span class="Apple-tab-span" style="white-space: pre;">  </span>clang_parseTranslationUnit(ci, "main.cpp", &args,<br><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;">  </span><span class="Apple-tab-span" style="white-space: pre;">  </span> 0, NULL, 0, clang_defaultEditingTranslationUnitOptions());<br><span class="Apple-tab-span" style="white-space: pre;">        </span>CXUnsavedFile file;<br><span class="Apple-tab-span" style="white-space: pre;">     </span>file.Filename = "main.cpp";<br><span class="Apple-tab-span" style="white-space: pre;">   </span>file.Contents = DOCUMENT;<br><span class="Apple-tab-span" style="white-space: pre;">       </span>file.Length = strlen(DOCUMENT);<br><span class="Apple-tab-span" style="white-space: pre;"> </span>clang_reparseTranslationUnit(tu, 1, &file, clang_defaultEditingTranslationUnitOptions());<br><span class="Apple-tab-span" style="white-space: pre;">   </span>return 0;<br>}<br>Output is:<br>libclang: crash detected during reparsing<br>Segmentation fault (core dumped)<br>Am I doing something perverted or is this a bug?<br>Oliver<br>_______________________________________________<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></blockquote></blockquote></blockquote>_______________________________________________<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></blockquote><br>_______________________________________________<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></div></blockquote></div><br></body></html>