[clang] 4c55c3b - Frontend: Change ComputePreambleBounds to take MemoryBufferRef, NFC
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 11 14:20:02 PST 2020
Author: Duncan P. N. Exon Smith
Date: 2020-11-11T17:19:51-05:00
New Revision: 4c55c3b66dea3a1d6058392e1e96e166d318a2ff
URL: https://github.com/llvm/llvm-project/commit/4c55c3b66dea3a1d6058392e1e96e166d318a2ff
DIFF: https://github.com/llvm/llvm-project/commit/4c55c3b66dea3a1d6058392e1e96e166d318a2ff.diff
LOG: Frontend: Change ComputePreambleBounds to take MemoryBufferRef, NFC
Avoid requiring an actual MemoryBuffer in ComputePreambleBounds, when
a MemoryBufferRef will do just fine.
Differential Revision: https://reviews.llvm.org/D90890
Added:
Modified:
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/Preamble.cpp
clang/include/clang/Frontend/PrecompiledPreamble.h
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/PrecompiledPreamble.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 24678a3cc1bc..1d85439f53af 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -1104,7 +1104,7 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
// overriding the preamble will break sema completion. Fortunately we can just
// skip all includes in this case; these completions are really simple.
PreambleBounds PreambleRegion =
- ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
+ ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0);
bool CompletingInPreamble = PreambleRegion.Size > Input.Offset;
if (Input.Patch)
Input.Patch->apply(*CI);
diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp
index 8e1ad7242eb0..f4f82be81cde 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -249,8 +249,7 @@ scanPreamble(llvm::StringRef Contents, const tooling::CompileCommand &Cmd) {
// This means we're scanning (though not preprocessing) the preamble section
// twice. However, it's important to precisely follow the preamble bounds used
// elsewhere.
- auto Bounds =
- ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
+ auto Bounds = ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0);
auto PreambleContents =
llvm::MemoryBuffer::getMemBufferCopy(Contents.substr(0, Bounds.Size));
auto Clang = prepareCompilerInstance(
@@ -322,8 +321,7 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
// without those.
auto ContentsBuffer =
llvm::MemoryBuffer::getMemBuffer(Inputs.Contents, FileName);
- auto Bounds =
- ComputePreambleBounds(*CI.getLangOpts(), ContentsBuffer.get(), 0);
+ auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), *ContentsBuffer, 0);
trace::Span Tracer("BuildPreamble");
SPAN_ATTACH(Tracer, "File", FileName);
@@ -376,8 +374,7 @@ bool isPreambleCompatible(const PreambleData &Preamble,
const CompilerInvocation &CI) {
auto ContentsBuffer =
llvm::MemoryBuffer::getMemBuffer(Inputs.Contents, FileName);
- auto Bounds =
- ComputePreambleBounds(*CI.getLangOpts(), ContentsBuffer.get(), 0);
+ auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), *ContentsBuffer, 0);
auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
return compileCommandsAreEqual(Inputs.CompileCommand,
Preamble.CompileCommand) &&
diff --git a/clang/include/clang/Frontend/PrecompiledPreamble.h b/clang/include/clang/Frontend/PrecompiledPreamble.h
index 99faf60f1a44..cea39bfec95d 100644
--- a/clang/include/clang/Frontend/PrecompiledPreamble.h
+++ b/clang/include/clang/Frontend/PrecompiledPreamble.h
@@ -41,7 +41,7 @@ class PCHContainerOperations;
/// Runs lexer to compute suggested preamble bounds.
PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts,
- const llvm::MemoryBuffer *Buffer,
+ const llvm::MemoryBufferRef &Buffer,
unsigned MaxLines);
class PreambleCallbacks;
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 0728fee49d78..e1aa3682a2b7 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1317,9 +1317,8 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
if (!MainFileBuffer)
return nullptr;
- PreambleBounds Bounds =
- ComputePreambleBounds(*PreambleInvocationIn.getLangOpts(),
- MainFileBuffer.get(), MaxLines);
+ PreambleBounds Bounds = ComputePreambleBounds(
+ *PreambleInvocationIn.getLangOpts(), *MainFileBuffer, MaxLines);
if (!Bounds.Size)
return nullptr;
diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp
index 87cd9169c78c..0f4259900ec2 100644
--- a/clang/lib/Frontend/PrecompiledPreamble.cpp
+++ b/clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -303,9 +303,9 @@ template <class T> bool moveOnNoError(llvm::ErrorOr<T> Val, T &Output) {
} // namespace
PreambleBounds clang::ComputePreambleBounds(const LangOptions &LangOpts,
- const llvm::MemoryBuffer *Buffer,
+ const llvm::MemoryBufferRef &Buffer,
unsigned MaxLines) {
- return Lexer::ComputePreamble(Buffer->getBuffer(), LangOpts, MaxLines);
+ return Lexer::ComputePreamble(Buffer.getBuffer(), LangOpts, MaxLines);
}
llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
@@ -621,7 +621,7 @@ void PrecompiledPreamble::AddImplicitPreamble(
void PrecompiledPreamble::OverridePreamble(
CompilerInvocation &CI, IntrusiveRefCntPtr<llvm::vfs::FileSystem> &VFS,
llvm::MemoryBuffer *MainFileBuffer) const {
- auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), MainFileBuffer, 0);
+ auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), *MainFileBuffer, 0);
configurePreamble(Bounds, CI, VFS, MainFileBuffer);
}
More information about the cfe-commits
mailing list