Skip to content

Commit aaa4e45

Browse files
committed
[ClangImporter] Update umbrella header diagnostic handling
In swiftlang/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.
1 parent 4d0ab13 commit aaa4e45

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/ClangImporter/ClangSourceBufferImporter.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ SourceLoc ClangSourceBufferImporter::resolveSourceLocation(
6767

6868
StringRef presumedFile = presumedLoc.getFilename();
6969
SourceLoc startOfLine = loc.getAdvancedLoc(-presumedLoc.getColumn() + 1);
70-
bool isNewVirtualFile = swiftSourceManager.openVirtualFile(
71-
startOfLine, presumedFile, presumedLoc.getLine() - bufferLineNumber);
72-
if (isNewVirtualFile) {
73-
SourceLoc endOfLine = findEndOfLine(swiftSourceManager, loc, mirrorID);
74-
swiftSourceManager.closeVirtualFile(endOfLine);
70+
71+
// FIXME: Virtual files can't actually model the EOF position correctly, so
72+
// if this virtual file would start at EOF, just hope the physical location
73+
// will do.
74+
if (startOfLine != swiftSourceManager.getRangeForBuffer(mirrorID).getEnd()) {
75+
bool isNewVirtualFile = swiftSourceManager.openVirtualFile(
76+
startOfLine, presumedFile, presumedLoc.getLine() - bufferLineNumber);
77+
if (isNewVirtualFile) {
78+
SourceLoc endOfLine = findEndOfLine(swiftSourceManager, loc, mirrorID);
79+
swiftSourceManager.closeVirtualFile(endOfLine);
80+
}
7581
}
7682

7783
using SourceManagerRef = llvm::IntrusiveRefCntPtr<const clang::SourceManager>;

test/ClangImporter/diags_from_module.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Module
3737
// CHECK-PRIMARY: diags_from_module.swift:[[@LINE-4]]:8: error: could not build Objective-C module 'Module'
3838

3939
// CHECK-WARN: Sub2.h:7:2: warning: here is some warning about something
40-
// CHECK-WARN: <module-includes>:1:1: warning: umbrella header for module 'Module' does not include header 'NotInModule.h'
40+
// CHECK-WARN: Module.h:20:1: warning: umbrella header for module 'Module' does not include header 'NotInModule.h'
4141
// FIXME: show [-Wincomplete-umbrella]
4242

4343
// CHECK-NO-WARN-NOT: warning about something

0 commit comments

Comments
 (0)