Skip to content

Commit 346da2b

Browse files
committed
[ClangImporter] Fix issue with source order comparisons of clang source locations when using a bridging PCH
Clang importer was picking the beginning of the main FileID as include location of its modules, which is the same location that the clang PCH mechanism is using as import location. Make sure to use a different location otherwise we'll have problems with source order comparisons of clang source locations not being deterministic. rdar://29137319
1 parent edd7a22 commit 346da2b

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,14 @@ ClangImporter::Implementation::getNextIncludeLoc() {
11441144
if (!DummyIncludeBuffer.isValid()) {
11451145
clang::SourceLocation includeLoc =
11461146
srcMgr.getLocForStartOfFile(srcMgr.getMainFileID());
1147+
// Picking the beginning of the main FileID as include location is also what
1148+
// the clang PCH mechanism is doing (see
1149+
// clang::ASTReader::getImportLocation()). Choose the next source location
1150+
// here to avoid having the exact same import location as the clang PCH.
1151+
// Otherwise, if we are using a PCH for bridging header, we'll have
1152+
// problems with source order comparisons of clang source locations not
1153+
// being deterministic.
1154+
includeLoc = includeLoc.getLocWithOffset(1);
11471155
DummyIncludeBuffer = srcMgr.createFileID(
11481156
llvm::make_unique<ZeroFilledMemoryBuffer>(
11491157
256*1024, StringRef(moduleImportBufferName)),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
@import Foundation;
12
@import somemod1;
3+
4+
void func_in_bridge(void);

test/IDE/clang-importing/complete_with_clang_comments.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP -code-completion-comments=true \
1+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=TOP -code-completion-comments=true \
22
// RUN: -import-objc-header %S/Inputs/bridge.h -I %S/Inputs/somemod1 -I %S/Inputs/somemod2 | %FileCheck %s -check-prefix=CHECK-TOP
3+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=TOP -code-completion-comments=true \
4+
// RUN: -import-objc-header %S/Inputs/bridge.h -pch-output-dir %t.pch -I %S/Inputs/somemod1 -I %S/Inputs/somemod2 | %FileCheck %s -check-prefix=CHECK-TOP
35

46
// REQUIRES: objc_interop
57

0 commit comments

Comments
 (0)