[cfe-dev] [PATCH] libclang: report error code for bad PCH files
Dmitri Gribenko
gribozavr at gmail.com
Tue Feb 11 09:41:15 PST 2014
Hello,
The attached patch improves libclang to report the error condition
when CXTranslationUnit can not be created because of a stale PCH file.
This allows the caller, for example, to rebuild the PCH file and
retry the request.
There are APIs like clang_parseTranslationUnit(), which don't support
reporting detailed errors (the only error condition is a NULL result).
Because of this, in order to add this feature without breaking binary
compatibility, I propose to add a new API,
clang_TranslationUnit_hasFailure(), which checks if the TU is usable.
Then other APIs will return a non-NULL TU that is marked as erroneous,
and passing the erroneous TU to any API is a no-op.
My only concern is about clang_indexSourceFile function. On error, it
used to return NULL in out_TU. We might have clients that assume this
and don't dispose the returned TU if error is signaled. Now the
function can return an erroneous TU that should be disposed, otherwise
it is leaked.
As an alternative, in order not to introduce a possible memory leak in
clang_indexSourceFile, we could do the following. Instead of
allocating a block of memory to return as an erroneous TU, we could
use a magic pointer value, or an address of a static constant
"TheErroneousTU".
Argyrios, which way do you prefer?
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libclang-report-error-code-for-bad-pch-v1.patch
Type: application/octet-stream
Size: 16683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140211/0d5c5dcb/attachment.obj>
More information about the cfe-dev
mailing list