From d03e823fb43be47f8fe3c651bfcf8a3254c3fe1c Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 5 Apr 2010 21:10:19 +0000 Subject: 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 . llvm-svn: 100464 --- clang/tools/CIndex/CIndex.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'clang/tools/CIndex/CIndex.cpp') 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(CIdx); - // Configure the diagnostics. - DiagnosticOptions DiagOpts; - llvm::OwningPtr 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 Diags; - Diags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0)); + llvm::MaybeOwningPtr Diags; + Diags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0), true); llvm::SmallVector RemappedFiles; for (unsigned I = 0; I != num_unsaved_files; ++I) { @@ -1052,7 +1048,7 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, llvm::OwningPtr 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(), -- cgit v1.2.3