aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Frontend
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-03-21 18:40:17 +0000
committerTed Kremenek <kremenek@apple.com>2011-03-21 18:40:17 +0000
commit4f32786ac45210143654390177105eb749b614e9 (patch)
tree289b0c67da849bf045e5c03605f9fbfc80c23d01 /include/clang/Frontend
parentcd1eecfe4f43a542c8f9a6e7d12fa69b28c23a67 (diff)
Improve crash recovery cleanup to recovery CompilerInstances during crash recovery. This was a huge resource "root" during crashes.
This change requires making a bunch of fundamental Clang structures (optionally) reference counted to allow correct ownership semantics of these objects (e.g., ASTContext) to play out between an active ASTUnit and CompilerInstance object. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128011 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Frontend')
-rw-r--r--include/clang/Frontend/ASTUnit.h20
-rw-r--r--include/clang/Frontend/CompilerInstance.h73
-rw-r--r--include/clang/Frontend/CompilerInvocation.h3
3 files changed, 44 insertions, 52 deletions
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h
index a0c99f12e9..57c59d951e 100644
--- a/include/clang/Frontend/ASTUnit.h
+++ b/include/clang/Frontend/ASTUnit.h
@@ -71,12 +71,12 @@ public:
private:
llvm::IntrusiveRefCntPtr<Diagnostic> Diagnostics;
- llvm::OwningPtr<FileManager> FileMgr;
- llvm::OwningPtr<SourceManager> SourceMgr;
+ llvm::IntrusiveRefCntPtr<FileManager> FileMgr;
+ llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr;
llvm::OwningPtr<HeaderSearch> HeaderInfo;
- llvm::OwningPtr<TargetInfo> Target;
- llvm::OwningPtr<Preprocessor> PP;
- llvm::OwningPtr<ASTContext> Ctx;
+ llvm::IntrusiveRefCntPtr<TargetInfo> Target;
+ llvm::IntrusiveRefCntPtr<Preprocessor> PP;
+ llvm::IntrusiveRefCntPtr<ASTContext> Ctx;
FileSystemOptions FileSystemOpts;
@@ -90,7 +90,7 @@ private:
/// Optional owned invocation, just used to make the invocation used in
/// LoadFromCommandLine available.
- llvm::OwningPtr<CompilerInvocation> Invocation;
+ llvm::IntrusiveRefCntPtr<CompilerInvocation> Invocation;
/// \brief The set of target features.
///
@@ -396,11 +396,11 @@ public:
const SourceManager &getSourceManager() const { return *SourceMgr; }
SourceManager &getSourceManager() { return *SourceMgr; }
- const Preprocessor &getPreprocessor() const { return *PP.get(); }
- Preprocessor &getPreprocessor() { return *PP.get(); }
+ const Preprocessor &getPreprocessor() const { return *PP; }
+ Preprocessor &getPreprocessor() { return *PP; }
- const ASTContext &getASTContext() const { return *Ctx.get(); }
- ASTContext &getASTContext() { return *Ctx.get(); }
+ const ASTContext &getASTContext() const { return *Ctx; }
+ ASTContext &getASTContext() { return *Ctx; }
bool hasSema() const { return TheSema; }
Sema &getSema() const {
diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h
index 7ea79e5599..2c37c9568e 100644
--- a/include/clang/Frontend/CompilerInstance.h
+++ b/include/clang/Frontend/CompilerInstance.h
@@ -59,25 +59,25 @@ class TargetInfo;
/// and a long form that takes explicit instances of any required objects.
class CompilerInstance {
/// The options used in this compiler instance.
- llvm::OwningPtr<CompilerInvocation> Invocation;
+ llvm::IntrusiveRefCntPtr<CompilerInvocation> Invocation;
/// The diagnostics engine instance.
llvm::IntrusiveRefCntPtr<Diagnostic> Diagnostics;
/// The target being compiled for.
- llvm::OwningPtr<TargetInfo> Target;
+ llvm::IntrusiveRefCntPtr<TargetInfo> Target;
/// The file manager.
- llvm::OwningPtr<FileManager> FileMgr;
+ llvm::IntrusiveRefCntPtr<FileManager> FileMgr;
/// The source manager.
- llvm::OwningPtr<SourceManager> SourceMgr;
+ llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr;
/// The preprocessor.
- llvm::OwningPtr<Preprocessor> PP;
+ llvm::IntrusiveRefCntPtr<Preprocessor> PP;
/// The AST context.
- llvm::OwningPtr<ASTContext> Context;
+ llvm::IntrusiveRefCntPtr<ASTContext> Context;
/// The AST consumer.
llvm::OwningPtr<ASTConsumer> Consumer;
@@ -161,10 +161,7 @@ public:
return *Invocation;
}
- CompilerInvocation *takeInvocation() { return Invocation.take(); }
-
- /// setInvocation - Replace the current invocation; the compiler instance
- /// takes ownership of \arg Value.
+ /// setInvocation - Replace the current invocation.
void setInvocation(CompilerInvocation *Value);
/// }
@@ -251,13 +248,13 @@ public:
bool hasDiagnostics() const { return Diagnostics != 0; }
+ /// Get the current diagnostics engine.
Diagnostic &getDiagnostics() const {
assert(Diagnostics && "Compiler instance has no diagnostics!");
return *Diagnostics;
}
- /// setDiagnostics - Replace the current diagnostics engine; the compiler
- /// instance takes ownership of \arg Value.
+ /// setDiagnostics - Replace the current diagnostics engine.
void setDiagnostics(Diagnostic *Value);
DiagnosticClient &getDiagnosticClient() const {
@@ -277,12 +274,7 @@ public:
return *Target;
}
- /// takeTarget - Remove the current diagnostics engine and give ownership
- /// to the caller.
- TargetInfo *takeTarget() { return Target.take(); }
-
- /// setTarget - Replace the current diagnostics engine; the compiler
- /// instance takes ownership of \arg Value.
+ /// Replace the current diagnostics engine.
void setTarget(TargetInfo *Value);
/// }
@@ -291,17 +283,17 @@ public:
bool hasFileManager() const { return FileMgr != 0; }
+ /// Return the current file manager to the caller.
FileManager &getFileManager() const {
assert(FileMgr && "Compiler instance has no file manager!");
return *FileMgr;
}
+
+ void resetAndLeakFileManager() {
+ FileMgr.resetWithoutRelease();
+ }
- /// takeFileManager - Remove the current file manager and give ownership to
- /// the caller.
- FileManager *takeFileManager() { return FileMgr.take(); }
-
- /// setFileManager - Replace the current file manager; the compiler instance
- /// takes ownership of \arg Value.
+ /// setFileManager - Replace the current file manager.
void setFileManager(FileManager *Value);
/// }
@@ -310,17 +302,17 @@ public:
bool hasSourceManager() const { return SourceMgr != 0; }
+ /// Return the current source manager.
SourceManager &getSourceManager() const {
assert(SourceMgr && "Compiler instance has no source manager!");
return *SourceMgr;
}
+
+ void resetAndLeakSourceManager() {
+ SourceMgr.resetWithoutRelease();
+ }
- /// takeSourceManager - Remove the current source manager and give ownership
- /// to the caller.
- SourceManager *takeSourceManager() { return SourceMgr.take(); }
-
- /// setSourceManager - Replace the current source manager; the compiler
- /// instance takes ownership of \arg Value.
+ /// setSourceManager - Replace the current source manager.
void setSourceManager(SourceManager *Value);
/// }
@@ -329,17 +321,17 @@ public:
bool hasPreprocessor() const { return PP != 0; }
+ /// Return the current preprocessor.
Preprocessor &getPreprocessor() const {
assert(PP && "Compiler instance has no preprocessor!");
return *PP;
}
- /// takePreprocessor - Remove the current preprocessor and give ownership to
- /// the caller.
- Preprocessor *takePreprocessor() { return PP.take(); }
+ void resetAndLeakPreprocessor() {
+ PP.resetWithoutRelease();
+ }
- /// setPreprocessor - Replace the current preprocessor; the compiler instance
- /// takes ownership of \arg Value.
+ /// Replace the current preprocessor.
void setPreprocessor(Preprocessor *Value);
/// }
@@ -352,13 +344,12 @@ public:
assert(Context && "Compiler instance has no AST context!");
return *Context;
}
+
+ void resetAndLeakASTContext() {
+ Context.resetWithoutRelease();
+ }
- /// takeASTContext - Remove the current AST context and give ownership to the
- /// caller.
- ASTContext *takeASTContext() { return Context.take(); }
-
- /// setASTContext - Replace the current AST context; the compiler instance
- /// takes ownership of \arg Value.
+ /// setASTContext - Replace the current AST context.
void setASTContext(ASTContext *Value);
/// \brief Replace the current Sema; the compiler instance takes ownership
diff --git a/include/clang/Frontend/CompilerInvocation.h b/include/clang/Frontend/CompilerInvocation.h
index e0329dbc96..e18f3fe632 100644
--- a/include/clang/Frontend/CompilerInvocation.h
+++ b/include/clang/Frontend/CompilerInvocation.h
@@ -22,6 +22,7 @@
#include "clang/Frontend/LangStandard.h"
#include "clang/Frontend/PreprocessorOptions.h"
#include "clang/Frontend/PreprocessorOutputOptions.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringMap.h"
#include <string>
@@ -41,7 +42,7 @@ class Diagnostic;
/// This class is designed to represent an abstract "invocation" of the
/// compiler, including data such as the include paths, the code generation
/// options, the warning flags, and so on.
-class CompilerInvocation {
+class CompilerInvocation : public llvm::RefCountedBase<CompilerInvocation> {
/// Options controlling the static analyzer.
AnalyzerOptions AnalyzerOpts;