From: Duncan P. N. Exon Smith Date: Wed, 14 Oct 2020 17:28:34 +0000 (-0400) Subject: clang/Frontend: Mostly stop using SourceManager::getBuffer, NFC X-Git-Tag: llvmorg-13-init~9226 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=63af2422798188d70a411f76b0f06ab63a783a0d;p=platform%2Fupstream%2Fllvm.git clang/Frontend: Mostly stop using SourceManager::getBuffer, NFC Update clang/lib/Frontend to use a `MemoryBufferRef` from `getBufferOrFake` instead of `MemoryBuffer*` from `getBuffer`, with the exception of `FrontendInputFile`, which I'm leaving for later. Differential Revision: https://reviews.llvm.org/D89409 --- diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 92654db..9a806d7 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -450,7 +450,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem, PresumedModuleMapFile)) return true; - if (SrcMgr.getBuffer(ModuleMapID)->getBufferSize() == Offset) + if (SrcMgr.getBufferOrFake(ModuleMapID).getBufferSize() == Offset) Offset = 0; return false; diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 77a88f6..ec5cace 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -805,11 +805,9 @@ void PrintPreprocessedAction::ExecuteAction() { // concern, so if we scan for too long, we'll just assume the file should // be opened in binary mode. bool BinaryMode = true; - bool InvalidFile = false; const SourceManager& SM = CI.getSourceManager(); - const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getMainFileID(), - &InvalidFile); - if (!InvalidFile) { + if (llvm::Optional Buffer = + SM.getBufferOrNone(SM.getMainFileID())) { const char *cur = Buffer->getBufferStart(); const char *end = Buffer->getBufferEnd(); const char *next = (cur != end) ? cur + 1 : end; @@ -937,12 +935,12 @@ void DumpCompilerOptionsAction::ExecuteAction() { void PrintDependencyDirectivesSourceMinimizerAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); SourceManager &SM = CI.getPreprocessor().getSourceManager(); - const llvm::MemoryBuffer *FromFile = SM.getBuffer(SM.getMainFileID()); + llvm::MemoryBufferRef FromFile = SM.getBufferOrFake(SM.getMainFileID()); llvm::SmallString<1024> Output; llvm::SmallVector Toks; if (minimizeSourceToDependencyDirectives( - FromFile->getBuffer(), Output, Toks, &CI.getDiagnostics(), + FromFile.getBuffer(), Output, Toks, &CI.getDiagnostics(), SM.getLocForStartOfFile(SM.getMainFileID()))) { assert(CI.getDiagnostics().hasErrorOccurred() && "no errors reported for failure"); diff --git a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp index 982e56c..1388c2e 100644 --- a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp +++ b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp @@ -70,7 +70,7 @@ void HTMLPrinter::HandleTranslationUnit(ASTContext &Ctx) { if (Entry) Name = Entry->getName(); else - Name = R.getSourceMgr().getBuffer(FID)->getBufferIdentifier(); + Name = R.getSourceMgr().getBufferOrFake(FID).getBufferIdentifier(); html::AddLineNumbers(R, FID); html::AddHeaderFooterInternalBuiltinCSS(R, FID, Name); diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp index c0c8122..9d5366b 100644 --- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -702,9 +702,9 @@ void RewriteModernObjC::InitializeCommon(ASTContext &context) { // Get the ID and start/end of the main file. MainFileID = SM->getMainFileID(); - const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID); - MainFileStart = MainBuf->getBufferStart(); - MainFileEnd = MainBuf->getBufferEnd(); + llvm::MemoryBufferRef MainBuf = SM->getBufferOrFake(MainFileID); + MainFileStart = MainBuf.getBufferStart(); + MainFileEnd = MainBuf.getBufferEnd(); Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts()); } diff --git a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp index 990509a..3caf9a6 100644 --- a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -631,9 +631,9 @@ void RewriteObjC::InitializeCommon(ASTContext &context) { // Get the ID and start/end of the main file. MainFileID = SM->getMainFileID(); - const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID); - MainFileStart = MainBuf->getBufferStart(); - MainFileEnd = MainBuf->getBufferEnd(); + llvm::MemoryBufferRef MainBuf = SM->getBufferOrFake(MainFileID); + MainFileStart = MainBuf.getBufferStart(); + MainFileEnd = MainBuf.getBufferEnd(); Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts()); }