Skip to content

Commit f3af4ae

Browse files
authored
Merge pull request #4028 from akyrtzi/deserialization-crash-27709042
[Serialization] Fix deserialization crash occurring when a mixed framework fails to load its ObjC part.
2 parents 3db6fd2 + 3bc81f7 commit f3af4ae

File tree

7 files changed

+44
-1
lines changed

7 files changed

+44
-1
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ Status ModuleFile::associateWithFileContext(FileUnit *file,
10931093
"invalid module name (submodules not yet supported)");
10941094
}
10951095
auto module = getModule(modulePath);
1096-
if (!module) {
1096+
if (!module || module->failedToLoad()) {
10971097
// If we're missing the module we're shadowing, treat that specially.
10981098
if (modulePath.size() == 1 &&
10991099
modulePath.front() == file->getParentModule()->getName()) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
framework module MixModA {
2+
export *
3+
module * { export * }
4+
}
5+
6+
module MixModA.Swift {
7+
header "MixModA-Swift.h"
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import ObjCFail
2+
3+
open class SwiftClsA {
4+
public init() {}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import MixModA
2+
3+
open class TyB : SwiftClsA {
4+
public override init() { super.init() }
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module ObjCFail {
2+
header "objcfail.h"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifdef FAIL
2+
#error failing clang module
3+
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Test that there is no crash in such a case:
2+
// - there is mixed framework A
3+
// - swift module B depends on A and is built fine
4+
// - there is a swift invocation that imports B but causes the ObjC part of A to fail to import
5+
6+
7+
// RUN: rm -rf %t
8+
// RUN: mkdir -p %t/MixModA.framework/Headers
9+
// RUN: mkdir -p %t/MixModA.framework/Modules/MixModA.swiftmodule
10+
// RUN: cp %S/Inputs/MixModA.modulemap %t/MixModA.framework/Modules/module.modulemap
11+
12+
// RUN: %target-swift-frontend -emit-module %S/Inputs/SwiftModA.swift -module-name MixModA -I %S/Inputs/objcfail -o %t/MixModA.framework/Modules/MixModA.swiftmodule/x86_64.swiftmodule -emit-objc-header -emit-objc-header-path %t/MixModA.framework/Headers/MixModA-Swift.h -module-cache-path %t/mcp
13+
// RUN: %target-swift-frontend -emit-module %S/Inputs/SwiftModB.swift -module-name SwiftModB -F %t -o %t -module-cache-path %t/mcp
14+
15+
// RUN: %target-swift-frontend -parse %s -I %t -module-cache-path %t/mcp
16+
// RUN: %target-swift-frontend -parse %s -Xcc -DFAIL -I %t -module-cache-path %t/mcp -show-diagnostics-after-fatal -verify
17+
18+
import SwiftModB // expected-error {{missing required module}}
19+
_ = TyB() // expected-error {{use of unresolved identifier 'TyB'}}

0 commit comments

Comments
 (0)