This would trigger when path prefixes are remapped, as the buffer
identifier is the remapped path, not the path on the file system. There
is no easy way to recover the original path, so drop the assert.
Virtual files from different modules can differ despite having identical
names (e.g. `<module-imports>`. This fixes some diagnostics related test
failures when these virtual files were (incorrectly) deduplicated and
the module imports from a previous module were shown, by checking if the
buffer has a corresponding clang::FileEntry.
Clang can end up with multiple file IDs representing the same file, but
in different contexts. For example, file in the current module always
have file IDs >0, while files in imported modules always have file IDs
<-1. As we end up compiling multiple modules, the same file can be seen
both as the "current" module, and a transitive import. We don't want
multiple Swift buffer IDs for the same file, as it breaks things like
-verify that compare buffer IDs.
rdar://162661286
In apple/llvm-project#1860, the diagnostic for a missing import in an umbrella header was improved by moving it to the end of the file and including a fix-it suggesting the import that would be needed. This breaks two things on the Swift side:
• One Swift test assumes the old source location will be used.
• The `ClangSourceBufferImporter` doesn’t work correctly when a diagnostic is emitted at EOF. It tries to create a virtual file covering EOF..<EOF, but it’s not actually valid to start a virtual file at EOF—it would always be empty.
This commit corrects these issues, which should unblock the automerger.
Fixes rdar://69707827.
Emitting Swift diagnostics in Clang buffers requires making those
buffers valid places to put Swift SourceLocs, which means making a
mirror of those buffers in the Swift SourceManager. This isn't a copy;
instead, any Clang SourceManagers that are involved are kept alive
until the importer is torn down. (There might be more than one because
of diagnostics emitted during module building.)
For a long time we only emitted diagnostics in Clang buffers if the
diagnostics came from Clang, but then we added another case for custom
Swift names that fail to import. I'm about to add another such
diagnostic, so let's formalize this buffer mapping first.
No intended functionality change.