From: Rafael Espindola Date: Mon, 18 Aug 2014 18:47:08 +0000 (+0000) Subject: return a std::unique_ptr from getMainBufferWithPrecompiledPreamble. NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=623a4f45c0945850e73a9f140744f87c2a04f3fc;p=clang return a std::unique_ptr from getMainBufferWithPrecompiledPreamble. NFC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215927 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index ae1d788162..f92596de7f 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -428,11 +428,10 @@ private: std::pair > ComputePreamble(CompilerInvocation &Invocation, unsigned MaxLines, bool &CreatedBuffer); - - llvm::MemoryBuffer *getMainBufferWithPrecompiledPreamble( - const CompilerInvocation &PreambleInvocationIn, - bool AllowRebuild = true, - unsigned MaxLines = 0); + + std::unique_ptr getMainBufferWithPrecompiledPreamble( + const CompilerInvocation &PreambleInvocationIn, bool AllowRebuild = true, + unsigned MaxLines = 0); void RealizeTopLevelDeclsFromPreamble(); /// \brief Transfers ownership of the objects (like SourceManager) from diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index abab9dc1f3..b39ba1b65a 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -1343,11 +1343,11 @@ static void makeStandaloneDiagnostic(const LangOptions &LangOpts, /// \returns If the precompiled preamble can be used, returns a newly-allocated /// buffer that should be used in place of the main file when doing so. /// Otherwise, returns a NULL pointer. -llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( - const CompilerInvocation &PreambleInvocationIn, - bool AllowRebuild, - unsigned MaxLines) { - +std::unique_ptr +ASTUnit::getMainBufferWithPrecompiledPreamble( + const CompilerInvocation &PreambleInvocationIn, bool AllowRebuild, + unsigned MaxLines) { + IntrusiveRefCntPtr PreambleInvocation(new CompilerInvocation(PreambleInvocationIn)); FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts(); @@ -1451,8 +1451,10 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( PreambleInvocation->getDiagnosticOpts()); getDiagnostics().setNumWarnings(NumWarningsInPreamble); - return llvm::MemoryBuffer::getMemBufferCopy( - NewPreamble.first->getBuffer(), FrontendOpts.Inputs[0].getFile()); + return std::unique_ptr( + llvm::MemoryBuffer::getMemBufferCopy( + NewPreamble.first->getBuffer(), + FrontendOpts.Inputs[0].getFile())); } } @@ -1646,9 +1648,10 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( CompletionCacheTopLevelHashValue = 0; PreambleTopLevelHashValue = CurrentTopLevelHashValue; } - - return llvm::MemoryBuffer::getMemBufferCopy(NewPreamble.first->getBuffer(), - MainFilename); + + return std::unique_ptr( + llvm::MemoryBuffer::getMemBufferCopy(NewPreamble.first->getBuffer(), + MainFilename)); } void ASTUnit::RealizeTopLevelDeclsFromPreamble() { @@ -1885,7 +1888,7 @@ bool ASTUnit::LoadFromCompilerInvocation(bool PrecompilePreamble) { std::unique_ptr OverrideMainBuffer; if (PrecompilePreamble) { PreambleRebuildCounter = 2; - OverrideMainBuffer.reset(getMainBufferWithPrecompiledPreamble(*Invocation)); + OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(*Invocation); } SimpleTimer ParsingTimer(WantTiming); @@ -2047,7 +2050,7 @@ bool ASTUnit::Reparse(ArrayRef RemappedFiles) { // build a precompiled preamble, do so now. std::unique_ptr OverrideMainBuffer; if (!getPreambleFile(this).empty() || PreambleRebuildCounter > 0) - OverrideMainBuffer.reset(getMainBufferWithPrecompiledPreamble(*Invocation)); + OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(*Invocation); // Clear out the diagnostics state. getDiagnostics().Reset(); @@ -2410,7 +2413,7 @@ void ASTUnit::CodeComplete(StringRef File, unsigned Line, unsigned Column, // the use of the precompiled preamble if we're if the completion // point is within the main file, after the end of the precompiled // preamble. - llvm::MemoryBuffer *OverrideMainBuffer = nullptr; + std::unique_ptr OverrideMainBuffer; if (!getPreambleFile(this).empty()) { std::string CompleteFilePath(File); llvm::sys::fs::UniqueID CompleteFileID; @@ -2420,9 +2423,8 @@ void ASTUnit::CodeComplete(StringRef File, unsigned Line, unsigned Column, llvm::sys::fs::UniqueID MainID; if (!llvm::sys::fs::getUniqueID(MainPath, MainID)) { if (CompleteFileID == MainID && Line > 1) - OverrideMainBuffer - = getMainBufferWithPrecompiledPreamble(*CCInvocation, false, - Line - 1); + OverrideMainBuffer = getMainBufferWithPrecompiledPreamble( + *CCInvocation, false, Line - 1); } } } @@ -2430,14 +2432,15 @@ void ASTUnit::CodeComplete(StringRef File, unsigned Line, unsigned Column, // If the main file has been overridden due to the use of a preamble, // make that override happen and introduce the preamble. if (OverrideMainBuffer) { - PreprocessorOpts.addRemappedFile(OriginalSourceFile, OverrideMainBuffer); + PreprocessorOpts.addRemappedFile(OriginalSourceFile, + OverrideMainBuffer.get()); PreprocessorOpts.PrecompiledPreambleBytes.first = Preamble.size(); PreprocessorOpts.PrecompiledPreambleBytes.second = PreambleEndsAtStartOfLine; PreprocessorOpts.ImplicitPCHInclude = getPreambleFile(this); PreprocessorOpts.DisablePCHValidation = true; - - OwnedBuffers.push_back(OverrideMainBuffer); + + OwnedBuffers.push_back(OverrideMainBuffer.release()); } else { PreprocessorOpts.PrecompiledPreambleBytes.first = 0; PreprocessorOpts.PrecompiledPreambleBytes.second = false;