Skip to content

Commit 26438e4

Browse files
committed
[ClangImporter] Handle -Xcc -include, sort of.
What does that mean? We'll indeed parse the provided prefix header. If you aren't using a bridging header, that's all you get -- nothing extra is made visible. If you /are/ using a bridging header, the prefix header is prepended to it...but none of the modular content it imports is made visible. I cloned rdar://problem/22083824 to fix that. The important thing is that we /won't/ try to import overlays before we've even finished setting up all the module loaders, and therefore won't crash. rdar://problem/20893290 Swift SVN r30831
1 parent a2ec277 commit 26438e4

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,6 @@ ClangImporter::create(ASTContext &ctx,
518518

519519
clang::Preprocessor &clangPP = instance.getPreprocessor();
520520
clangPP.enableIncrementalProcessing();
521-
auto *CB = new HeaderImportCallbacks(*importer, importer->Impl);
522-
clangPP.addPPCallbacks(std::unique_ptr<clang::PPCallbacks>(CB));
523521

524522
instance.createModuleManager();
525523
instance.getModuleManager()->addListener(
@@ -537,6 +535,9 @@ ClangImporter::create(ASTContext &ctx,
537535
clang::Parser::DeclGroupPtrTy parsed;
538536
while (!importer->Impl.Parser->ParseTopLevelDecl(parsed)) {}
539537

538+
auto *CB = new HeaderImportCallbacks(*importer, importer->Impl);
539+
clangPP.addPPCallbacks(std::unique_ptr<clang::PPCallbacks>(CB));
540+
540541
// Create the selectors we'll be looking for.
541542
auto &clangContext = importer->Impl.Instance->getASTContext();
542543
importer->Impl.objectAtIndexedSubscript
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@import Security;
2+
3+
extern const int includedConst;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -Xcc -include -Xcc %S/Inputs/Xcc_include.h -parse %s 2>&1 | FileCheck -check-prefix=CHECK-INCLUDE-ONLY %s
2+
3+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -Xcc -include -Xcc %S/Inputs/Xcc_include.h -import-objc-header %S/../../Inputs/empty.swift -parse %s 2>&1 | FileCheck -check-prefix=CHECK-INCLUDE-PLUS-BRIDGING %s
4+
5+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -Xcc -include -Xcc %S/Inputs/Xcc_include.h -F %S/Inputs/mixed-target/ -module-name Mixed -import-underlying-module -parse %s -disable-objc-attr-requires-foundation-module 2>&1 | FileCheck -check-prefix=CHECK-INCLUDE-FRAMEWORK %s
6+
7+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -Xcc -include -Xcc %S/Inputs/this_header_does_not_exist.h -parse %s 2>&1 | FileCheck -check-prefix=CHECK-INCLUDE-MISSING %s
8+
9+
// CHECK-INCLUDE-MISSING: error: '{{.*}}this_header_does_not_exist.h' file not found
10+
11+
func test() {
12+
// CHECK-INCLUDE-ONLY: error: use of unresolved identifier 'includedConst'
13+
// CHECK-INCLUDE-PLUS-BRIDGING-NOT: unresolved identifier 'includedConst'
14+
// CHECK-INCLUDE-FRAMEWORK: error: use of unresolved identifier 'includedConst'
15+
_ = includedConst
16+
17+
// CHECK-INCLUDE-ONLY: error: use of unresolved identifier 'errSecSuccess'
18+
// CHECK-INCLUDE-PLUS-BRIDGING: error: use of unresolved identifier 'errSecSuccess'
19+
// CHECK-INCLUDE-FRAMEWORK: error: use of unresolved identifier 'errSecSuccess'
20+
_ = errSecSuccess
21+
22+
#if FRAMEWORK
23+
// CHECK-INCLUDE-FRAMEWORK-NOT: error: unresolved identifier 'Base'
24+
_ = Base()
25+
#endif
26+
}

test/ClangModules/sdk-bridging-header.swift

+9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
// RUN: %target-swift-frontend -parse -verify %s -import-objc-header %S/Inputs/sdk-bridging-header.h
22
// RUN: not %target-swift-frontend -parse %s -import-objc-header %S/Inputs/bad-bridging-header.h 2>&1 | FileCheck -check-prefix=CHECK-FATAL %s
33

4+
// RUN: %target-swift-frontend -parse -verify %s -Xcc -include -Xcc %S/Inputs/sdk-bridging-header.h -import-objc-header %S/../Inputs/empty.swift
5+
6+
// RUN: not %target-swift-frontend -parse %s -Xcc -include -Xcc %S/Inputs/bad-bridging-header.h 2>&1 | FileCheck -check-prefix=CHECK-INCLUDE %s
7+
// RUN: not %target-swift-frontend -parse %s -Xcc -include -Xcc %S/Inputs/bad-bridging-header.h -import-objc-header %S/../Inputs/empty.swift 2>&1 | FileCheck -check-prefix=CHECK-INCLUDE %s
8+
// RUN: not %target-swift-frontend -parse %s -Xcc -include -Xcc %S/Inputs/bad-bridging-header.h -import-objc-header %S/Inputs/sdk-bridging-header.h 2>&1 | FileCheck -check-prefix=CHECK-INCLUDE %s
9+
410
// CHECK-FATAL: failed to import bridging header
511

12+
// CHECK-INCLUDE: error: 'this-header-does-not-exist.h' file not found
13+
// CHECK-INCLUDE: error: use of unresolved identifier 'Predicate'
14+
615
// REQUIRES: objc_interop
716

817
import Foundation

0 commit comments

Comments
 (0)