Skip to content

[Serialization] Fix deserialization crash occurring when a mixed framework fails to load its ObjC part. #4028

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
Aug 5, 2016
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
2 changes: 1 addition & 1 deletion lib/Serialization/ModuleFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ Status ModuleFile::associateWithFileContext(FileUnit *file,
"invalid module name (submodules not yet supported)");
}
auto module = getModule(modulePath);
if (!module) {
if (!module || module->failedToLoad()) {
// If we're missing the module we're shadowing, treat that specially.
if (modulePath.size() == 1 &&
modulePath.front() == file->getParentModule()->getName()) {
Expand Down
8 changes: 8 additions & 0 deletions test/Serialization/Inputs/MixModA.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
framework module MixModA {
export *
module * { export * }
}

module MixModA.Swift {
header "MixModA-Swift.h"
}
5 changes: 5 additions & 0 deletions test/Serialization/Inputs/SwiftModA.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ObjCFail

open class SwiftClsA {
public init() {}
}
5 changes: 5 additions & 0 deletions test/Serialization/Inputs/SwiftModB.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import MixModA

open class TyB : SwiftClsA {
public override init() { super.init() }
}
3 changes: 3 additions & 0 deletions test/Serialization/Inputs/objcfail/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module ObjCFail {
header "objcfail.h"
}
3 changes: 3 additions & 0 deletions test/Serialization/Inputs/objcfail/objcfail.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifdef FAIL
#error failing clang module
#endif
19 changes: 19 additions & 0 deletions test/Serialization/failed-clang-module.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Test that there is no crash in such a case:
// - there is mixed framework A
// - swift module B depends on A and is built fine
// - there is a swift invocation that imports B but causes the ObjC part of A to fail to import


// RUN: rm -rf %t
// RUN: mkdir -p %t/MixModA.framework/Headers
// RUN: mkdir -p %t/MixModA.framework/Modules/MixModA.swiftmodule
// RUN: cp %S/Inputs/MixModA.modulemap %t/MixModA.framework/Modules/module.modulemap

// 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
// RUN: %target-swift-frontend -emit-module %S/Inputs/SwiftModB.swift -module-name SwiftModB -F %t -o %t -module-cache-path %t/mcp
Copy link
Member

@rintaro rintaro Aug 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x86_64 should be %target-cpu
x86_64.swiftmodule should be %target-swiftmodule-name
PR: #4043


// RUN: %target-swift-frontend -parse %s -I %t -module-cache-path %t/mcp
// RUN: %target-swift-frontend -parse %s -Xcc -DFAIL -I %t -module-cache-path %t/mcp -show-diagnostics-after-fatal -verify

import SwiftModB // expected-error {{missing required module}}
_ = TyB() // expected-error {{use of unresolved identifier 'TyB'}}