From 811db4eac4e036de3705570a46e28bf7d993dbab Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 23 Oct 2012 22:26:28 +0000 Subject: Make DiagnosticOptions intrusively reference-counted, and make sure the various stakeholders bump up the reference count. In particular, the diagnostics engine now keeps the DiagnosticOptions object alive. llvm-svn: 166508 --- clang/tools/libclang/CIndex.cpp | 6 +++--- clang/tools/libclang/CIndexCodeCompletion.cpp | 6 +++++- clang/tools/libclang/CIndexDiagnostic.cpp | 8 ++++---- clang/tools/libclang/Indexing.cpp | 12 ++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) (limited to 'clang/tools/libclang') diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index f3c91e31b4d..3a6c408bff1 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -2559,10 +2559,10 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { bool ForSerialization = options & CXTranslationUnit_ForSerialization; // Configure the diagnostics. - DiagnosticOptions DiagOpts; IntrusiveRefCntPtr - Diags(CompilerInstance::createDiagnostics(DiagOpts, num_command_line_args, - command_line_args)); + Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions, + num_command_line_args, + command_line_args)); // Recover resources if we crash before exiting this function. llvm::CrashRecoveryContextCleanupRegistrar Diagnostics; + IntrusiveRefCntPtr DiagOpts; + /// \brief Diag object IntrusiveRefCntPtr Diag; @@ -305,8 +307,10 @@ static llvm::sys::cas_flag CodeCompletionResultObjects; AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults( const FileSystemOptions& FileSystemOpts) : CXCodeCompleteResults(), + DiagOpts(new DiagnosticOptions), Diag(new DiagnosticsEngine( - IntrusiveRefCntPtr(new DiagnosticIDs))), + IntrusiveRefCntPtr(new DiagnosticIDs), + &*DiagOpts)), FileSystemOpts(FileSystemOpts), FileMgr(new FileManager(FileSystemOpts)), SourceMgr(new SourceManager(*Diag, *FileMgr)), diff --git a/clang/tools/libclang/CIndexDiagnostic.cpp b/clang/tools/libclang/CIndexDiagnostic.cpp index 14722e01849..3154480ae19 100644 --- a/clang/tools/libclang/CIndexDiagnostic.cpp +++ b/clang/tools/libclang/CIndexDiagnostic.cpp @@ -19,7 +19,7 @@ #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/DiagnosticRenderer.h" -#include "clang/Frontend/DiagnosticOptions.h" +#include "clang/Basic/DiagnosticOptions.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/MemoryBuffer.h" @@ -87,7 +87,7 @@ public: class CXDiagnosticRenderer : public DiagnosticNoteRenderer { public: CXDiagnosticRenderer(const LangOptions &LangOpts, - const DiagnosticOptions &DiagOpts, + DiagnosticOptions *DiagOpts, CXDiagnosticSetImpl *mainSet) : DiagnosticNoteRenderer(LangOpts, DiagOpts), CurrentSet(mainSet), MainSet(mainSet) {} @@ -191,9 +191,9 @@ CXDiagnosticSetImpl *cxdiag::lazyCreateDiags(CXTranslationUnit TU, if (!TU->Diagnostics) { CXDiagnosticSetImpl *Set = new CXDiagnosticSetImpl(); TU->Diagnostics = Set; - DiagnosticOptions DOpts; + llvm::IntrusiveRefCntPtr DOpts = new DiagnosticOptions; CXDiagnosticRenderer Renderer(AU->getASTContext().getLangOpts(), - DOpts, Set); + &*DOpts, Set); for (ASTUnit::stored_diag_iterator it = AU->stored_diag_begin(), ei = AU->stored_diag_end(); it != ei; ++it) { diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index 36442fa2324..714a36ebddf 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -290,13 +290,13 @@ static void clang_indexSourceFile_Impl(void *UserData) { CaptureDiagnosticConsumer *CaptureDiag = new CaptureDiagnosticConsumer(); // Configure the diagnostics. - DiagnosticOptions DiagOpts; IntrusiveRefCntPtr - Diags(CompilerInstance::createDiagnostics(DiagOpts, num_command_line_args, - command_line_args, - CaptureDiag, - /*ShouldOwnClient=*/true, - /*ShouldCloneClient=*/false)); + Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions, + num_command_line_args, + command_line_args, + CaptureDiag, + /*ShouldOwnClient=*/true, + /*ShouldCloneClient=*/false)); // Recover resources if we crash before exiting this function. llvm::CrashRecoveryContextCleanupRegistrar