[clang] 63af242 - clang/Frontend: Mostly stop using SourceManager::getBuffer, NFC
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 20:31:49 PDT 2020
Author: Duncan P. N. Exon Smith
Date: 2020-10-14T23:31:28-04:00
New Revision: 63af2422798188d70a411f76b0f06ab63a783a0d
URL: https://github.com/llvm/llvm-project/commit/63af2422798188d70a411f76b0f06ab63a783a0d
DIFF: https://github.com/llvm/llvm-project/commit/63af2422798188d70a411f76b0f06ab63a783a0d.diff
LOG: 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
Added:
Modified:
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Frontend/Rewrite/HTMLPrint.cpp
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
clang/lib/Frontend/Rewrite/RewriteObjC.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index 92654dbe8a10..9a806d7c9af8 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 77a88f696abc..ec5caceba207 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<llvm::MemoryBufferRef> 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<minimize_source_to_dependency_directives::Token, 32> 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 982e56cebbca..1388c2e1faab 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 c0c81221b234..9d5366bb161e 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 990509a84b06..3caf9a672062 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());
}
More information about the cfe-commits
mailing list