Index: include/clang-c/Index.h =================================================================== --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -210,6 +210,14 @@ int displayDiagnostics); /** + * \brief Same as clang_createIndex but provides an argument called + * disableCrashRecovery to control whether crash recovery is enabled/disabled. + */ +CINDEX_LINKAGE CXIndex clang_createIndex2(int excludeDeclarationsFromPCH, + int displayDiagnostics, + unsigned disableCrashRecovery); + +/** * \brief Destroy the given index. * * The index must not be destroyed until all of the translation units created Index: tools/libclang/CIndex.cpp =================================================================== --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3068,9 +3068,15 @@ extern "C" { CXIndex clang_createIndex(int excludeDeclarationsFromPCH, int displayDiagnostics) { + return clang_createIndex2(excludeDeclarationsFromPCH, displayDiagnostics, /* disableCrashRecovery */0); +} + +CXIndex clang_createIndex2(int excludeDeclarationsFromPCH, + int displayDiagnostics, + unsigned disableCrashRecovery) { // We use crash recovery to make some of our APIs more reliable, implicitly // enable it. - if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY")) + if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY") && !disableCrashRecovery) llvm::CrashRecoveryContext::Enable(); // Look through the managed static to trigger construction of the managed Index: tools/libclang/libclang.exports =================================================================== --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -109,6 +109,7 @@ clang_constructUSR_ObjCProtocol clang_createCXCursorSet clang_createIndex +clang_createIndex2 clang_createTranslationUnit clang_createTranslationUnit2 clang_createTranslationUnitFromSourceFile