Skip to content

Commit c5fe028

Browse files
authored
Merge pull request swiftlang#70860 from hyp/eng/lnk4217_bridgeObjc
[SILOptimizer] set the parent module context for _bridgeToObjectiveC …
2 parents 0cc72fb + 7356870 commit c5fe028

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,12 @@ findBridgeToObjCFunc(SILOptFunctionBuilder &functionBuilder,
522522
// Implementation of _bridgeToObjectiveC could not be found.
523523
if (!bridgedFunc)
524524
return llvm::None;
525+
// The bridging function must have the correct parent module set. This ensures
526+
// that IRGen sets correct linkage when this function comes from the same
527+
// module as being compiled.
528+
if (!bridgedFunc->getDeclContext())
529+
bridgedFunc->setParentModule(
530+
resultDecl->getDeclContext()->getParentModule());
525531

526532
if (dynamicCast.getFunction()->isSerialized() &&
527533
!bridgedFunc->hasValidLinkageForFragileRef())
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Input for bridged_casts_folding_same_module.swift test case.
2+
3+
open class NSObject {
4+
public init() {}
5+
}
6+
7+
extension AnyHashable : _ObjectiveCBridgeable {
8+
public func _bridgeToObjectiveC() -> NSObject {
9+
return NSObject()
10+
}
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -O -emit-ir %S/Inputs/foundation_bridging.swift -primary-file %s -disable-autolink-framework CoreFoundation -parse-as-library -module-name Foundation | %FileCheck %s
2+
3+
// REQUIRES: OS=windows-msvc
4+
5+
open class NSSet {
6+
public init(_ set: AnyHashable) {
7+
if let item = set as? NSObject {
8+
print("yay, has object!")
9+
}
10+
}
11+
}
12+
13+
// Ensure that the _bridgeToObjectiveC function (from the same module) is not annotated
14+
// with 'dllimport'.
15+
// CHECK: declare swiftcc ptr @"$ss11AnyHashableV10FoundationE19_bridgeToObjectiveCAC8NSObjectCyF"

0 commit comments

Comments
 (0)