From aa2b9952ef98a5fe2d47384ef17106855b8bae51 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 14 Nov 2017 09:34:39 +0000 Subject: [PATCH] [libclang] Allow crash recovery with LIBCLANG_NOTHREADS Enabled crash recovery for some libclang operations on a calling thread even when LIBCLANG_NOTHREAD is specified. Previously it would only run under crash recovery if LIBCLANG_NOTHREAD is not set. Moved handling of LIBCLANG_NOTHREAD env variable into RunSafely from its call sites. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318142 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/libclang/CIndex.cpp | 15 ++------------- tools/libclang/CIndexCodeCompletion.cpp | 5 ----- tools/libclang/Indexing.cpp | 10 ---------- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index fa3b970855..2a1b63d83e 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -3508,11 +3508,6 @@ enum CXErrorCode clang_parseTranslationUnit2FullArgv( llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, out_TU); }; - if (getenv("LIBCLANG_NOTHREADS")) { - ParseTranslationUnitImpl(); - return result; - } - llvm::CrashRecoveryContext CRC; if (!RunSafely(CRC, ParseTranslationUnitImpl)) { @@ -3921,8 +3916,7 @@ int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName, result = clang_saveTranslationUnit_Impl(TU, FileName, options); }; - if (!CXXUnit->getDiagnostics().hasUnrecoverableErrorOccurred() || - getenv("LIBCLANG_NOTHREADS")) { + if (!CXXUnit->getDiagnostics().hasUnrecoverableErrorOccurred()) { SaveTranslationUnitImpl(); if (getenv("LIBCLANG_RESOURCE_USAGE")) @@ -4045,11 +4039,6 @@ int clang_reparseTranslationUnit(CXTranslationUnit TU, TU, llvm::makeArrayRef(unsaved_files, num_unsaved_files), options); }; - if (getenv("LIBCLANG_NOTHREADS")) { - ReparseTranslationUnitImpl(); - return result; - } - llvm::CrashRecoveryContext CRC; if (!RunSafely(CRC, ReparseTranslationUnitImpl)) { @@ -8164,7 +8153,7 @@ bool RunSafely(llvm::CrashRecoveryContext &CRC, llvm::function_ref Fn, unsigned Size) { if (!Size) Size = GetSafetyThreadStackSize(); - if (Size) + if (Size && !getenv("LIBCLANG_NOTHREADS")) return CRC.RunSafelyOnThread(Fn, Size); return CRC.RunSafely(Fn); } diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp index c2b4c0bcb0..2f32dc24e5 100644 --- a/tools/libclang/CIndexCodeCompletion.cpp +++ b/tools/libclang/CIndexCodeCompletion.cpp @@ -806,11 +806,6 @@ CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU, llvm::makeArrayRef(unsaved_files, num_unsaved_files), options); }; - if (getenv("LIBCLANG_NOTHREADS")) { - CodeCompleteAtImpl(); - return result; - } - llvm::CrashRecoveryContext CRC; if (!RunSafely(CRC, CodeCompleteAtImpl)) { diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp index 2a136242ef..021ebcfcfe 100644 --- a/tools/libclang/Indexing.cpp +++ b/tools/libclang/Indexing.cpp @@ -880,11 +880,6 @@ int clang_indexSourceFileFullArgv( TU_options); }; - if (getenv("LIBCLANG_NOTHREADS")) { - IndexSourceFileImpl(); - return result; - } - llvm::CrashRecoveryContext CRC; if (!RunSafely(CRC, IndexSourceFileImpl)) { @@ -934,11 +929,6 @@ int clang_indexTranslationUnit(CXIndexAction idxAction, index_options, TU); }; - if (getenv("LIBCLANG_NOTHREADS")) { - IndexTranslationUnitImpl(); - return result; - } - llvm::CrashRecoveryContext CRC; if (!RunSafely(CRC, IndexTranslationUnitImpl)) { -- 2.40.0