Fix _bridgeToObjectiveC lookup code in optimizeBridgedSwiftToObjCCast

Previously it assumed that if we succeed in looking up the method in the current
module we must be able to request a definition (vs a declaration).

This is not true. It could be that we had declared the type in a different
module. Always ask for a declaration.

rdar://27547957
This commit is contained in:
Arnold Schwaighofer
2016-07-27 10:22:37 -07:00
parent 8c7e75afa0
commit c65e1a31e3
4 changed files with 6 additions and 15 deletions

View File

@@ -316,8 +316,10 @@ SILFunction *SILModule::getOrCreateFunction(SILLocation loc,
if (auto fn = lookUpFunction(name)) { if (auto fn = lookUpFunction(name)) {
assert(fn->getLoweredFunctionType() == constantType); assert(fn->getLoweredFunctionType() == constantType);
assert(fn->getLinkage() == constant.getLinkage(ForDefinition) assert(fn->getLinkage() == linkage ||
|| fn->getLinkage() == constant.getLinkage(NotForDefinition)); (forDefinition == ForDefinition_t::NotForDefinition &&
fn->getLinkage() ==
constant.getLinkage(ForDefinition_t::ForDefinition)));
if (forDefinition) { if (forDefinition) {
// In all the cases where getConstantLinkage returns something // In all the cases where getConstantLinkage returns something
// different for ForDefinition, it returns an available-externally // different for ForDefinition, it returns an available-externally

View File

@@ -1624,8 +1624,6 @@ optimizeBridgedSwiftToObjCCast(SILInstruction *Inst,
assert(Conf && "_ObjectiveCBridgeable conformance should exist"); assert(Conf && "_ObjectiveCBridgeable conformance should exist");
(void) Conf; (void) Conf;
bool isCurrentModuleBridgeToObjectiveC = false;
// Generate code to invoke _bridgeToObjectiveC // Generate code to invoke _bridgeToObjectiveC
SILBuilderWithScope Builder(Inst); SILBuilderWithScope Builder(Inst);
@@ -1647,16 +1645,13 @@ optimizeBridgedSwiftToObjCCast(SILInstruction *Inst,
M.getSwiftModule()->lookupMember(Results, Source.getNominalOrBoundGenericNominal(), M.getSwiftModule()->lookupMember(Results, Source.getNominalOrBoundGenericNominal(),
M.getASTContext().Id_bridgeToObjectiveC, Identifier()); M.getASTContext().Id_bridgeToObjectiveC, Identifier());
ResultsRef = Results; ResultsRef = Results;
isCurrentModuleBridgeToObjectiveC = true;
} }
if (ResultsRef.size() != 1) if (ResultsRef.size() != 1)
return nullptr; return nullptr;
auto MemberDeclRef = SILDeclRef(Results.front()); auto MemberDeclRef = SILDeclRef(Results.front());
auto Linkage = (isCurrentModuleBridgeToObjectiveC) auto *BridgedFunc = M.getOrCreateFunction(Loc, MemberDeclRef,
? ForDefinition_t::ForDefinition ForDefinition_t::NotForDefinition);
: ForDefinition_t::NotForDefinition;
auto *BridgedFunc = M.getOrCreateFunction(Loc, MemberDeclRef, Linkage);
assert(BridgedFunc && assert(BridgedFunc &&
"Implementation of _bridgeToObjectiveC could not be found"); "Implementation of _bridgeToObjectiveC could not be found");

View File

@@ -12,9 +12,6 @@
// RUN: %line-directive %t/main.swift -- %target-run %t/Dictionary // RUN: %line-directive %t/main.swift -- %target-run %t/Dictionary
// REQUIRES: executable_test // REQUIRES: executable_test
// rdar://27547957
// XFAIL: swift_test_mode_optimize
#if os(OSX) || os(iOS) || os(tvOS) || os(watchOS) #if os(OSX) || os(iOS) || os(tvOS) || os(watchOS)
import Darwin import Darwin
#else #else

View File

@@ -12,9 +12,6 @@
// RUN: %line-directive %t/main.swift -- %target-run %t/Set // RUN: %line-directive %t/main.swift -- %target-run %t/Set
// REQUIRES: executable_test // REQUIRES: executable_test
// rdar://27547957
// XFAIL: swift_test_mode_optimize
import StdlibUnittest import StdlibUnittest
import StdlibCollectionUnittest import StdlibCollectionUnittest