Skip to content

Commit c464741

Browse files
committed
Sema: Allow _diagnoseUnavailableCodeReached() to not exist in the stdlib.
Sometimes the compiler may need to build with an out-of-date standard library and we can't assume recently added well-known declarations are present. When synthesizing Hashable and Equatable conformances, if `_diagnoseUnavailableCodeReached()` isn't present then just generate the body of the case normally instead. This isn't ideal, but there isn't any existing infrastructure to generate a call to `fatalError()` at the AST level and this should be a rare edge case where we're simply falling back to the previous behavior where unavailable cases weren't handled at all. No tests because it isn't straight forward to compile with an intentionally broken standard library that's missing some declarations. Resolves rdar://120554183
1 parent 2c2f05e commit c464741

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/Sema/DerivedConformances.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ DerivedConformance::createBuiltinCall(ASTContext &ctx,
496496
CallExpr *DerivedConformance::createDiagnoseUnavailableCodeReachedCallExpr(
497497
ASTContext &ctx) {
498498
FuncDecl *diagnoseDecl = ctx.getDiagnoseUnavailableCodeReachedDecl();
499+
assert(diagnoseDecl);
499500
auto diagnoseDeclRefExpr =
500501
new (ctx) DeclRefExpr(diagnoseDecl, DeclNameLoc(), true);
501502
diagnoseDeclRefExpr->setType(diagnoseDecl->getInterfaceType());
@@ -939,6 +940,12 @@ CaseStmt *DerivedConformance::unavailableEnumElementCaseStmt(
939940
if (!availableAttr->isUnconditionallyUnavailable())
940941
return nullptr;
941942

943+
// If the stdlib isn't new enough to contain the helper function for
944+
// diagnosing execution of unavailable code then just synthesize this case
945+
// normally.
946+
if (!C.getDiagnoseUnavailableCodeReachedDecl())
947+
return nullptr;
948+
942949
auto createElementPattern = [&]() -> EnumElementPattern * {
943950
// .<elt>
944951
EnumElementPattern *eltPattern = new (C) EnumElementPattern(

0 commit comments

Comments
 (0)