Skip to content

Commit f1b347c

Browse files
committed
Handle non-deserializable SIL functions referenced in witness tables
This is enough to let the test case in rdar://problem/40899824 pass, and any callers of this function already need to be able to handle a nullptr result. There's a lot more work to do in this area, but it's nice to get the simple things working again.
1 parent 2a89d5c commit f1b347c

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

lib/Serialization/DeserializeSIL.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,15 @@ SILFunction *SILDeserializer::getFuncForReference(StringRef name) {
375375
if (iter == FuncTable->end())
376376
return nullptr;
377377

378-
return readSILFunction(*iter, nullptr, name, /*declarationOnly*/ true);
378+
auto maybeFn = readSILFunctionChecked(*iter, nullptr, name,
379+
/*declarationOnly*/ true);
380+
if (!maybeFn) {
381+
// Ignore the failure and just pretend the function doesn't exist
382+
llvm::consumeError(maybeFn.takeError());
383+
return nullptr;
384+
}
385+
386+
return maybeFn.get();
379387
}
380388

381389
/// Helper function to find a SILGlobalVariable given its name. It first checks
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module rdar40899824Helper { header "rdar40899824Helper.h" }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef BAD
2+
typedef struct {
3+
int value;
4+
} SoonToBeMissing;
5+
#endif
6+
7+
@interface Impl
8+
#ifndef BAD
9+
- (void)use:(SoonToBeMissing)value;
10+
#endif
11+
12+
- (void)unrelated;
13+
@end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -emit-module -o %t/Library.swiftmodule -I %S/Inputs/custom-modules -DLIBRARY -Xfrontend -enable-objc-interop -Xfrontend -disable-objc-attr-requires-foundation-module
3+
// RUN: %target-swift-frontend %s -I %t -I %S/Inputs/custom-modules -enable-objc-interop -emit-ir > /dev/null
4+
5+
// RUN: %target-swift-frontend %s -I %t -I %S/Inputs/custom-modules -enable-objc-interop -emit-ir -Xcc -DBAD > /dev/null
6+
// RUN: %target-swift-frontend %s -I %t -I %S/Inputs/custom-modules -enable-objc-interop -emit-ir -Xcc -DBAD -O > /dev/null
7+
8+
#if LIBRARY
9+
10+
import rdar40899824Helper
11+
12+
public protocol Proto: class {
13+
func use(_: SoonToBeMissing)
14+
func unrelated()
15+
}
16+
17+
extension Impl: Proto {}
18+
19+
#else // LIBRARY
20+
21+
import Library
22+
import rdar40899824Helper
23+
24+
func testGeneric<T: Proto>(_ obj: T) {
25+
obj.unrelated()
26+
}
27+
28+
func testExistential(_ obj: Proto) {
29+
obj.unrelated()
30+
}
31+
32+
func test(_ proto: Proto, _ impl: Impl) {
33+
impl.unrelated()
34+
testGeneric(impl)
35+
testExistential(impl)
36+
}
37+
38+
#endif // LIBRARY

0 commit comments

Comments
 (0)