Frontend: Take VFS and MainFileBuffer by reference in PrecompiledPreamble::CanReuse, NFC

Clarify that `PrecompiledPreamble::CanReuse` requires non-null arguments
for `VFS` and `MainFileBuffer`, taking them by reference instead of by
pointer.

Differential Revision: https://reviews.llvm.org/D91297
This commit is contained in:
Duncan P. N. Exon Smith 2020-11-10 10:54:03 -05:00 committed by Duncan P. N. Exon Smith
parent 03bce0bf4e
commit f4d02fbe41
4 changed files with 15 additions and 16 deletions

View File

@ -378,8 +378,7 @@ bool isPreambleCompatible(const PreambleData &Preamble,
auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
return compileCommandsAreEqual(Inputs.CompileCommand,
Preamble.CompileCommand) &&
Preamble.Preamble.CanReuse(CI, ContentsBuffer.get(), Bounds,
VFS.get());
Preamble.Preamble.CanReuse(CI, *ContentsBuffer, Bounds, *VFS);
}
void escapeBackslashAndQuotes(llvm::StringRef Text, llvm::raw_ostream &OS) {

View File

@ -105,8 +105,8 @@ public:
/// Check whether PrecompiledPreamble can be reused for the new contents(\p
/// MainFileBuffer) of the main file.
bool CanReuse(const CompilerInvocation &Invocation,
const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
llvm::vfs::FileSystem *VFS) const;
const llvm::MemoryBufferRef &MainFileBuffer,
PreambleBounds Bounds, llvm::vfs::FileSystem &VFS) const;
/// Changes options inside \p CI to use PCH from this preamble. Also remaps
/// main file to \p MainFileBuffer and updates \p VFS to ensure the preamble

View File

@ -1317,8 +1317,8 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
return nullptr;
if (Preamble) {
if (Preamble->CanReuse(PreambleInvocationIn, MainFileBuffer.get(), Bounds,
VFS.get())) {
if (Preamble->CanReuse(PreambleInvocationIn, *MainFileBuffer, Bounds,
*VFS)) {
// Okay! We can re-use the precompiled preamble.
// Set the state of the diagnostic object to mimic its state

View File

@ -501,12 +501,12 @@ std::size_t PrecompiledPreamble::getSize() const {
}
bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
const llvm::MemoryBuffer *MainFileBuffer,
const llvm::MemoryBufferRef &MainFileBuffer,
PreambleBounds Bounds,
llvm::vfs::FileSystem *VFS) const {
llvm::vfs::FileSystem &VFS) const {
assert(
Bounds.Size <= MainFileBuffer->getBufferSize() &&
Bounds.Size <= MainFileBuffer.getBufferSize() &&
"Buffer is too large. Bounds were calculated from a different buffer?");
auto PreambleInvocation = std::make_shared<CompilerInvocation>(Invocation);
@ -520,7 +520,7 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
if (PreambleBytes.size() != Bounds.Size ||
PreambleEndsAtStartOfLine != Bounds.PreambleEndsAtStartOfLine ||
!std::equal(PreambleBytes.begin(), PreambleBytes.end(),
MainFileBuffer->getBuffer().begin()))
MainFileBuffer.getBuffer().begin()))
return false;
// The preamble has not changed. We may be able to re-use the precompiled
// preamble.
@ -532,14 +532,14 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
llvm::StringSet<> OverriddenAbsPaths; // Either by buffers or files.
for (const auto &R : PreprocessorOpts.RemappedFiles) {
llvm::vfs::Status Status;
if (!moveOnNoError(VFS->status(R.second), Status)) {
if (!moveOnNoError(VFS.status(R.second), Status)) {
// If we can't stat the file we're remapping to, assume that something
// horrible happened.
return false;
}
// If a mapped file was previously missing, then it has changed.
llvm::SmallString<128> MappedPath(R.first);
if (!VFS->makeAbsolute(MappedPath))
if (!VFS.makeAbsolute(MappedPath))
OverriddenAbsPaths.insert(MappedPath);
OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile(
@ -552,13 +552,13 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
const PrecompiledPreamble::PreambleFileHash PreambleHash =
PreambleFileHash::createForMemoryBuffer(RB.second->getMemBufferRef());
llvm::vfs::Status Status;
if (moveOnNoError(VFS->status(RB.first), Status))
if (moveOnNoError(VFS.status(RB.first), Status))
OverriddenFiles[Status.getUniqueID()] = PreambleHash;
else
OverridenFileBuffers[RB.first] = PreambleHash;
llvm::SmallString<128> MappedPath(RB.first);
if (!VFS->makeAbsolute(MappedPath))
if (!VFS.makeAbsolute(MappedPath))
OverriddenAbsPaths.insert(MappedPath);
}
@ -574,7 +574,7 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
}
llvm::vfs::Status Status;
if (!moveOnNoError(VFS->status(F.first()), Status)) {
if (!moveOnNoError(VFS.status(F.first()), Status)) {
// If the file's buffer is not remapped and we can't stat it,
// assume that something horrible happened.
return false;
@ -603,7 +603,7 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
return false;
// If a file previously recorded as missing exists as a regular file, then
// consider the preamble out-of-date.
if (auto Status = VFS->status(F.getKey())) {
if (auto Status = VFS.status(F.getKey())) {
if (Status->isRegularFile())
return false;
}