[cfe-users] libclang - saved translation unit reloading problem

Guba Dániel Olivér gudaol at gmx.com
Thu Jul 23 01:07:46 PDT 2015


Hello!

Im working with libclang3.7~svn242178-1~exp1 (with little modified 
ClangSharp bindings) and i'd like to save and reload serialized 
translation units to improve loading time of C/C++ projects in MonoDevelop.
I use this code snippet to save header files:

CXTranslationUnit save;
ec = clang.parseTranslationUnit2 
(Index,name,null,0,null,0,(uint)CXTranslationUnit_Flags.ForSerialization,out 
save);
error |= ec != CXErrorCode.Success;
if (!error) {
     se = (CXSaveError)clang.saveTranslationUnit (pch, name + ".save", 
clang.defaultSaveOptions (pch));
     error |= se != CXSaveError.CXSaveError_None;
}
clang.disposeTranslationUnit (save);

I checked, the save happens with /CXSaveError_None/, and to load them i 
use this snippet, to show my problem, also reparsing them just after the 
load:

CXTranslationUnit load;
CXErrorCode ec = clang.createTranslationUnit2 (index, fileName + ".pch", 
out load);
uint numDiag = clang.getNumDiagnostics (load);
for (uint i = 0; i < numDiag; i++) {
     CXDiagnostic diag = clang.getDiagnostic (load, i);
     Console.WriteLine ("Loaded TU diagnostic: " + diag);
}
Console.WriteLine ("Loading: " + ec);
if (ec != CXErrorCode.Success)
     return;
else {
     Console.WriteLine ("Reparsing TU: " + 
(CXErrorCode)clang.reparseTranslationUnit (load, 0, null, 
clang.defaultReparseOptions (load)));

The output of the code:

"Loading: Success
Reparsing TU: Failure"

So my questions are:
a., is this normal?
b., if not, what i am doing wrong? I tried to play with parse flags, but 
it made no difference.

c., now i create a new TU just to save it, because saving a TU, 
reparsing it, saving it again causes an a crash in libclang, is this a 
bug or a feature?
Related stacktrace:
libclang37.so(+0x597335) [0x7f4eb89be335]
libclang37.so(+0x5a1e00) [0x7f4eb89c8e00]
libclang37.so(+0x5c10aa) [0x7f4eb89e80aa]
libclang37.so(+0x5c403e) [0x7f4eb89eb03e]
libclang37.so(+0x24551c) [0x7f4eb866c51c]
libclang37.so(+0x253958) [0x7f4eb867a958]
libclang37.so(+0x256c6e) [0x7f4eb867dc6e]
libclang37.so(+0x1a656f) [0x7f4eb85cd56f]
libclang37.so(clang_saveTranslationUnit+0x1ae) [0x7f4eb85e221e]
[0x4201db2b]


Thanks,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20150723/36c29dd9/attachment.html>


More information about the cfe-users mailing list