Commit Graph

8 Commits

Author SHA1 Message Date
Henrik G. Olsson
acc967bf9d Remove assert that path exists on file system
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.
2025-10-17 15:39:05 -07:00
Henrik G. Olsson
d69c021d25 [ClangImporter] check if buffer represents file before dedup
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.
2025-10-16 19:48:29 -07:00
Henrik G. Olsson
696c08ea2b [ClangImporter] Deduplicate clang buffers representing the same file
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
2025-10-15 23:11:36 -07:00
Alexis Laferrière
1bc7a8ea7c [ClangImporter] Keep using the buffer start address as map key
rdar://71497407
2021-01-07 15:00:34 -08:00
Brent Royal-Gordon
dde1209026 Update SourceBufferImporter to avoid getBuffer()
This was recently removed from clang in https://reviews.llvm.org/D89427. Fixes rdar://70771582.
2020-10-29 12:22:57 -07:00
Brent Royal-Gordon
aaa4e45fa8 [ClangImporter] Update umbrella header diagnostic handling
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.
2020-09-28 16:27:41 -07:00
Daniel Rodríguez Troitiño
87da361dc9 Replace #import with #include to please VC++.
VC++ chokes on the #import, and thinks we are trying to import
libraries. Replace by #include, which should be more portable.
2019-10-30 11:44:19 -07:00
Jordan Rose
e364552876 [ClangImporter] Pull buffer importing out of ClangDiagnosticConsumer
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.
2019-10-28 22:08:26 -07:00