Skip to content

Commit 4197cef

Browse files
committed
AST: On iOS, use _stdlib_isOSVersionAtLeast_AEIC() for availability checks.
Resolves rdar://134793410.
1 parent fcead40 commit 4197cef

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

include/swift/AST/ASTContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,9 @@ class ASTContext final {
734734
// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast.
735735
FuncDecl *getIsOSVersionAtLeastDecl() const;
736736

737+
// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast_AEIC.
738+
FuncDecl *getIsOSVersionAtLeastAEICDecl() const;
739+
737740
// Retrieve the declaration of Swift._stdlib_isVariantOSVersionAtLeast.
738741
FuncDecl *getIsVariantOSVersionAtLeastDecl() const;
739742

lib/AST/ASTContext.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,13 @@ struct ASTContext::Implementation {
390390
/// -> Builtin.Int1
391391
FuncDecl *IsOSVersionAtLeastDecl = nullptr;
392392

393+
/// func _stdlib_isOSVersionAtLeast_AEIC(
394+
/// Builtin.Word,
395+
/// Builtin.Word,
396+
/// Builtin.word)
397+
/// -> Builtin.Int1
398+
FuncDecl *IsOSVersionAtLeastAEICDecl = nullptr;
399+
393400
/// func _stdlib_isVariantOSVersionAtLeast(
394401
/// Builtin.Word,
395402
/// Builtin.Word,
@@ -1828,6 +1835,18 @@ ConstructorDecl *ASTContext::getMakeUTF8StringDecl() const {
18281835
}
18291836

18301837
FuncDecl *ASTContext::getIsOSVersionAtLeastDecl() const {
1838+
// On iOS, the compiler should emit calls to the @_alwaysEmitIntoClient
1839+
// variant of _stdlib_isOSVersionAtLeast because availability checks must
1840+
// have the correct platform ID embedded in them in order for the binary to
1841+
// be able to run correctly on other platforms (e.g. macOS).
1842+
//
1843+
// FIXME: This exception should be temporary. The @_alwaysEmitIntoClient
1844+
// variant should be used consistently on all platforms in the future.
1845+
if (LangOpts.Target.getOS() == llvm::Triple::IOS) {
1846+
if (auto decl = getIsOSVersionAtLeastAEICDecl())
1847+
return decl;
1848+
}
1849+
18311850
if (getImpl().IsOSVersionAtLeastDecl)
18321851
return getImpl().IsOSVersionAtLeastDecl;
18331852

@@ -1861,6 +1880,18 @@ FuncDecl *ASTContext::getIsOSVersionAtLeastDecl() const {
18611880
return decl;
18621881
}
18631882

1883+
FuncDecl *ASTContext::getIsOSVersionAtLeastAEICDecl() const {
1884+
if (getImpl().IsOSVersionAtLeastAEICDecl)
1885+
return getImpl().IsOSVersionAtLeastAEICDecl;
1886+
1887+
auto decl = findLibraryIntrinsic(*this, "_stdlib_isOSVersionAtLeast_AEIC");
1888+
if (!decl)
1889+
return nullptr;
1890+
1891+
getImpl().IsOSVersionAtLeastAEICDecl = decl;
1892+
return decl;
1893+
}
1894+
18641895
FuncDecl *ASTContext::getIsVariantOSVersionAtLeastDecl() const {
18651896
if (getImpl().IsVariantOSVersionAtLeastDecl)
18661897
return getImpl().IsVariantOSVersionAtLeastDecl;

test/SILGen/availability_query_maccatalyst_zippered.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if #available(tvOS 9.0, *) {
5151
// CHECK: [[MACOS_MAJOR:%.*]] = integer_literal $Builtin.Word, 10
5252
// CHECK: [[MACOS_MINOR:%.*]] = integer_literal $Builtin.Word, 54
5353
// CHECK: [[MACOS_PATCH:%.*]] = integer_literal $Builtin.Word, 3
54-
// CHECK: [[QUERY_FUNC:%.*]] = function_ref @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
54+
// CHECK: [[QUERY_FUNC:%.*]] = function_ref @${{ss26_stdlib_isOSVersionAtLeasty|ss31_stdlib_isOSVersionAtLeast_AEICy}}Bi1_Bw_BwBwtF : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
5555
// CHECK: [[QUERY_RESULT:%.*]] = apply [[QUERY_FUNC]]([[MACOS_MAJOR]], [[MACOS_MINOR]], [[MACOS_PATCH]]) : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
5656
// The '*' matches for iOS, so we only need to check to check the
5757
// macOS version and thus use the primary target version check

0 commit comments

Comments
 (0)