diff options
Diffstat (limited to 'clang/tools/libclang/Indexing.cpp')
-rw-r--r-- | clang/tools/libclang/Indexing.cpp | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index dc7a0c0714b..9b83aa00e9f 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -514,16 +514,22 @@ static void clang_indexSourceFile_Impl(void *UserData) { unsigned num_unsaved_files = ITUI->num_unsaved_files; CXTranslationUnit *out_TU = ITUI->out_TU; unsigned TU_options = ITUI->TU_options; - ITUI->result = 1; // init as error. - + + // Set up the initial return value. + ITUI->result = CXError_Failure; + if (out_TU) *out_TU = 0; - bool requestedToGetTU = (out_TU != 0); + bool requestedToGetTU = (out_TU != 0); - if (!cxIdxAction) + if (!cxIdxAction) { + ITUI->result = CXError_InvalidArguments; return; - if (!client_index_callbacks || index_callbacks_size == 0) + } + if (!client_index_callbacks || index_callbacks_size == 0) { + ITUI->result = CXError_InvalidArguments; return; + } IndexerCallbacks CB; memset(&CB, 0, sizeof(CB)); @@ -671,13 +677,18 @@ static void clang_indexSourceFile_Impl(void *UserData) { if (DiagTrap.hasErrorOccurred() && CXXIdx->getDisplayDiagnostics()) printDiagsToStderr(Unit); + if (isASTReadError(Unit)) { + ITUI->result = CXError_ASTReadError; + return; + } + if (!Success) return; if (out_TU) *out_TU = CXTU->takeTU(); - ITUI->result = 0; // success. + ITUI->result = CXError_Success; } //===----------------------------------------------------------------------===// @@ -754,14 +765,20 @@ static void clang_indexTranslationUnit_Impl(void *UserData) { IndexerCallbacks *client_index_callbacks = ITUI->index_callbacks; unsigned index_callbacks_size = ITUI->index_callbacks_size; unsigned index_options = ITUI->index_options; - ITUI->result = 1; // init as error. + // Set up the initial return value. + ITUI->result = CXError_Failure; + + // Check arguments. if (isNotUsableTU(TU)) { LOG_BAD_TU(TU); + ITUI->result = CXError_InvalidArguments; return; } - if (!client_index_callbacks || index_callbacks_size == 0) + if (!client_index_callbacks || index_callbacks_size == 0) { + ITUI->result = CXError_InvalidArguments; return; + } CIndexer *CXXIdx = TU->CIdx; if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing)) @@ -809,7 +826,7 @@ static void clang_indexTranslationUnit_Impl(void *UserData) { indexTranslationUnit(*Unit, *IndexCtx); indexDiagnostics(TU, *IndexCtx); - ITUI->result = 0; + ITUI->result = CXError_Success; } //===----------------------------------------------------------------------===// @@ -981,7 +998,8 @@ int clang_indexSourceFile(CXIndexAction idxAction, index_callbacks_size, index_options, source_filename, command_line_args, num_command_line_args, unsaved_files, - num_unsaved_files, out_TU, TU_options, 0 }; + num_unsaved_files, out_TU, TU_options, + CXError_Failure }; if (getenv("LIBCLANG_NOTHREADS")) { clang_indexSourceFile_Impl(&ITUI); |