<div>Dear Sir/Madam,</div><div><br></div><div>I have the following code inside a class.</div><div><br></div><div>//visit AST</div><div> static CXChildVisitResult TranslationUnitVisitor(CXCursor, CXCursor, CXClientData data)</div>
<div> {</div><div> <span style="white-space:pre-wrap"> </span> return CXChildVisit_Recurse; // visit complete AST recursivly</div><div> }</div><div><br></div><div> </div><div> void VisitTranslationUnitWithPCH()</div>
<div> {</div><div><span style="white-space:pre-wrap"> </span> //create function pointer</div><div><span style="white-space:pre-wrap"> </span> CXChildVisitResult (*pTranslationUnitVisitor)(CXCursor, CXCursor, CXClientData) = TranslationUnitVisitor;</div>
<div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span> //excludeDeclsFromPCH = 1, displayDiagnostics=1</div><div><span style="white-space:pre-wrap"> </span> CXIndex cx_idx = clang_createIndex(0, 1);</div>
<div><span style="white-space:pre-wrap"> </span> </div><div> <span style="white-space:pre-wrap"> </span> //IndexTest.pch was produced with the following command:</div><div><span style="white-space:pre-wrap"> </span> //"clang -x c test.h -emit-ast -o test.pch"</div>
<div><span style="white-space:pre-wrap"> </span> //system("/home/socrates/llvm/Debug+Asserts/bin/clang -x c test.h -emit-ast -o test.pch");</div><div><span style="white-space:pre-wrap"> </span> CXTranslationUnit TU = clang_createTranslationUnit(cx_idx, "test.pch");</div>
<div><br></div><div><span style="white-space:pre-wrap"> </span> // This will load all the symbols from 'test.pch'</div><div><span style="white-space:pre-wrap"> </span> clang_visitChildren(clang_getTranslationUnitCursor(TU), pTranslationUnitVisitor, 0);</div>
<div><span style="white-space:pre-wrap"> </span> clang_disposeTranslationUnit(TU);</div><div><br></div><div><span style="white-space:pre-wrap"> </span> // This will load all the symbols from 'test.c', excluding symbols</div>
<div><span style="white-space:pre-wrap"> </span> // from 'test.pch'.</div><div><span style="white-space:pre-wrap"> </span> char *args[] = { "-Xclang", "test.pch" };</div>
<div><span style="white-space:pre-wrap"> </span> TU = clang_createTranslationUnitFromSourceFile(cx_idx, "test.c", 2, args, 0, 0);</div><div><span style="white-space:pre-wrap"> </span> </div>
<div><span style="white-space:pre-wrap"> </span> clang_visitChildren(clang_getTranslationUnitCursor(TU), pTranslationUnitVisitor,0);</div><div><span style="white-space:pre-wrap"> </span> clang_disposeTranslationUnit(TU);</div>
<div> }</div><div><br></div><div>When I run it I get the following errors:</div><div><br></div><div><div>clang: ASTUnit.cpp:1064: bool clang::ASTUnit::Parse(llvm::MemoryBuffer*): Assertion `Clang->getFrontendOpts().Inputs.size() == 1 && "Invocation must have exactly one source file!"' failed.</div>
<div><br></div><div>//some output of my program</div><div><br></div><div>libclang: crash detected during parsing: {</div><div> 'source_filename' : 'test.c'</div><div> 'command_line_args' : ['-Xclang', 'test.pch'],</div>
<div> 'unsaved_files' : [],</div><div> 'options' : 1,</div><div>}</div><div>0 clang 0x00000000029dd864</div><div>1 clang 0x00000000029dd53a</div><div>2 libpthread.so.0 0x00007f7169891cb0</div>
<div>3 libclang.so 0x00007f7167355507 clang_getTranslationUnitCursor + 20</div><div>4 libSessionTypeChecker.so 0x00007f716707dae3</div><div>5 libSessionTypeChecker.so 0x00007f716707d9e2</div><div>6 clang 0x0000000000c8c202 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) + 94</div>
<div>7 clang 0x0000000000fcd7f4 clang::ParseAST(clang::Sema&, bool, bool) + 789</div><div>8 clang 0x0000000000c79c92 clang::ASTFrontendAction::ExecuteAction() + 298</div><div>9 clang 0x0000000000e17428 clang::CodeGenAction::ExecuteAction() + 1194</div>
<div>10 clang 0x0000000000c798c6 clang::FrontendAction::Execute() + 252</div><div>11 clang 0x0000000000c52bd4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 718</div>
<div>12 clang 0x0000000000c24843 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 969</div><div>13 clang 0x0000000000c12e03 cc1_main(char const**, char const**, char const*, void*) + 999</div>
<div>14 clang 0x0000000000c1fbb9 main + 494</div><div>15 libc.so.6 0x00007f7168ad276d __libc_start_main + 237</div><div>16 clang 0x0000000000c12059</div><div>Stack dump:</div>
<div>0.<span style="white-space:pre-wrap"> </span>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 </div>
<div>1.<span style="white-space:pre-wrap"> </span><eof> parser at end of file</div><div>clang: error: unable to execute command: Segmentation fault (core dumped)</div><div>clang: error: clang frontend command failed due to signal (use -v to see invocation)</div>
<div>clang version 3.2 (trunk 159118)</div><div>Target: x86_64-unknown-linux-gnu</div><div>Thread model: posix</div><div>clang: note: diagnostic msg: PLEASE submit a bug report to <a href="http://llvm.org/bugs/" target="_blank">http://llvm.org/bugs/</a> and include the crash backtrace, preprocessed source, and associated run script.</div>
<div>clang: note: diagnostic msg: </div><div>********************</div><div><br></div><div>PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:</div><div>Preprocessed source(s) and associated run script(s) are located at:</div>
<div>clang: note: diagnostic msg: /tmp/Master-9A0ZAq.i</div><div>clang: note: diagnostic msg: /tmp/Master-9A0ZAq.sh</div><div>clang: note: diagnostic msg: </div></div><div><br></div><div>I would be grateful for your help with this issue.</div>
<div><br></div><div><u>Note</u>: 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.</div>
<div><br></div><div>Thank you very much,</div><div><br></div><div>Socrates</div><div><br></div>