This is an archive of the discontinued LLVM Phabricator instance.

WIP: Frontend: Handle PreprocessorOptions::RemappedFiles in createVFSFromCompilerInvocation
Needs ReviewPublic

Authored by dexonsmith on Nov 12 2020, 5:59 AM.

Details

Summary

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

Diff Detail