|
14 | 14 | #include "clang/AST/ASTConsumer.h" |
15 | 15 | #include "clang/AST/ASTContext.h" |
16 | 16 | #include "clang/AST/ASTMutationListener.h" |
| 17 | +#include "clang/AST/Availability.h" |
17 | 18 | #include "clang/AST/CXXInheritance.h" |
18 | 19 | #include "clang/AST/Decl.h" |
19 | 20 | #include "clang/AST/DeclCXX.h" |
@@ -2358,7 +2359,8 @@ AvailabilityAttr *Sema::mergeAvailabilityAttr( |
2358 | 2359 | bool Implicit, VersionTuple Introduced, VersionTuple Deprecated, |
2359 | 2360 | VersionTuple Obsoleted, bool IsUnavailable, StringRef Message, |
2360 | 2361 | bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK, |
2361 | | - int Priority, const IdentifierInfo *Environment) { |
| 2362 | + int Priority, const IdentifierInfo *Environment, |
| 2363 | + VersionTuple OrigAnyAppleOSVersion) { |
2362 | 2364 | VersionTuple MergedIntroduced = Introduced; |
2363 | 2365 | VersionTuple MergedDeprecated = Deprecated; |
2364 | 2366 | VersionTuple MergedObsoleted = Obsoleted; |
@@ -2517,7 +2519,8 @@ AvailabilityAttr *Sema::mergeAvailabilityAttr( |
2517 | 2519 | !OverrideOrImpl) { |
2518 | 2520 | auto *Avail = ::new (Context) AvailabilityAttr( |
2519 | 2521 | Context, CI, Platform, Introduced, Deprecated, Obsoleted, IsUnavailable, |
2520 | | - Message, IsStrict, Replacement, Priority, Environment); |
| 2522 | + Message, IsStrict, Replacement, Priority, Environment, |
| 2523 | + OrigAnyAppleOSVersion); |
2521 | 2524 | Avail->setImplicit(Implicit); |
2522 | 2525 | return Avail; |
2523 | 2526 | } |
@@ -2703,6 +2706,63 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { |
2703 | 2706 | } |
2704 | 2707 | } |
2705 | 2708 |
|
| 2709 | + // Handle anyAppleOS specially: create implicit platform-specific attributes |
| 2710 | + // instead of the original anyAppleOS attribute. |
| 2711 | + if (II->getName() == "anyappleos") { |
| 2712 | + // Validate anyAppleOS versions; reject versions older than 26.0. |
| 2713 | + auto ValidateVersion = [&](const llvm::VersionTuple &Version, |
| 2714 | + SourceLocation Loc) -> bool { |
| 2715 | + if (AvailabilitySpec::validateAnyAppleOSVersion(Version)) |
| 2716 | + return true; |
| 2717 | + S.Diag(Loc, diag::err_availability_invalid_anyappleos_version) |
| 2718 | + << Version.getAsString(); |
| 2719 | + return false; |
| 2720 | + }; |
| 2721 | + |
| 2722 | + // Validate the versions; bail out if any are invalid. |
| 2723 | + bool Valid = ValidateVersion(Introduced.Version, Introduced.KeywordLoc); |
| 2724 | + Valid &= ValidateVersion(Deprecated.Version, Deprecated.KeywordLoc); |
| 2725 | + Valid &= ValidateVersion(Obsoleted.Version, Obsoleted.KeywordLoc); |
| 2726 | + if (!Valid) |
| 2727 | + return; |
| 2728 | + |
| 2729 | + llvm::Triple T = S.Context.getTargetInfo().getTriple(); |
| 2730 | + |
| 2731 | + // Only create implicit attributes for Darwin OSes. |
| 2732 | + if (!T.isOSDarwin()) |
| 2733 | + return; |
| 2734 | + |
| 2735 | + StringRef PlatformName; |
| 2736 | + |
| 2737 | + // Determine the platform name based on the target triple. |
| 2738 | + if (T.isMacOSX()) |
| 2739 | + PlatformName = "macos"; |
| 2740 | + else if (T.getOS() == llvm::Triple::IOS && T.isMacCatalystEnvironment()) |
| 2741 | + PlatformName = "maccatalyst"; |
| 2742 | + else // For iOS, tvOS, watchOS, visionOS, bridgeOS, etc. |
| 2743 | + PlatformName = llvm::Triple::getOSTypeName(T.getOS()); |
| 2744 | + |
| 2745 | + IdentifierInfo *NewII = &S.Context.Idents.get(PlatformName); |
| 2746 | + |
| 2747 | + // Use the special low-priority value for pragma push anyAppleOS. |
| 2748 | + int ExpandedPriority = |
| 2749 | + (PriorityModifier == Sema::AP_PragmaClangAttribute) |
| 2750 | + ? Sema::AP_PragmaClangAttribute_InferredFromAnyAppleOS |
| 2751 | + : Sema::AP_InferredFromAnyAppleOS; |
| 2752 | + |
| 2753 | + AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr( |
| 2754 | + ND, AL, NewII, /*Implicit=*/true, Introduced.Version, |
| 2755 | + Deprecated.Version, Obsoleted.Version, IsUnavailable, Str, IsStrict, |
| 2756 | + Replacement, AvailabilityMergeKind::None, ExpandedPriority, |
| 2757 | + IIEnvironment, Introduced.Version); |
| 2758 | + if (NewAttr) |
| 2759 | + D->addAttr(NewAttr); |
| 2760 | + |
| 2761 | + // Don't add the original anyAppleOS attribute - only the implicit |
| 2762 | + // platform-specific attributes. |
| 2763 | + return; |
| 2764 | + } |
| 2765 | + |
2706 | 2766 | AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr( |
2707 | 2767 | ND, AL, II, false /*Implicit*/, Introduced.Version, Deprecated.Version, |
2708 | 2768 | Obsoleted.Version, IsUnavailable, Str, IsStrict, Replacement, |
|
0 commit comments