diff --git a/lib/ClangImporter/ClangSourceBufferImporter.cpp b/lib/ClangImporter/ClangSourceBufferImporter.cpp index fa4df253d7a0f..097fb96c50cff 100644 --- a/lib/ClangImporter/ClangSourceBufferImporter.cpp +++ b/lib/ClangImporter/ClangSourceBufferImporter.cpp @@ -67,11 +67,17 @@ SourceLoc ClangSourceBufferImporter::resolveSourceLocation( StringRef presumedFile = presumedLoc.getFilename(); SourceLoc startOfLine = loc.getAdvancedLoc(-presumedLoc.getColumn() + 1); - bool isNewVirtualFile = swiftSourceManager.openVirtualFile( - startOfLine, presumedFile, presumedLoc.getLine() - bufferLineNumber); - if (isNewVirtualFile) { - SourceLoc endOfLine = findEndOfLine(swiftSourceManager, loc, mirrorID); - swiftSourceManager.closeVirtualFile(endOfLine); + + // FIXME: Virtual files can't actually model the EOF position correctly, so + // if this virtual file would start at EOF, just hope the physical location + // will do. + if (startOfLine != swiftSourceManager.getRangeForBuffer(mirrorID).getEnd()) { + bool isNewVirtualFile = swiftSourceManager.openVirtualFile( + startOfLine, presumedFile, presumedLoc.getLine() - bufferLineNumber); + if (isNewVirtualFile) { + SourceLoc endOfLine = findEndOfLine(swiftSourceManager, loc, mirrorID); + swiftSourceManager.closeVirtualFile(endOfLine); + } } using SourceManagerRef = llvm::IntrusiveRefCntPtr; diff --git a/test/ClangImporter/diags_from_module.swift b/test/ClangImporter/diags_from_module.swift index 8e74e7a8ca062..5cc81a87e1291 100644 --- a/test/ClangImporter/diags_from_module.swift +++ b/test/ClangImporter/diags_from_module.swift @@ -37,7 +37,7 @@ import Module // CHECK-PRIMARY: diags_from_module.swift:[[@LINE-4]]:8: error: could not build Objective-C module 'Module' // CHECK-WARN: Sub2.h:7:2: warning: here is some warning about something -// CHECK-WARN: :1:1: warning: umbrella header for module 'Module' does not include header 'NotInModule.h' +// CHECK-WARN: Module.h:20:1: warning: umbrella header for module 'Module' does not include header 'NotInModule.h' // FIXME: show [-Wincomplete-umbrella] // CHECK-NO-WARN-NOT: warning about something