Skip to content

[5.0][ClangImporter] Fix issue with source order comparisons of clang source locations when using a bridging PCH #21956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,14 @@ ClangImporter::Implementation::getNextIncludeLoc() {
if (!DummyIncludeBuffer.isValid()) {
clang::SourceLocation includeLoc =
srcMgr.getLocForStartOfFile(srcMgr.getMainFileID());
// Picking the beginning of the main FileID as include location is also what
// the clang PCH mechanism is doing (see
// clang::ASTReader::getImportLocation()). Choose the next source location
// here to avoid having the exact same import location as the clang PCH.
// Otherwise, if we are using a PCH for bridging header, we'll have
// problems with source order comparisons of clang source locations not
// being deterministic.
includeLoc = includeLoc.getLocWithOffset(1);
DummyIncludeBuffer = srcMgr.createFileID(
llvm::make_unique<ZeroFilledMemoryBuffer>(
256*1024, StringRef(moduleImportBufferName)),
Expand Down
3 changes: 3 additions & 0 deletions test/IDE/clang-importing/Inputs/bridge.h
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
@import Foundation;
@import somemod1;

void func_in_bridge(void);
4 changes: 3 additions & 1 deletion test/IDE/clang-importing/complete_with_clang_comments.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TOP -code-completion-comments=true \
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=TOP -code-completion-comments=true \
// RUN: -import-objc-header %S/Inputs/bridge.h -I %S/Inputs/somemod1 -I %S/Inputs/somemod2 | %FileCheck %s -check-prefix=CHECK-TOP
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -code-completion -source-filename %s -code-completion-token=TOP -code-completion-comments=true \
// 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

// REQUIRES: objc_interop

Expand Down