Merge pull request #12680 from DougGregor/importer-bridged-typedef-4.1
[Clang importer] Fix bridging of the underlying types of typedefs.
diff --git a/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp b/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp
index 8162028..18fee20 100644
--- a/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp
+++ b/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp
@@ -223,15 +223,22 @@
auto id = component.getComputedPropertyId();
switch (id.getKind()) {
case KeyPathPatternComponent::ComputedPropertyId::DeclRef: {
- auto decl = cast<AbstractFunctionDecl>(id.getDeclRef().getDecl());
- if (auto clas = dyn_cast<ClassDecl>(decl->getDeclContext())) {
- ensureAliveClassMethod(getMethodInfo(decl, /*witness*/ false),
- dyn_cast<FuncDecl>(decl),
- clas);
- } else if (isa<ProtocolDecl>(decl->getDeclContext())) {
- ensureAliveProtocolMethod(getMethodInfo(decl, /*witness*/ true));
+ auto declRef = id.getDeclRef();
+ if (declRef.isForeign) {
+ // Nothing to do here: foreign functions aren't ours to be deleting.
+ // (And even if they were, they're ObjC-dispatched and thus anchored
+ // already: see isAnchorFunction)
} else {
- llvm_unreachable("key path keyed by a non-class, non-protocol method");
+ auto decl = cast<AbstractFunctionDecl>(declRef.getDecl());
+ if (auto clas = dyn_cast<ClassDecl>(decl->getDeclContext())) {
+ ensureAliveClassMethod(getMethodInfo(decl, /*witness*/ false),
+ dyn_cast<FuncDecl>(decl),
+ clas);
+ } else if (isa<ProtocolDecl>(decl->getDeclContext())) {
+ ensureAliveProtocolMethod(getMethodInfo(decl, /*witness*/ true));
+ } else {
+ llvm_unreachable("key path keyed by a non-class, non-protocol method");
+ }
}
break;
}
diff --git a/test/SILOptimizer/Inputs/keypaths_objc.h b/test/SILOptimizer/Inputs/keypaths_objc.h
new file mode 100644
index 0000000..f1a379b
--- /dev/null
+++ b/test/SILOptimizer/Inputs/keypaths_objc.h
@@ -0,0 +1,14 @@
+@import Foundation;
+
+@interface ObjCFoo
+
+@property(readonly) NSString *_Nonnull objcProp;
+
+@end
+
+
+@interface ObjCFoo (Extras)
+
+@property(readonly) NSString *_Nonnull objcExtraProp;
+
+@end
diff --git a/test/SILOptimizer/dead_func_objc_extension_keypath.swift b/test/SILOptimizer/dead_func_objc_extension_keypath.swift
new file mode 100644
index 0000000..ca04f4c
--- /dev/null
+++ b/test/SILOptimizer/dead_func_objc_extension_keypath.swift
@@ -0,0 +1,7 @@
+// RUN: %target-swift-frontend %s -O -emit-sil -import-objc-header %S/Inputs/keypaths_objc.h
+// REQUIRES: objc_interop
+
+import Foundation
+public func test_nocrash_rdar34913689() {
+ _ = \ObjCFoo.objcExtraProp
+}