Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions lib/ClangImporter/ClangSourceBufferImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "ClangSourceBufferImporter.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/SourceManager.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/Support/MemoryBuffer.h"
Expand Down Expand Up @@ -47,12 +48,19 @@ SourceLoc ClangSourceBufferImporter::resolveSourceLocation(
if (mirrorIter != mirroredBuffers.end()) {
mirrorID = mirrorIter->second;
} else {
StringRef bufIdent = buffer.getBufferIdentifier();
std::unique_ptr<llvm::MemoryBuffer> mirrorBuffer{
llvm::MemoryBuffer::getMemBuffer(buffer.getBuffer(),
buffer.getBufferIdentifier(),
/*RequiresNullTerminator=*/true)
};
mirrorID = swiftSourceManager.addNewSourceBuffer(std::move(mirrorBuffer));
llvm::MemoryBuffer::getMemBuffer(buffer.getBuffer(), bufIdent,
/*RequiresNullTerminator=*/true)};
// The same underlying file can exist as multiple clang file IDs. E.g. as
// part of the its own module, and then later loaded as an import in another
// module. Don't deduplicate files like "<module-imports>" that have
// different contents in different modules, despite the same name.
auto IDOpt = swiftSourceManager.getIDForBufferIdentifier(bufIdent);
if (IDOpt.has_value() && clangSrcMgr.getFileEntryForID(clangFileID)) {
mirrorID = IDOpt.value();
} else
mirrorID = swiftSourceManager.addNewSourceBuffer(std::move(mirrorBuffer));
mirroredBuffers[buffer.getBufferStart()] = mirrorID;
}
loc = swiftSourceManager.getLocForOffset(mirrorID, decomposedLoc.second);
Expand Down