Skip to content

Commit

Permalink
AST: On iOS, use _stdlib_isOSVersionAtLeast_AEIC() for availability c…
Browse files Browse the repository at this point in the history
…hecks.

Resolves rdar://134793410.
  • Loading branch information
tshortli committed Aug 28, 2024
1 parent fcead40 commit 4197cef
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,9 @@ class ASTContext final {
// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast.
FuncDecl *getIsOSVersionAtLeastDecl() const;

// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast_AEIC.
FuncDecl *getIsOSVersionAtLeastAEICDecl() const;

// Retrieve the declaration of Swift._stdlib_isVariantOSVersionAtLeast.
FuncDecl *getIsVariantOSVersionAtLeastDecl() const;

Expand Down
31 changes: 31 additions & 0 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ struct ASTContext::Implementation {
/// -> Builtin.Int1
FuncDecl *IsOSVersionAtLeastDecl = nullptr;

/// func _stdlib_isOSVersionAtLeast_AEIC(
/// Builtin.Word,
/// Builtin.Word,
/// Builtin.word)
/// -> Builtin.Int1
FuncDecl *IsOSVersionAtLeastAEICDecl = nullptr;

/// func _stdlib_isVariantOSVersionAtLeast(
/// Builtin.Word,
/// Builtin.Word,
Expand Down Expand Up @@ -1828,6 +1835,18 @@ ConstructorDecl *ASTContext::getMakeUTF8StringDecl() const {
}

FuncDecl *ASTContext::getIsOSVersionAtLeastDecl() const {
// On iOS, the compiler should emit calls to the @_alwaysEmitIntoClient
// variant of _stdlib_isOSVersionAtLeast because availability checks must
// have the correct platform ID embedded in them in order for the binary to
// be able to run correctly on other platforms (e.g. macOS).
//
// FIXME: This exception should be temporary. The @_alwaysEmitIntoClient
// variant should be used consistently on all platforms in the future.
if (LangOpts.Target.getOS() == llvm::Triple::IOS) {
if (auto decl = getIsOSVersionAtLeastAEICDecl())
return decl;
}

if (getImpl().IsOSVersionAtLeastDecl)
return getImpl().IsOSVersionAtLeastDecl;

Expand Down Expand Up @@ -1861,6 +1880,18 @@ FuncDecl *ASTContext::getIsOSVersionAtLeastDecl() const {
return decl;
}

FuncDecl *ASTContext::getIsOSVersionAtLeastAEICDecl() const {
if (getImpl().IsOSVersionAtLeastAEICDecl)
return getImpl().IsOSVersionAtLeastAEICDecl;

auto decl = findLibraryIntrinsic(*this, "_stdlib_isOSVersionAtLeast_AEIC");
if (!decl)
return nullptr;

getImpl().IsOSVersionAtLeastAEICDecl = decl;
return decl;
}

FuncDecl *ASTContext::getIsVariantOSVersionAtLeastDecl() const {
if (getImpl().IsVariantOSVersionAtLeastDecl)
return getImpl().IsVariantOSVersionAtLeastDecl;
Expand Down
2 changes: 1 addition & 1 deletion test/SILGen/availability_query_maccatalyst_zippered.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if #available(tvOS 9.0, *) {
// CHECK: [[MACOS_MAJOR:%.*]] = integer_literal $Builtin.Word, 10
// CHECK: [[MACOS_MINOR:%.*]] = integer_literal $Builtin.Word, 54
// CHECK: [[MACOS_PATCH:%.*]] = integer_literal $Builtin.Word, 3
// CHECK: [[QUERY_FUNC:%.*]] = function_ref @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
// 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
// CHECK: [[QUERY_RESULT:%.*]] = apply [[QUERY_FUNC]]([[MACOS_MAJOR]], [[MACOS_MINOR]], [[MACOS_PATCH]]) : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
// The '*' matches for iOS, so we only need to check to check the
// macOS version and thus use the primary target version check
Expand Down

0 comments on commit 4197cef

Please sign in to comment.