Skip to content

[6.2] SILGen: Fix if #available for unavailable custom domains in zippered modules #81776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,13 @@ SILValue SILGenFunction::emitZipperedOSVersionRangeCheck(
return B.createIntegerLiteral(loc, i1, true);
}

// If either version is "never" then the check is trivially false because it
// can never succeed.
if (OSVersion.isEmpty() || VariantOSVersion.isEmpty()) {
SILType i1 = SILType::getBuiltinIntegerType(1, getASTContext());
return B.createIntegerLiteral(loc, i1, false);
}

// The variant-only availability-checking entrypoint is not part
// of the Swift 5.0 ABI. It is only available in macOS 10.15 and above.
bool isVariantEntrypointAvailable = !TargetTriple.isMacOSXVersionLT(10, 15);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// RUN: %target-swift-emit-irgen -module-name Test %s -verify \
// RUN: -enable-experimental-feature CustomAvailability \
// RUN: -define-enabled-availability-domain EnabledDomain \
// RUN: -define-disabled-availability-domain DisabledDomain \
// RUN: -target %target-cpu-apple-macosx13 \
// RUN: -target-variant %target-cpu-apple-ios16-macabi \
// RUN: -Onone | %FileCheck %s --check-prefixes=CHECK

// RUN: %target-swift-emit-irgen -module-name Test %s -verify \
// RUN: -enable-experimental-feature CustomAvailability \
// RUN: -define-enabled-availability-domain EnabledDomain \
// RUN: -define-disabled-availability-domain DisabledDomain \
// RUN: -target %target-cpu-apple-macosx13 \
// RUN: -target-variant %target-cpu-apple-ios16-macabi \
// RUN: -O | %FileCheck %s --check-prefixes=CHECK

// REQUIRES: OS=macosx || OS=maccatalyst
// REQUIRES: swift_feature_CustomAvailability

@_silgen_name("always")
public func always()

@_silgen_name("never")
public func never()

// CHECK-NOT: call swiftcc void @never()

// CHECK: call swiftcc void @always()
// CHECK-NOT: call swiftcc void @never()
if #available(EnabledDomain) {
always()
} else {
never()
}

// CHECK: call swiftcc void @always()
// CHECK-NOT: call swiftcc void @never()
if #available(DisabledDomain) {
never()
} else {
always()
}

// FIXME: [availability] These CHECK lines for if #unavailable are inverted (rdar://147929876)
// CHECK-NOT: call swiftcc void @always()
// CHECK: call swiftcc void @never()
if #unavailable(EnabledDomain) {
never()
} else {
always()
}

// CHECK-NOT: call swiftcc void @always()
// CHECK: call swiftcc void @never()
if #unavailable(DisabledDomain) {
always()
} else {
never()
}