[cfe-dev] clang 3.2 libclang: crash detected during reparsing

Oliver ogtifs at gmail.com
Tue Apr 9 00:56:06 PDT 2013


I think maybe this message got lost somewhere, resending:

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.

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

for(unsigned i=0, n = clang_getNumDiagnostics(tu); i!=n; ++i) {
 CXDiagnostic diag = clang_getDiagnostic(tu, i);
 CXDiagnosticSeverity sev = clang_getDiagnosticSeverity(diag);
 CXSourceLocation loc = clang_getDiagnosticLocation(diag);
 CXString str = clang_formatDiagnostic(diag, 
clang_defaultDiagnosticDisplayOptions());
}

Regards,
Oliver

On Fri, Apr 5, 2013 at 1:45 , Argyrios Kyrtzidis <akyrtzi at gmail.com> 
wrote:
> On Apr 4, 2013, at 12:14 AM, Oliver Giles <ogtifs at gmail.com> wrote:
> 
>> I just tried this again with the latest clang from svn. The original 
>> snippet works but the next lines in my original code are:
>> 
>> CXCursor cursor = clang_getTranslationUnitCursor(tu);
>> CXSourceRange sr = clang_getCursorExtent(cursor);
>> CXToken* tokens;
>> unsigned numtokens;
>> clang_tokenize(tu, sr, &tokens, &numtokens);
>> CXCursor* cursors = new CXCursor[numtokens];
>> clang_annotateTokens(tu, tokens, numtokens, cursors);
>> 
>> Appending even the first line of this 
>> (clang_getTranslationUnitCursor) to the example I gave earlier 
>> causes a segfault in the clang 3.3 library.
>> 
> 
> Fixed in r178800. FYI, it looks like the CXTranslationUnit object 
> that you get is null, so there was a problem during parsing.
> 
>> 
>> Oliver
>> 
>> On 2013-01-16 20:14, Argyrios Kyrtzidis wrote:
>>> Fixed in r172632, thanks!
>>> 
>>> On Jan 15, 2013, at 9:36 PM, Oliver <ogtifs at gmail.com> wrote:
>>> 
>>>> Hi,
>>>> Some example code for document editing I was using with clang 3.1 
>>>> now segfaults on clang 3.2:
>>>> 
>>>> #include <clang-c/Index.h>
>>>> #include <string.h>
>>>> 
>>>> char DOCUMENT[] = "int main() { return 0; }\n";
>>>> 
>>>> int main(int argc, char** argv) {
>>>> 	const char* args;
>>>> 	CXIndex ci = clang_createIndex(0,0);
>>>> 	CXTranslationUnit tu =
>>>> 			clang_parseTranslationUnit(ci, "main.cpp", &args,
>>>> 			 0, NULL, 0, clang_defaultEditingTranslationUnitOptions());
>>>> 	CXUnsavedFile file;
>>>> 	file.Filename = "main.cpp";
>>>> 	file.Contents = DOCUMENT;
>>>> 	file.Length = strlen(DOCUMENT);
>>>> 	clang_reparseTranslationUnit(tu, 1, &file, 
>>>> clang_defaultEditingTranslationUnitOptions());
>>>> 	return 0;
>>>> }
>>>> 
>>>> Output is:
>>>> libclang: crash detected during reparsing
>>>> Segmentation fault (core dumped)
>>>> 
>>>> Am I doing something perverted or is this a bug?
>>>> 
>>>> Oliver
>>>> _______________________________________________
>>>> cfe-dev mailing list
>>>> cfe-dev at cs.uiuc.edu
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>> 
> 
> 




More information about the cfe-dev mailing list