[cfe-dev] AST Parser failure
Socrates Katsoulacos
socrates.katsoulacos11 at imperial.ac.uk
Thu Aug 9 09:29:22 PDT 2012
Dear Sir/Madam,
I have the following code inside a class.
//visit AST
static CXChildVisitResult TranslationUnitVisitor(CXCursor,
CXCursor, CXClientData data)
{
return CXChildVisit_Recurse; // visit complete AST recursivly
}
void VisitTranslationUnitWithPCH()
{
//create function pointer
CXChildVisitResult (*pTranslationUnitVisitor)(CXCursor, CXCursor,
CXClientData) = TranslationUnitVisitor;
//excludeDeclsFromPCH = 1, displayDiagnostics=1
CXIndex cx_idx = clang_createIndex(0, 1);
//IndexTest.pch was produced with the following command:
//"clang -x c test.h -emit-ast -o test.pch"
//system("/home/socrates/llvm/Debug+Asserts/bin/clang -x c test.h
-emit-ast -o test.pch");
CXTranslationUnit TU = clang_createTranslationUnit(cx_idx, "test.pch");
// This will load all the symbols from 'test.pch'
clang_visitChildren(clang_getTranslationUnitCursor(TU),
pTranslationUnitVisitor, 0);
clang_disposeTranslationUnit(TU);
// This will load all the symbols from 'test.c', excluding symbols
// from 'test.pch'.
char *args[] = { "-Xclang", "test.pch" };
TU = clang_createTranslationUnitFromSourceFile(cx_idx, "test.c", 2, args,
0, 0);
clang_visitChildren(clang_getTranslationUnitCursor(TU),
pTranslationUnitVisitor,0);
clang_disposeTranslationUnit(TU);
}
When I run it I get the following errors:
clang: ASTUnit.cpp:1064: bool clang::ASTUnit::Parse(llvm::MemoryBuffer*):
Assertion `Clang->getFrontendOpts().Inputs.size() == 1 && "Invocation must
have exactly one source file!"' failed.
//some output of my program
libclang: crash detected during parsing: {
'source_filename' : 'test.c'
'command_line_args' : ['-Xclang', 'test.pch'],
'unsaved_files' : [],
'options' : 1,
}
0 clang 0x00000000029dd864
1 clang 0x00000000029dd53a
2 libpthread.so.0 0x00007f7169891cb0
3 libclang.so 0x00007f7167355507
clang_getTranslationUnitCursor + 20
4 libSessionTypeChecker.so 0x00007f716707dae3
5 libSessionTypeChecker.so 0x00007f716707d9e2
6 clang 0x0000000000c8c202
clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) + 94
7 clang 0x0000000000fcd7f4
clang::ParseAST(clang::Sema&, bool, bool) + 789
8 clang 0x0000000000c79c92
clang::ASTFrontendAction::ExecuteAction() + 298
9 clang 0x0000000000e17428
clang::CodeGenAction::ExecuteAction() + 1194
10 clang 0x0000000000c798c6
clang::FrontendAction::Execute() + 252
11 clang 0x0000000000c52bd4
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 718
12 clang 0x0000000000c24843
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 969
13 clang 0x0000000000c12e03 cc1_main(char const**, char
const**, char const*, void*) + 999
14 clang 0x0000000000c1fbb9 main + 494
15 libc.so.6 0x00007f7168ad276d __libc_start_main + 237
16 clang 0x0000000000c12059
Stack dump:
0. Program arguments: /home/socrates/llvm/Debug+Asserts/bin/clang -cc1
-triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free
-main-file-name Master.c -mrelocation-model static -mdisable-fp-elim
-fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables
-target-cpu x86-64 -target-linker-version 2.22 -momit-leaf-frame-pointer
-resource-dir /home/socrates/llvm/Debug+Asserts/bin/../lib/clang/3.2 -I
/home/socrates/Desktop/sessionC/include -I /usr/include -fmodule-cache-path
/var/tmp/clang-module-cache -internal-isystem /usr/local/include
-internal-isystem
/home/socrates/llvm/Debug+Asserts/bin/../lib/clang/3.2/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-fdebug-compilation-dir /home/socrates -ferror-limit 19 -fmessage-length 0
-mstackrealign -fobjc-runtime=gnu-fragile -fdiagnostics-show-option -load
/home/socrates/llvm/Debug+Asserts/lib/libclang.so -load
/home/socrates/llvm/Debug+Asserts/lib/libSessionTypeChecker.so -add-plugin
sess-type-check -plugin-arg-sess-type-check 2 -o /tmp/Master-UhLn2i.o -x c
/home/socrates/Desktop/MPI_TestCode/Master.c
1. <eof> parser at end of file
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.2 (trunk 159118)
Target: x86_64-unknown-linux-gnu
Thread model: posix
clang: note: diagnostic msg: PLEASE submit a bug report to
http://llvm.org/bugs/ and include the crash backtrace, preprocessed source,
and associated run script.
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/Master-9A0ZAq.i
clang: note: diagnostic msg: /tmp/Master-9A0ZAq.sh
clang: note: diagnostic msg:
I would be grateful for your help with this issue.
*Note*: I load libclang using "-Xclang -load -Xclang
/home/socrates/llvm/Debug+Asserts/lib/libclang.so" since it was not finding
the clang_* functions (e.g. clang_createIndex()) otherwise.
Thank you very much,
Socrates
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120809/abefea66/attachment.html>
More information about the cfe-dev
mailing list