From 80d06eb47648c2f074fe7f94acf3240e665940d0 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 18 May 2021 21:01:50 -0700 Subject: [PATCH] sema_manager: Use llvm::CrashRecoveryContext --- src/sema_manager.cc | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/sema_manager.cc b/src/sema_manager.cc index 805a5ee5..dca5b03b 100644 --- a/src/sema_manager.cc +++ b/src/sema_manager.cc @@ -327,19 +327,26 @@ buildCompilerInstance(Session &session, std::unique_ptr ci, bool parse(CompilerInstance &clang) { SyntaxOnlyAction action; - if (!action.BeginSourceFile(clang, clang.getFrontendOpts().Inputs[0])) - return false; + llvm::CrashRecoveryContext crc; + bool ok = false; + auto run = [&]() { + if (!action.BeginSourceFile(clang, clang.getFrontendOpts().Inputs[0])) + return; #if LLVM_VERSION_MAJOR >= 9 // rL364464 - if (llvm::Error e = action.Execute()) { - llvm::consumeError(std::move(e)); - return false; - } + if (llvm::Error e = action.Execute()) { + llvm::consumeError(std::move(e)); + return; + } #else - if (!action.Execute()) - return false; + if (!action.Execute()) + return; #endif - action.EndSourceFile(); - return true; + action.EndSourceFile(); + ok = true; + }; + if (!crc.RunSafely(run)) + LOG_S(ERROR) << "clang crashed"; + return ok; } void buildPreamble(Session &session, CompilerInvocation &ci,