Skip to content

Commit 52abd6c

Browse files
committed
AST/Sema: Adjust @backDeployed attribute diagnostics for unavailable decls
Use `inheritsAvailabilityFromPlatform()` to determine whether to suppress diagnostics about back deployed functions being unavailable. Previously, if the platform of the `@backDeployed` attribute and the platform of the `@available` attribute did not match exactly the diagnostic was always suppressed, which was too permissive.
1 parent 35afd7f commit 52abd6c

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

lib/AST/Decl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,10 @@ Decl::getIntroducedOSVersion(PlatformKind Kind) const {
551551

552552
llvm::Optional<llvm::VersionTuple>
553553
Decl::getBackDeployedBeforeOSVersion(ASTContext &Ctx) const {
554-
if (auto *attr = getAttrs().getBackDeployed(Ctx))
555-
return attr->Version;
554+
if (auto *attr = getAttrs().getBackDeployed(Ctx)) {
555+
auto version = attr->Version;
556+
return version;
557+
}
556558

557559
// Accessors may inherit `@backDeployed`.
558560
if (auto *AD = dyn_cast<AccessorDecl>(this))

lib/Sema/TypeCheckAttr.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4547,11 +4547,12 @@ void AttributeChecker::checkBackDeployedAttrs(
45474547
// Unavailable decls cannot be back deployed.
45484548
if (auto unavailableAttrPair = VD->getSemanticUnavailableAttr()) {
45494549
auto unavailableAttr = unavailableAttrPair.value().first;
4550+
if (!inheritsAvailabilityFromPlatform(unavailableAttr->Platform,
4551+
Attr->Platform)) {
4552+
auto platformString = prettyPlatformString(Attr->Platform);
45504553

4551-
if (unavailableAttr->Platform == PlatformKind::none ||
4552-
unavailableAttr->Platform == Attr->Platform) {
4553-
diagnose(AtLoc, diag::attr_has_no_effect_on_unavailable_decl, Attr,
4554-
VD, prettyPlatformString(Platform));
4554+
diagnose(AtLoc, diag::attr_has_no_effect_on_unavailable_decl, Attr, VD,
4555+
platformString);
45554556
diagnose(unavailableAttr->AtLoc, diag::availability_marked_unavailable,
45564557
VD)
45574558
.highlight(unavailableAttr->getRange());
@@ -4563,14 +4564,17 @@ void AttributeChecker::checkBackDeployedAttrs(
45634564
// If it's not, the attribute doesn't make sense since the back deployment
45644565
// fallback could never be executed at runtime.
45654566
if (auto availableRangeAttrPair = VD->getSemanticAvailableRangeAttr()) {
4567+
auto beforePlatformString = prettyPlatformString(Attr->Platform);
4568+
auto beforeVersion = Attr->Version;
45664569
auto availableAttr = availableRangeAttrPair.value().first;
4567-
if (Attr->Version <= availableAttr->Introduced.value()) {
4570+
auto introVersion = availableAttr->Introduced.value();
4571+
StringRef introPlatformString = availableAttr->prettyPlatformString();
4572+
4573+
if (Attr->Version <= introVersion) {
45684574
diagnose(AtLoc, diag::attr_has_no_effect_decl_not_available_before,
4569-
Attr, VD, prettyPlatformString(Platform),
4570-
Attr->Version);
4575+
Attr, VD, beforePlatformString, beforeVersion);
45714576
diagnose(availableAttr->AtLoc, diag::availability_introduced_in_version,
4572-
VD, prettyPlatformString(availableAttr->Platform),
4573-
*availableAttr->Introduced)
4577+
VD, introPlatformString, introVersion)
45744578
.highlight(availableAttr->getRange());
45754579
continue;
45764580
}

0 commit comments

Comments
 (0)