Skip to content

Commit 1e45942

Browse files
committed
[Serialization] Skip MissingMembers when allowing errors
A normal compilation would error before merging modules when there are MissingMemberDecls, so the missing member case is unreachable. That's not true when allowing errors though, where we continue regardless. Skip the missing member instead of crashing. Resolves rdar://76365694.
1 parent 5a387d7 commit 1e45942

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,8 @@ static bool shouldSerializeMember(Decl *D) {
16111611
llvm_unreachable("decl should never be a member");
16121612

16131613
case DeclKind::MissingMember:
1614+
if (D->getASTContext().LangOpts.AllowModuleWithCompilerErrors)
1615+
return false;
16141616
llvm_unreachable("should never need to reserialize a member placeholder");
16151617

16161618
case DeclKind::IfConfig:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/mods)
3+
4+
// RUN: touch %t/empty.swift
5+
// RUN: %{python} %utils/split_file.py -o %t %s
6+
7+
// We're going to swap A and B around to cause an invalid xref
8+
// RUN: %target-swift-frontend -emit-module -o %t/mods/A.swiftmodule -module-name A %t/lib.swift
9+
// RUN: %target-swift-frontend -emit-module -o %t/mods/B.swiftmodule -module-name B %t/empty.swift
10+
11+
// Compile using SomeType from A
12+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsmain.partial.swiftmodule -I %t/mods %t/errors.swift
13+
// Empty module so we can do a merge modules step
14+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsempty.partial.swiftmodule %t/empty.swift
15+
16+
// Swap A and B
17+
// RUN: %target-swift-frontend -emit-module -o %t/mods/A.swiftmodule -module-name A %t/empty.swift
18+
// RUN: %target-swift-frontend -emit-module -o %t/mods/B.swiftmodule -module-name B %t/lib.swift
19+
20+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errors.swiftmodule -experimental-allow-module-with-compiler-errors %t/mods/errorsmain.partial.swiftmodule %t/mods/errorsempty.partial.swiftmodule
21+
22+
// Expect this to crash without allowing errors (we should never get into a
23+
// situation where merge modules is run with MissingMemberDecls)
24+
// RUN: not --crash %target-swift-frontend -module-name errors -emit-module -o %t/mods/errors.swiftmodule %t/mods/errorsmain.partial.swiftmodule %t/mods/errorsempty.partial.swiftmodule
25+
26+
// BEGIN lib.swift
27+
public struct SomeType {
28+
public init() {}
29+
}
30+
31+
32+
// BEGIN errors.swift
33+
import A
34+
import B
35+
36+
public class SomeClass {
37+
public let member: SomeType
38+
public init(member: SomeType) {
39+
self.member = member
40+
}
41+
}

0 commit comments

Comments
 (0)