Skip to content

Commit 30bdb6b

Browse files
committed
[Serialization] Don't serialize an internally-imported bridging header
Internally-imported bridging headers must not leak outside of the Swift module. Don't serialize their contents, and make sure we can still import the module even if the bridging header has been removed.
1 parent b9f00ef commit 30bdb6b

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
197197
serializationOpts.DocOutputPath = outs.ModuleDocOutputPath;
198198
serializationOpts.SourceInfoOutputPath = outs.ModuleSourceInfoOutputPath;
199199
serializationOpts.GroupInfoPath = opts.GroupInfoPath.c_str();
200-
if (opts.ModuleHasBridgingHeader && !outs.ModuleOutputPath.empty())
200+
if (opts.ModuleHasBridgingHeader && !outs.ModuleOutputPath.empty() &&
201+
!opts.ImportHeaderAsInternal)
201202
serializationOpts.SerializeBridgingHeader = true;
202203
// For batch mode, emit empty header path as placeholder.
203204
if (serializationOpts.SerializeBridgingHeader &&
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// Stage in the headers we need
4+
// RUN: mkdir %t/headers
5+
// RUN: cp %S/../Inputs/c-bridging-header.h %t/headers
6+
7+
// RUN: mkdir %t/src
8+
// RUN: split-file %s %t/src
9+
10+
// Build a module
11+
// RUN: mkdir %t/modules
12+
// RUN: %target-swift-frontend -internal-import-bridging-header %t/headers/c-bridging-header.h -sdk %clang-importer-sdk -emit-module -o %t/modules/MyModule.swiftmodule %t/src/MyModule.swift
13+
14+
// Check that there's no serialized bridging header in the module file.
15+
// RUN: llvm-bcanalyzer -dump %t/modules/MyModule.swiftmodule | %FileCheck -check-prefix MODULE-FILE %s
16+
17+
// Use the module.
18+
// RUN: %target-swift-frontend -typecheck -sdk %clang-importer-sdk -I %t/modules %t/src/MyClient.swift
19+
20+
// Delete the bridging header, and again use the module.
21+
// RUN: rm %t/headers/c-bridging-header.h
22+
// RUN: %target-swift-frontend -typecheck -sdk %clang-importer-sdk -I %t/modules %t/src/MyClient.swift
23+
24+
//--- MyModule.swift
25+
func getRed() -> Color { red }
26+
27+
func getX(point: MyPoint) -> Double { point.x }
28+
29+
public func f() {
30+
_ = getRed()
31+
}
32+
33+
//--- MyClient.swift
34+
35+
import MyModule
36+
37+
func g() {
38+
f()
39+
}
40+
41+
42+
// MODULE-FILE-NOT: IMPORTED_HEADER
43+
// MODULE-FILE-NOT: IMPORTED_HEADER_CONTENTS
44+
45+
// MODULE-FILE: SEARCH_PATH
46+
47+
// MODULE-FILE-NOT: IMPORTED_HEADER
48+
// MODULE-FILE-NOT: IMPORTED_HEADER_CONTENTS

0 commit comments

Comments
 (0)