Skip to content

Commit 77d8c46

Browse files
committed
[Serialization] Recover from deserialization failures in ModuleFile::lookupObjCMethods
This was reported by deserialization safety in: Interpreter/SDK/Foundation_NSString.swift
1 parent 88d796b commit 77d8c46

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,13 @@ void ModuleFile::lookupObjCMethods(
885885
auto found = *known;
886886
for (const auto &result : found) {
887887
// Deserialize the method and add it to the list.
888-
if (auto func = dyn_cast_or_null<AbstractFunctionDecl>(
889-
getDecl(std::get<2>(result))))
888+
auto declOrError = getDeclChecked(std::get<2>(result));
889+
if (!declOrError) {
890+
consumeError(declOrError.takeError());
891+
continue;
892+
}
893+
894+
if (auto func = dyn_cast_or_null<AbstractFunctionDecl>(declOrError.get()))
890895
results.push_back(func);
891896
}
892897
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -typecheck -verify %s \
2+
// RUN: -enable-deserialization-safety \
3+
// RUN: -Xllvm -debug-only=Serialization 2>&1 | %FileCheck %s
4+
5+
// REQUIRES: objc_interop
6+
// REQUIRES: asserts
7+
8+
import Foundation
9+
10+
// Fails at reading __SwiftNativeNSEnumerator.init() on macOS.
11+
NSString.instancesRespond(to: "init") // expected-warning {{use of string literal for Objective-C selectors is deprecated; use '#selector' instead}}
12+
// CHECK: Skipping unsafe deserialization: 'init()'

0 commit comments

Comments
 (0)