diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2021-06-13 19:31:46 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2021-06-13 19:37:19 +0000 | 
| commit | e8d8bef961a50d4dc22501cde4fb9fb0be1b2532 (patch) | |
| tree | 94f04805f47bb7c59ae29690d8952b6074fff602 /contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp | |
| parent | bb130ff39747b94592cb26d71b7cb097b9a4ea6b (diff) | |
| parent | b60736ec1405bb0a8dd40989f67ef4c93da068ab (diff) | |
Diffstat (limited to 'contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp')
| -rw-r--r-- | contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp | 51 | 
1 files changed, 30 insertions, 21 deletions
diff --git a/contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp b/contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp index 6cdfc595dcae..77b93713ce68 100644 --- a/contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -208,6 +208,11 @@ public:      Callbacks.AfterPCHEmitted(Writer);    } +  bool BeginSourceFileAction(CompilerInstance &CI) override { +    assert(CI.getLangOpts().CompilingPCH); +    return ASTFrontendAction::BeginSourceFileAction(CI); +  } +    bool shouldEraseOutputFiles() override { return !hasEmittedPreamblePCH(); }    bool hasCodeCompletionSupport() const override { return false; }    bool hasASTFileSupport() const override { return false; } @@ -298,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( @@ -396,6 +401,8 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(    auto PreambleDepCollector = std::make_shared<PreambleDependencyCollector>();    Clang->addDependencyCollector(PreambleDepCollector); +  Clang->getLangOpts().CompilingPCH = true; +    // Remap the main source file to the preamble buffer.    StringRef MainFilePath = FrontendOpts.Inputs[0].getFile();    auto PreambleInputBuffer = llvm::MemoryBuffer::getMemBufferCopy( @@ -456,7 +463,8 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(            PrecompiledPreamble::PreambleFileHash::createForFile(File->getSize(),                                                                 ModTime);      } else { -      const llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File); +      llvm::MemoryBufferRef Buffer = +          SourceMgr.getMemoryBufferForFileOrFake(File);        FilesInPreamble[File->getName()] =            PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer(Buffer);      } @@ -493,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); @@ -512,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. @@ -524,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( @@ -542,15 +550,15 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,    llvm::StringMap<PreambleFileHash> OverridenFileBuffers;    for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) {      const PrecompiledPreamble::PreambleFileHash PreambleHash = -        PreambleFileHash::createForMemoryBuffer(RB.second); +        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);    } @@ -566,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; @@ -595,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;      } @@ -613,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);  } @@ -727,7 +735,7 @@ PrecompiledPreamble::PCHStorage::getKind() const {  PrecompiledPreamble::TempPCHFile &PrecompiledPreamble::PCHStorage::asFile() {    assert(getKind() == Kind::TempFile); -  return *reinterpret_cast<TempPCHFile *>(Storage.buffer); +  return *reinterpret_cast<TempPCHFile *>(&Storage);  }  const PrecompiledPreamble::TempPCHFile & @@ -738,7 +746,7 @@ PrecompiledPreamble::PCHStorage::asFile() const {  PrecompiledPreamble::InMemoryPreamble &  PrecompiledPreamble::PCHStorage::asMemory() {    assert(getKind() == Kind::InMemory); -  return *reinterpret_cast<InMemoryPreamble *>(Storage.buffer); +  return *reinterpret_cast<InMemoryPreamble *>(&Storage);  }  const PrecompiledPreamble::InMemoryPreamble & @@ -776,13 +784,13 @@ PrecompiledPreamble::PreambleFileHash::createForFile(off_t Size,  PrecompiledPreamble::PreambleFileHash  PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer( -    const llvm::MemoryBuffer *Buffer) { +    const llvm::MemoryBufferRef &Buffer) {    PreambleFileHash Result; -  Result.Size = Buffer->getBufferSize(); +  Result.Size = Buffer.getBufferSize();    Result.ModTime = 0;    llvm::MD5 MD5Ctx; -  MD5Ctx.update(Buffer->getBuffer().data()); +  MD5Ctx.update(Buffer.getBuffer().data());    MD5Ctx.final(Result.MD5);    return Result; @@ -804,7 +812,8 @@ void PrecompiledPreamble::configurePreamble(    PreprocessorOpts.PrecompiledPreambleBytes.first = Bounds.Size;    PreprocessorOpts.PrecompiledPreambleBytes.second =        Bounds.PreambleEndsAtStartOfLine; -  PreprocessorOpts.DisablePCHValidation = true; +  PreprocessorOpts.DisablePCHOrModuleValidation = +      DisableValidationForModuleKind::PCH;    setupPreambleStorage(Storage, PreprocessorOpts, VFS);  }  | 
