Skip to content

Commit 48e23a6

Browse files
authored
Merge pull request #41647 from xymus/recover-from-anyobject-lookup
[Serialization] Recover from failures under AnyObjectLookup
2 parents 80c643e + 4d75242 commit 48e23a6

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,15 @@ void ModuleFile::lookupClassMember(ImportPath::Access accessPath,
774774
// one.
775775
if (name.isSimpleName()) {
776776
for (auto item : *iter) {
777-
auto vd = cast<ValueDecl>(getDecl(item.second));
777+
auto declOrError = getDeclChecked(item.second);
778+
if (!declOrError) {
779+
if (!getContext().LangOpts.EnableDeserializationRecovery)
780+
fatal(declOrError.takeError());
781+
consumeError(declOrError.takeError());
782+
continue;
783+
}
784+
785+
auto vd = cast<ValueDecl>(declOrError.get());
778786
auto dc = vd->getDeclContext();
779787
while (!dc->getParent()->isModuleScopeContext())
780788
dc = dc->getParent();
@@ -784,7 +792,15 @@ void ModuleFile::lookupClassMember(ImportPath::Access accessPath,
784792
}
785793
} else {
786794
for (auto item : *iter) {
787-
auto vd = cast<ValueDecl>(getDecl(item.second));
795+
auto declOrError = getDeclChecked(item.second);
796+
if (!declOrError) {
797+
if (!getContext().LangOpts.EnableDeserializationRecovery)
798+
fatal(declOrError.takeError());
799+
consumeError(declOrError.takeError());
800+
continue;
801+
}
802+
803+
auto vd = cast<ValueDecl>(declOrError.get());
788804
if (!vd->getName().matchesRef(name))
789805
continue;
790806

@@ -800,7 +816,15 @@ void ModuleFile::lookupClassMember(ImportPath::Access accessPath,
800816
}
801817

802818
for (auto item : *iter) {
803-
auto vd = cast<ValueDecl>(getDecl(item.second));
819+
auto declOrError = getDeclChecked(item.second);
820+
if (!declOrError) {
821+
if (!getContext().LangOpts.EnableDeserializationRecovery)
822+
fatal(declOrError.takeError());
823+
consumeError(declOrError.takeError());
824+
continue;
825+
}
826+
827+
auto vd = cast<ValueDecl>(declOrError.get());
804828
results.push_back(vd);
805829
}
806830
}
@@ -818,6 +842,8 @@ void ModuleFile::lookupClassMembers(ImportPath::Access accessPath,
818842
for (auto item : list) {
819843
auto decl = getDeclChecked(item.second);
820844
if (!decl) {
845+
if (!getContext().LangOpts.EnableDeserializationRecovery)
846+
fatal(decl.takeError());
821847
llvm::consumeError(decl.takeError());
822848
continue;
823849
}
@@ -839,6 +865,8 @@ void ModuleFile::lookupClassMembers(ImportPath::Access accessPath,
839865
for (auto item : list) {
840866
auto decl = getDeclChecked(item.second);
841867
if (!decl) {
868+
if (!getContext().LangOpts.EnableDeserializationRecovery)
869+
fatal(decl.takeError());
842870
llvm::consumeError(decl.takeError());
843871
continue;
844872
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#import <Foundation.h>
2+
3+
@interface ImplOnlyBase: NSObject @end

test/Serialization/Recovery/Inputs/custom-modules/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ module Typedefs { header "Typedefs.h" }
1414
module TypeRemovalObjC { header "TypeRemovalObjC.h" }
1515
module Types { header "Types.h" }
1616
module Conformance { header "Conformance.h" }
17+
module AnyObjectLookup { header "AnyObjectLookup.h" }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// Recover from searching though all possible methods on AnyObject.
2+
/// rdar://89494507
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -DLIB_B %s -module-name B -emit-module-path %t/B.swiftmodule -I %t -I %S/Inputs/custom-modules -enable-library-evolution -swift-version 5
6+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -DLIB_C %s -I %t -verify
7+
// Add this flag to the previous line to get back the original crash: -disable-deserialization-recovery
8+
9+
// REQUIRES: objc_interop
10+
11+
#if LIB_B
12+
13+
import Foundation
14+
@_implementationOnly import AnyObjectLookup
15+
16+
@objc internal class InternalClass: ImplOnlyBase {
17+
@objc func invisibleMethod() {
18+
}
19+
}
20+
21+
#elseif LIB_C
22+
23+
import B
24+
25+
func use(_ obj: AnyObject) {
26+
obj.invisibleMethod() // expected-error {{value of type 'AnyObject' has no member 'invisibleMethod'}}
27+
}
28+
29+
#endif

0 commit comments

Comments
 (0)