Skip to content

Commit 8ca00d3

Browse files
authored
Merge pull request #36852 from jckarter/disable-availability-checking-assertion-failure
SILGen: Don't crash when compiling `if #available` with `-disable-availability-checking`.
2 parents 3decf42 + 18bd2f7 commit 8ca00d3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,9 +1359,13 @@ void SILGenFunction::emitStmtCondition(StmtCondition Cond, JumpDest FalseDest,
13591359
// Check the running OS version to determine whether it is in the range
13601360
// specified by elt.
13611361
VersionRange OSVersion = elt.getAvailability()->getAvailableRange();
1362-
assert(!OSVersion.isEmpty());
1363-
1364-
if (OSVersion.isAll()) {
1362+
1363+
// The OS version might be left empty if availability checking was
1364+
// disabled. Treat it as always-true in that case.
1365+
assert(!OSVersion.isEmpty()
1366+
|| getASTContext().LangOpts.DisableAvailabilityChecking);
1367+
1368+
if (OSVersion.isEmpty() || OSVersion.isAll()) {
13651369
// If there's no check for the current platform, this condition is
13661370
// trivially true.
13671371
SILType i1 = SILType::getBuiltinIntegerType(1, getASTContext());
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swift-emit-silgen -disable-availability-checking %s -verify
2+
3+
func foo() {
4+
if #available(macOS 10.15, *) {}
5+
}

0 commit comments

Comments
 (0)