Skip to content

Commit 7387f85

Browse files
authored
Merge pull request #81767 from tshortli/fix-zippered-custom-availability-queries
SILGen: Fix `if #available` for unavailable custom domains in zippered modules
2 parents 0027779 + 4aa516a commit 7387f85

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,13 @@ SILValue SILGenFunction::emitZipperedOSVersionRangeCheck(
18511851
return B.createIntegerLiteral(loc, i1, true);
18521852
}
18531853

1854+
// If either version is "never" then the check is trivially false because it
1855+
// can never succeed.
1856+
if (OSVersion.isEmpty() || VariantOSVersion.isEmpty()) {
1857+
SILType i1 = SILType::getBuiltinIntegerType(1, getASTContext());
1858+
return B.createIntegerLiteral(loc, i1, false);
1859+
}
1860+
18541861
// The variant-only availability-checking entrypoint is not part
18551862
// of the Swift 5.0 ABI. It is only available in macOS 10.15 and above.
18561863
bool isVariantEntrypointAvailable = !TargetTriple.isMacOSXVersionLT(10, 15);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// RUN: %target-swift-emit-irgen -module-name Test %s -verify \
2+
// RUN: -enable-experimental-feature CustomAvailability \
3+
// RUN: -define-enabled-availability-domain EnabledDomain \
4+
// RUN: -define-disabled-availability-domain DisabledDomain \
5+
// RUN: -target %target-cpu-apple-macosx13 \
6+
// RUN: -target-variant %target-cpu-apple-ios16-macabi \
7+
// RUN: -Onone | %FileCheck %s --check-prefixes=CHECK
8+
9+
// RUN: %target-swift-emit-irgen -module-name Test %s -verify \
10+
// RUN: -enable-experimental-feature CustomAvailability \
11+
// RUN: -define-enabled-availability-domain EnabledDomain \
12+
// RUN: -define-disabled-availability-domain DisabledDomain \
13+
// RUN: -target %target-cpu-apple-macosx13 \
14+
// RUN: -target-variant %target-cpu-apple-ios16-macabi \
15+
// RUN: -O | %FileCheck %s --check-prefixes=CHECK
16+
17+
// REQUIRES: OS=macosx || OS=maccatalyst
18+
// REQUIRES: swift_feature_CustomAvailability
19+
20+
@_silgen_name("always")
21+
public func always()
22+
23+
@_silgen_name("never")
24+
public func never()
25+
26+
// CHECK-NOT: call swiftcc void @never()
27+
28+
// CHECK: call swiftcc void @always()
29+
// CHECK-NOT: call swiftcc void @never()
30+
if #available(EnabledDomain) {
31+
always()
32+
} else {
33+
never()
34+
}
35+
36+
// CHECK: call swiftcc void @always()
37+
// CHECK-NOT: call swiftcc void @never()
38+
if #available(DisabledDomain) {
39+
never()
40+
} else {
41+
always()
42+
}
43+
44+
// FIXME: [availability] These CHECK lines for if #unavailable are inverted (rdar://147929876)
45+
// CHECK-NOT: call swiftcc void @always()
46+
// CHECK: call swiftcc void @never()
47+
if #unavailable(EnabledDomain) {
48+
never()
49+
} else {
50+
always()
51+
}
52+
53+
// CHECK-NOT: call swiftcc void @always()
54+
// CHECK: call swiftcc void @never()
55+
if #unavailable(DisabledDomain) {
56+
always()
57+
} else {
58+
never()
59+
}

0 commit comments

Comments
 (0)