[PATCH] D91342: WIP: Frontend: Handle PreprocessorOptions::RemappedFiles in createVFSFromCompilerInvocation

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 12 05:59:13 PST 2020


dexonsmith created this revision.
dexonsmith added reviewers: JDevlieghere, jansvoboda11, akyrtzi.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

Instead of threading `PreprocessorOptions::RemappedFiles` through to the
`SourceManager`, handle it in `createVFSFromCompilerInvocation`.

I've also removed some of the now-dead code from `SourceManager`. I'll
leave unifying `ContentCache::OrigEntry` and
`ContentCache::ContentsEntry` for follow ups, since otherwise there'll
be a lot of noise here.

WIP: Currently I have hacked clang/test/PCH/remap-file-from-pch.cpp to
get it to pass, but probably the right thing is to write a prep patch
that reimplements the following fishy code in ASTReader from
6eec06d0d4fa2e108546b422619c6cb32f234e6e (maybe sending a list of files
that should trigger this behaviour through `PreprocessorOptions`?), not
necessarily keeping the exact same semantics.

  // Check if there was a request to override the contents of the file
  // that was part of the precompiled header. Overriding such a file
  // can lead to problems when lexing using the source locations from the
  // PCH.
  SourceManager &SM = getSourceManager();
  // FIXME: Reject if the overrides are different.
  if ((!Overridden && !Transient) && SM.isFileOverridden(File)) {
    if (Complain)
      Error(diag::err_fe_pch_file_overridden, Filename);
  
    // After emitting the diagnostic, bypass the overriding file to recover
    // (this creates a separate FileEntry).
    File = SM.bypassFileContentsOverride(*File);
    if (!File) {
      F.InputFilesLoaded[ID - 1] = InputFile::getNotFound();
      return InputFile();
    }
  }


https://reviews.llvm.org/D91342

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/test/PCH/remap-file-from-pch.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91342.304808.patch
Type: text/x-patch
Size: 10783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201112/28f99b2d/attachment-0001.bin>


More information about the cfe-commits mailing list