aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp69
1 files changed, 40 insertions, 29 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index c7b82db..d64290f 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -87,8 +87,9 @@ bool CompilerInstance::shouldBuildGlobalModuleIndex() const {
!DisableGeneratingGlobalModuleIndex;
}
-void CompilerInstance::setDiagnostics(DiagnosticsEngine *Value) {
- Diagnostics = Value;
+void CompilerInstance::setDiagnostics(
+ llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Value) {
+ Diagnostics = std::move(Value);
}
void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) {
@@ -160,20 +161,28 @@ llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem() const {
return getFileManager().getVirtualFileSystem();
}
-void CompilerInstance::setFileManager(FileManager *Value) {
- FileMgr = Value;
+llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
+CompilerInstance::getVirtualFileSystemPtr() const {
+ return getFileManager().getVirtualFileSystemPtr();
}
-void CompilerInstance::setSourceManager(SourceManager *Value) {
- SourceMgr = Value;
+void CompilerInstance::setFileManager(
+ llvm::IntrusiveRefCntPtr<FileManager> Value) {
+ FileMgr = std::move(Value);
+}
+
+void CompilerInstance::setSourceManager(
+ llvm::IntrusiveRefCntPtr<SourceManager> Value) {
+ SourceMgr = std::move(Value);
}
void CompilerInstance::setPreprocessor(std::shared_ptr<Preprocessor> Value) {
PP = std::move(Value);
}
-void CompilerInstance::setASTContext(ASTContext *Value) {
- Context = Value;
+void CompilerInstance::setASTContext(
+ llvm::IntrusiveRefCntPtr<ASTContext> Value) {
+ Context = std::move(Value);
if (Context && Consumer)
getASTConsumer().Initialize(getASTContext());
@@ -340,9 +349,8 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
llvm::vfs::FileSystem &VFS, DiagnosticOptions &Opts,
DiagnosticConsumer *Client, bool ShouldOwnClient,
const CodeGenOptions *CodeGenOpts) {
- IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
- IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
- new DiagnosticsEngine(DiagID, Opts));
+ auto Diags = llvm::makeIntrusiveRefCnt<DiagnosticsEngine>(
+ DiagnosticIDs::create(), Opts);
// Create the diagnostic client for reporting errors or for
// implementing -verify.
@@ -375,21 +383,23 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
FileManager *CompilerInstance::createFileManager(
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
if (!VFS)
- VFS = FileMgr ? &FileMgr->getVirtualFileSystem()
+ VFS = FileMgr ? FileMgr->getVirtualFileSystemPtr()
: createVFSFromCompilerInvocation(getInvocation(),
getDiagnostics());
assert(VFS && "FileManager has no VFS?");
if (getFrontendOpts().ShowStats)
VFS =
llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(std::move(VFS));
- FileMgr = new FileManager(getFileSystemOpts(), std::move(VFS));
+ FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(getFileSystemOpts(),
+ std::move(VFS));
return FileMgr.get();
}
// Source Manager
void CompilerInstance::createSourceManager(FileManager &FileMgr) {
- SourceMgr = new SourceManager(getDiagnostics(), FileMgr);
+ SourceMgr =
+ llvm::makeIntrusiveRefCnt<SourceManager>(getDiagnostics(), FileMgr);
}
// Initialize the remapping of files to alternative contents, e.g.,
@@ -549,11 +559,11 @@ std::string CompilerInstance::getSpecificModuleCachePath(StringRef ModuleHash) {
void CompilerInstance::createASTContext() {
Preprocessor &PP = getPreprocessor();
- auto *Context = new ASTContext(getLangOpts(), PP.getSourceManager(),
- PP.getIdentifierTable(), PP.getSelectorTable(),
- PP.getBuiltinInfo(), PP.TUKind);
+ auto Context = llvm::makeIntrusiveRefCnt<ASTContext>(
+ getLangOpts(), PP.getSourceManager(), PP.getIdentifierTable(),
+ PP.getSelectorTable(), PP.getBuiltinInfo(), PP.TUKind);
Context->InitBuiltinTypes(getTarget(), getAuxTarget());
- setASTContext(Context);
+ setASTContext(std::move(Context));
}
// ExternalASTSource
@@ -633,17 +643,17 @@ IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource(
const HeaderSearchOptions &HSOpts =
PP.getHeaderSearchInfo().getHeaderSearchOpts();
- IntrusiveRefCntPtr<ASTReader> Reader(new ASTReader(
+ auto Reader = llvm::makeIntrusiveRefCnt<ASTReader>(
PP, ModCache, &Context, PCHContainerRdr, CodeGenOpts, Extensions,
Sysroot.empty() ? "" : Sysroot.data(), DisableValidation,
AllowPCHWithCompilerErrors, /*AllowConfigurationMismatch*/ false,
HSOpts.ModulesValidateSystemHeaders,
HSOpts.ModulesForceValidateUserHeaders,
- HSOpts.ValidateASTInputFilesContent, UseGlobalModuleIndex));
+ HSOpts.ValidateASTInputFilesContent, UseGlobalModuleIndex);
// We need the external source to be set up before we read the AST, because
// eagerly-deserialized declarations may use it.
- Context.setExternalSource(Reader.get());
+ Context.setExternalSource(Reader);
Reader->setDeserializationListener(
static_cast<ASTDeserializationListener *>(DeserializationListener),
@@ -750,7 +760,7 @@ void CompilerInstance::createSema(TranslationUnitKind TUKind,
// Attach the external sema source if there is any.
if (ExternalSemaSrc) {
- TheSema->addExternalSource(ExternalSemaSrc.get());
+ TheSema->addExternalSource(ExternalSemaSrc);
ExternalSemaSrc->InitializeSema(*TheSema);
}
@@ -1216,9 +1226,9 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
if (ThreadSafeConfig) {
Instance.createFileManager(ThreadSafeConfig->getVFS());
} else if (FrontendOpts.ModulesShareFileManager) {
- Instance.setFileManager(&getFileManager());
+ Instance.setFileManager(getFileManagerPtr());
} else {
- Instance.createFileManager(&getVirtualFileSystem());
+ Instance.createFileManager(getVirtualFileSystemPtr());
}
if (ThreadSafeConfig) {
@@ -1745,17 +1755,18 @@ void CompilerInstance::createASTReader() {
if (timerGroup)
ReadTimer = std::make_unique<llvm::Timer>("reading_modules",
"Reading modules", *timerGroup);
- TheASTReader = new ASTReader(
+ TheASTReader = llvm::makeIntrusiveRefCnt<ASTReader>(
getPreprocessor(), getModuleCache(), &getASTContext(),
getPCHContainerReader(), getCodeGenOpts(),
getFrontendOpts().ModuleFileExtensions,
Sysroot.empty() ? "" : Sysroot.c_str(),
PPOpts.DisablePCHOrModuleValidation,
/*AllowASTWithCompilerErrors=*/FEOpts.AllowPCMWithCompilerErrors,
- /*AllowConfigurationMismatch=*/false, HSOpts.ModulesValidateSystemHeaders,
- HSOpts.ModulesForceValidateUserHeaders,
- HSOpts.ValidateASTInputFilesContent,
- getFrontendOpts().UseGlobalModuleIndex, std::move(ReadTimer));
+ /*AllowConfigurationMismatch=*/false,
+ +HSOpts.ModulesValidateSystemHeaders,
+ +HSOpts.ModulesForceValidateUserHeaders,
+ +HSOpts.ValidateASTInputFilesContent,
+ +getFrontendOpts().UseGlobalModuleIndex, std::move(ReadTimer));
if (hasASTConsumer()) {
TheASTReader->setDeserializationListener(
getASTConsumer().GetASTDeserializationListener());