SIL: Revert public linkage for @_silgen_name forward declarations.

It turns out that the stdlib build depends on `internal` functions with
`@_silgen_name` getting hidden linkage in some configurations. Instead of
messing with the linkage computation, just fix the `stdlib/Error.swift` test by
making `setWillThrowHandler` `public` to give it the right linkage.

Resolves rdar://141590619.
This commit is contained in:
Allan Shortlidge
2024-12-17 08:34:16 -08:00
parent f2ad9f3d90
commit 95cc7319a1
3 changed files with 1 additions and 58 deletions

View File

@@ -651,14 +651,6 @@ SILLinkage SILDeclRef::getDefinitionLinkage() const {
effectiveAccess = std::max(effectiveAccess, AccessLevel::Internal);
}
// Declarations with a @_silgen_name attribute and no body may be forward
// declarations of functions defined in another module. Therefore they must
// always have external (public) linkage, regardless of declared access level.
if (auto afd = getAbstractFunctionDecl()) {
if (!afd->hasBody() && afd->getAttrs().hasAttribute<SILGenNameAttr>())
effectiveAccess = AccessLevel::Public;
}
switch (effectiveAccess) {
case AccessLevel::Private:
case AccessLevel::FilePrivate:

View File

@@ -1,49 +0,0 @@
// RUN: %target-swift-frontend -parse-as-library -emit-ir %s | %FileCheck %s
// Since this test depends on weak linking based on availability, it only
// applies to Apple platforms.
// REQUIRES: OS=macosx || OS=ios || OS=tvos || OS=watchos || OS=visionos
@available(SwiftStdlib 9999, *)
@_silgen_name("privateForwardDecl")
private func privateForwardDecl()
@available(SwiftStdlib 9999, *)
@_silgen_name("internalForwardDecl")
internal func internalForwardDecl()
@available(SwiftStdlib 9999, *)
@_silgen_name("publicForwardDecl")
public func publicForwardDecl()
@available(SwiftStdlib 9999, *)
@_silgen_name("privateDefined")
private func privateDefined() {}
// CHECK: define internal swiftcc void @privateDefined()
@available(SwiftStdlib 9999, *)
@_silgen_name("internalDefined")
internal func internalDefined() {}
// CHECK: define hidden swiftcc void @internalDefined()
@available(SwiftStdlib 9999, *)
@_silgen_name("publicDefined")
public func publicDefined() {}
// CHECK: define swiftcc void @publicDefined()
public func test() {
guard #available(SwiftStdlib 9999, *) else { return }
privateForwardDecl()
internalForwardDecl()
publicForwardDecl()
privateDefined()
internalDefined()
publicDefined()
}
// CHECK: declare extern_weak swiftcc void @privateForwardDecl()
// CHECK: declare extern_weak swiftcc void @internalForwardDecl()
// CHECK: declare extern_weak swiftcc void @publicForwardDecl()

View File

@@ -229,7 +229,7 @@ func throwJazzHandsTyped() throws(SillyError) {
// not available, so pass it through an UnsafeRawPointer.
@available(SwiftStdlib 5.8, *)
@_silgen_name("_swift_setWillThrowHandler")
func setWillThrowHandler(
public func setWillThrowHandler(
_ handler: (@convention(c) (UnsafeRawPointer) -> Void)?
)