diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-04-05 21:10:19 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-04-05 21:10:19 +0000 |
commit | d03e823fb43be47f8fe3c651bfcf8a3254c3fe1c (patch) | |
tree | c6f260659019cb36d845c73fb880e27203624c9e /clang/tools/CIndex/CIndex.cpp | |
parent | 41e692dcf1399068dcdc90df160cb432d567ec50 (diff) | |
download | bcm5719-llvm-d03e823fb43be47f8fe3c651bfcf8a3254c3fe1c.tar.gz bcm5719-llvm-d03e823fb43be47f8fe3c651bfcf8a3254c3fe1c.zip |
Clarify the ownership semantics of the Diagnostic object used by
ASTUnit. Previously, we would end up with use-after-free errors
because the Diagnostic object would be creating in one place (say,
CIndex) and its ownership would not be transferred into the
ASTUnit. Fixes <rdar://problem/7818608>.
llvm-svn: 100464
Diffstat (limited to 'clang/tools/CIndex/CIndex.cpp')
-rw-r--r-- | clang/tools/CIndex/CIndex.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp index 9db5ba79cef..a6e284e904f 100644 --- a/clang/tools/CIndex/CIndex.cpp +++ b/clang/tools/CIndex/CIndex.cpp @@ -996,11 +996,7 @@ CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx, CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx); - // Configure the diagnostics. - DiagnosticOptions DiagOpts; - llvm::OwningPtr<Diagnostic> Diags; - Diags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0)); - return ASTUnit::LoadFromPCHFile(ast_filename, *Diags, + return ASTUnit::LoadFromPCHFile(ast_filename, DefaultDiag(), CXXIdx->getOnlyLocalDecls(), 0, 0, true); } @@ -1019,8 +1015,8 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, // Configure the diagnostics. DiagnosticOptions DiagOpts; - llvm::OwningPtr<Diagnostic> Diags; - Diags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0)); + llvm::MaybeOwningPtr<Diagnostic> Diags; + Diags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0), true); llvm::SmallVector<ASTUnit::RemappedFile, 4> RemappedFiles; for (unsigned I = 0; I != num_unsaved_files; ++I) { @@ -1052,7 +1048,7 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, llvm::OwningPtr<ASTUnit> Unit( ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(), - *Diags, + Diags, CXXIdx->getClangResourcesPath(), CXXIdx->getOnlyLocalDecls(), RemappedFiles.data(), @@ -1169,7 +1165,7 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, Diags->Report(diag::err_fe_invoking) << AllArgs << ErrMsg; } - ASTUnit *ATU = ASTUnit::LoadFromPCHFile(astTmpFile, *Diags, + ASTUnit *ATU = ASTUnit::LoadFromPCHFile(astTmpFile, Diags, CXXIdx->getOnlyLocalDecls(), RemappedFiles.data(), RemappedFiles.size(), |