aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-03-18 02:06:56 +0000
committerTed Kremenek <kremenek@apple.com>2011-03-18 02:06:56 +0000
commitb547eebdffb07dbc2a8239ca93b696b051096933 (patch)
tree6df28443a157b822d424f937183c3d6e0b5aee3d /lib/Frontend/ASTUnit.cpp
parent965fe844ceb6b840f79c7987deaed48ee30d070d (diff)
Use CrashRecoveryContextCleanup objects to recover an ASTUnit if we crash in ASTUnit::LoadFromCommandLine() and ASTUnit::LoadFromCompilerInvocation().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127851 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ASTUnit.cpp')
-rw-r--r--lib/Frontend/ASTUnit.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 41f2442a11..3eb418c39b 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -44,6 +44,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Timer.h"
+#include "llvm/Support/CrashRecoveryContext.h"
#include <cstdlib>
#include <cstdio>
#include <sys/stat.h>
@@ -500,6 +501,12 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
unsigned NumRemappedFiles,
bool CaptureDiagnostics) {
llvm::OwningPtr<ASTUnit> AST(new ASTUnit(true));
+
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar
+ ASTUnitCleanup(llvm::CrashRecoveryContextCleanup::
+ create<ASTUnit>(AST.get()));
+
ConfigureDiags(Diags, 0, 0, *AST, CaptureDiagnostics);
AST->OnlyLocalDecls = OnlyLocalDecls;
@@ -1579,6 +1586,11 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
AST->Invocation.reset(CI);
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar
+ ASTUnitCleanup(llvm::CrashRecoveryContextCleanup::
+ create<ASTUnit>(AST.get()));
+
return AST->LoadFromCompilerInvocation(PrecompilePreamble)? 0 : AST.take();
}
@@ -1704,6 +1716,12 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
AST->NumStoredDiagnosticsInPreamble = StoredDiagnostics.size();
AST->StoredDiagnostics.swap(StoredDiagnostics);
AST->Invocation.reset(CI.take());
+
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar
+ ASTUnitCleanup(llvm::CrashRecoveryContextCleanup::
+ create<ASTUnit>(AST.get()));
+
return AST->LoadFromCompilerInvocation(PrecompilePreamble) ? 0 : AST.take();
}