[PATCH] D89409: clang/Frontend: Mostly stop using SourceManager::getBuffer, NFC
Duncan P. N. Exon Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 10:41:03 PDT 2020
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.
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.
https://reviews.llvm.org/D89409
Files:
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
Index: clang/lib/Frontend/Rewrite/RewriteObjC.cpp
===================================================================
--- clang/lib/Frontend/Rewrite/RewriteObjC.cpp
+++ clang/lib/Frontend/Rewrite/RewriteObjC.cpp
@@ -631,9 +631,9 @@
// 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());
}
Index: clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
===================================================================
--- clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -702,9 +702,9 @@
// 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());
}
Index: clang/lib/Frontend/Rewrite/HTMLPrint.cpp
===================================================================
--- clang/lib/Frontend/Rewrite/HTMLPrint.cpp
+++ clang/lib/Frontend/Rewrite/HTMLPrint.cpp
@@ -70,7 +70,7 @@
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);
Index: clang/lib/Frontend/FrontendActions.cpp
===================================================================
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -805,11 +805,9 @@
// 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 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");
Index: clang/lib/Frontend/FrontendAction.cpp
===================================================================
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -449,7 +449,7 @@
PresumedModuleMapFile))
return true;
- if (SrcMgr.getBuffer(ModuleMapID)->getBufferSize() == Offset)
+ if (SrcMgr.getBufferOrFake(ModuleMapID).getBufferSize() == Offset)
Offset = 0;
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89409.298178.patch
Type: text/x-patch
Size: 4086 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201014/523a8a91/attachment.bin>
More information about the cfe-commits
mailing list