|
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | 13 | #include "ClangSourceBufferImporter.h" |
| 14 | +#include "swift/Basic/Assertions.h" |
14 | 15 | #include "swift/Basic/SourceManager.h" |
15 | 16 | #include "clang/Basic/SourceManager.h" |
16 | 17 | #include "llvm/Support/MemoryBuffer.h" |
@@ -47,18 +48,19 @@ SourceLoc ClangSourceBufferImporter::resolveSourceLocation( |
47 | 48 | if (mirrorIter != mirroredBuffers.end()) { |
48 | 49 | mirrorID = mirrorIter->second; |
49 | 50 | } else { |
| 51 | + StringRef bufIdent = buffer.getBufferIdentifier(); |
50 | 52 | std::unique_ptr<llvm::MemoryBuffer> mirrorBuffer{ |
51 | | - llvm::MemoryBuffer::getMemBuffer(buffer.getBuffer(), |
52 | | - buffer.getBufferIdentifier(), |
53 | | - /*RequiresNullTerminator=*/true) |
54 | | - }; |
| 53 | + llvm::MemoryBuffer::getMemBuffer(buffer.getBuffer(), bufIdent, |
| 54 | + /*RequiresNullTerminator=*/true)}; |
55 | 55 | // The same underlying file can exist as multiple clang file IDs. E.g. as |
56 | 56 | // part of the its own module, and then later loaded as an import in another |
57 | | - // module. |
58 | | - auto IDOpt = swiftSourceManager.getIDForBufferIdentifier(buffer.getBufferIdentifier()); |
59 | | - if (IDOpt.has_value()) |
| 57 | + // module. Don't deduplicate files like "<module-imports>" that have |
| 58 | + // different contents in different modules, despite the same name. |
| 59 | + auto IDOpt = swiftSourceManager.getIDForBufferIdentifier(bufIdent); |
| 60 | + if (IDOpt.has_value() && clangSrcMgr.getFileEntryForID(clangFileID)) { |
| 61 | + CONDITIONAL_ASSERT(llvm::sys::fs::exists(bufIdent)); |
60 | 62 | mirrorID = IDOpt.value(); |
61 | | - else |
| 63 | + } else |
62 | 64 | mirrorID = swiftSourceManager.addNewSourceBuffer(std::move(mirrorBuffer)); |
63 | 65 | mirroredBuffers[buffer.getBufferStart()] = mirrorID; |
64 | 66 | } |
|
0 commit comments