Skip to content

Commit 37f78b5

Browse files
authored
Merge pull request swiftlang#21952 from akyrtzi/import-loc-pch
[ClangImporter] Fix issue with source order comparisons of clang source locations when using a bridging PCH
2 parents fdc6a71 + e7c5578 commit 37f78b5

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
@@ -1165,6 +1165,14 @@ ClangImporter::Implementation::getNextIncludeLoc() {
11651165
if (!DummyIncludeBuffer.isValid()) {
11661166
clang::SourceLocation includeLoc =
11671167
srcMgr.getLocForStartOfFile(srcMgr.getMainFileID());
1168+
// Picking the beginning of the main FileID as include location is also what
1169+
// the clang PCH mechanism is doing (see
1170+
// clang::ASTReader::getImportLocation()). Choose the next source location
1171+
// here to avoid having the exact same import location as the clang PCH.
1172+
// Otherwise, if we are using a PCH for bridging header, we'll have
1173+
// problems with source order comparisons of clang source locations not
1174+
// being deterministic.
1175+
includeLoc = includeLoc.getLocWithOffset(1);
11681176
DummyIncludeBuffer = srcMgr.createFileID(
11691177
llvm::make_unique<ZeroFilledMemoryBuffer>(
11701178
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)