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
This commit is contained in:
Duncan P. N. Exon Smith 2020-10-14 13:28:34 -04:00
parent f9fb9da36c
commit 63af242279
5 changed files with 12 additions and 14 deletions

View File

@ -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;

View File

@ -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");

View File

@ -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);

View File

@ -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());
}

View File

@ -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());
}