r251711 - Support tvOS and watchOS availability attributes
Tim Northover via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 30 09:30:50 PDT 2015
Author: tnorthover
Date: Fri Oct 30 11:30:49 2015
New Revision: 251711
URL: http://llvm.org/viewvc/llvm-project?rev=251711&view=rev
Log:
Support tvOS and watchOS availability attributes
Added:
cfe/trunk/test/Sema/attr-availability-tvos.c
cfe/trunk/test/Sema/attr-availability-watchos.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=251711&r1=251710&r2=251711&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Fri Oct 30 11:30:49 2015
@@ -456,8 +456,12 @@ def Availability : InheritableAttr {
.Case("android", "Android")
.Case("ios", "iOS")
.Case("macosx", "OS X")
+ .Case("tvos", "tvOS")
+ .Case("watchos", "watchOS")
.Case("ios_app_extension", "iOS (App Extension)")
.Case("macosx_app_extension", "OS X (App Extension)")
+ .Case("tvos_app_extension", "tvOS (App Extension)")
+ .Case("watchos_app_extension", "watchOS (App Extension)")
.Default(llvm::StringRef());
} }];
let HasCustomParsing = 1;
Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=251711&r1=251710&r2=251711&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Fri Oct 30 11:30:49 2015
@@ -580,6 +580,14 @@ are:
Apple's Mac OS X operating system. The minimum deployment target is
specified by the ``-mmacosx-version-min=*version*`` command-line argument.
+``tvos``
+ Apple's tvOS operating system. The minimum deployment target is specified by
+ the ``-mtvos-version-min=*version*`` command-line argument.
+
+``watchos``
+ Apple's watchOS operating system. The minimum deployment target is specified by
+ the ``-mwatchos-version-min=*version*`` command-line argument.
+
A declaration can be used even when deploying back to a platform version prior
to when the declaration was introduced. When this happens, the declaration is
`weakly linked
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=251711&r1=251710&r2=251711&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Fri Oct 30 11:30:49 2015
@@ -1062,6 +1062,8 @@ static bool HasFeature(const Preprocesso
.Case("attribute_availability_with_message", true)
.Case("attribute_availability_app_extension", true)
.Case("attribute_availability_with_version_underscores", true)
+ .Case("attribute_availability_tvos", true)
+ .Case("attribute_availability_watchos", true)
.Case("attribute_cf_returns_not_retained", true)
.Case("attribute_cf_returns_retained", true)
.Case("attribute_cf_returns_on_parameters", true)
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=251711&r1=251710&r2=251711&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Oct 30 11:30:49 2015
@@ -1863,6 +1863,22 @@ AvailabilityAttr *Sema::mergeAvailabilit
continue;
}
+ // If there is an existing availability attribute for this platform that
+ // is explicit and the new one is implicit use the explicit one and
+ // discard the new implicit attribute.
+ if (OldAA->getRange().isValid() && Range.isInvalid()) {
+ return nullptr;
+ }
+
+ // If there is an existing attribute for this platform that is implicit
+ // and the new attribute is explicit then erase the old one and
+ // continue processing the attributes.
+ if (Range.isValid() && OldAA->getRange().isInvalid()) {
+ Attrs.erase(Attrs.begin() + i);
+ --e;
+ continue;
+ }
+
FoundAny = true;
VersionTuple OldIntroduced = OldAA->getIntroduced();
VersionTuple OldDeprecated = OldAA->getDeprecated();
@@ -2000,6 +2016,74 @@ static void handleAvailabilityAttr(Sema
Index);
if (NewAttr)
D->addAttr(NewAttr);
+
+ // Transcribe "ios" to "watchos" (and add a new attribute) if the versioning
+ // matches before the start of the watchOS platform.
+ if (S.Context.getTargetInfo().getTriple().isWatchOS()) {
+ IdentifierInfo *NewII = nullptr;
+ if (II->getName() == "ios")
+ NewII = &S.Context.Idents.get("watchos");
+ else if (II->getName() == "ios_app_extension")
+ NewII = &S.Context.Idents.get("watchos_app_extension");
+
+ if (NewII) {
+ auto adjustWatchOSVersion = [](VersionTuple Version) -> VersionTuple {
+ if (Version.empty())
+ return Version;
+ auto Major = Version.getMajor();
+ auto NewMajor = Major >= 9 ? Major - 7 : 0;
+ if (NewMajor >= 2) {
+ if (Version.getMinor().hasValue()) {
+ if (Version.getSubminor().hasValue())
+ return VersionTuple(NewMajor, Version.getMinor().getValue(),
+ Version.getSubminor().getValue());
+ else
+ return VersionTuple(NewMajor, Version.getMinor().getValue());
+ }
+ }
+
+ return VersionTuple(2, 0);
+ };
+
+ auto NewIntroduced = adjustWatchOSVersion(Introduced.Version);
+ auto NewDeprecated = adjustWatchOSVersion(Deprecated.Version);
+ auto NewObsoleted = adjustWatchOSVersion(Obsoleted.Version);
+
+ AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(ND,
+ SourceRange(),
+ NewII,
+ NewIntroduced,
+ NewDeprecated,
+ NewObsoleted,
+ IsUnavailable, Str,
+ Sema::AMK_None,
+ Index);
+ if (NewAttr)
+ D->addAttr(NewAttr);
+ }
+ } else if (S.Context.getTargetInfo().getTriple().isTvOS()) {
+ // Transcribe "ios" to "tvos" (and add a new attribute) if the versioning
+ // matches before the start of the tvOS platform.
+ IdentifierInfo *NewII = nullptr;
+ if (II->getName() == "ios")
+ NewII = &S.Context.Idents.get("tvos");
+ else if (II->getName() == "ios_app_extension")
+ NewII = &S.Context.Idents.get("tvos_app_extension");
+
+ if (NewII) {
+ AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(ND,
+ SourceRange(),
+ NewII,
+ Introduced.Version,
+ Deprecated.Version,
+ Obsoleted.Version,
+ IsUnavailable, Str,
+ Sema::AMK_None,
+ Index);
+ if (NewAttr)
+ D->addAttr(NewAttr);
+ }
+ }
}
template <class T>
Added: cfe/trunk/test/Sema/attr-availability-tvos.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-availability-tvos.c?rev=251711&view=auto
==============================================================================
--- cfe/trunk/test/Sema/attr-availability-tvos.c (added)
+++ cfe/trunk/test/Sema/attr-availability-tvos.c Fri Oct 30 11:30:49 2015
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos3.0" -fsyntax-only -verify %s
+
+void f0(int) __attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(tvos,introduced=2.1)));
+void f2(int) __attribute__((availability(tvos,introduced=2.0,deprecated=3.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(tvos,introduced=3.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
+
+void f5(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,deprecated=3.0)));
+void f6(int) __attribute__((availability(tvos,introduced=2.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+
+void test() {
+ f0(0); // expected-warning{{'f0' is deprecated: first deprecated in tvOS 2.1}}
+ f1(0);
+ f2(0); // expected-warning{{'f2' is deprecated: first deprecated in tvOS 3.0}}
+ f3(0);
+ f4(0); // expected-error{{f4' is unavailable: obsoleted in tvOS 3.0}}
+ f5(0); // expected-warning{{'f5' is deprecated: first deprecated in tvOS 3.0}}
+ f6(0); // expected-warning{{'f6' is deprecated: first deprecated in tvOS 3.0}}
+}
Added: cfe/trunk/test/Sema/attr-availability-watchos.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-availability-watchos.c?rev=251711&view=auto
==============================================================================
--- cfe/trunk/test/Sema/attr-availability-watchos.c (added)
+++ cfe/trunk/test/Sema/attr-availability-watchos.c Fri Oct 30 11:30:49 2015
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-watchos3.0" -fsyntax-only -verify %s
+
+void f0(int) __attribute__((availability(watchos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(watchos,introduced=2.1)));
+void f2(int) __attribute__((availability(watchos,introduced=2.0,deprecated=3.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(watchos,introduced=3.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(watchos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
+
+void f5(int) __attribute__((availability(watchos,introduced=2.0))) __attribute__((availability(watchos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(watchos,deprecated=3.0)));
+void f6(int) __attribute__((availability(watchos,introduced=2.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+
+void test() {
+ f0(0); // expected-warning{{'f0' is deprecated: first deprecated in watchOS 2.1}}
+ f1(0);
+ f2(0); // expected-warning{{'f2' is deprecated: first deprecated in watchOS 3.0}}
+ f3(0);
+ f4(0); // expected-error{{f4' is unavailable: obsoleted in watchOS 3.0}}
+ f5(0); // expected-warning{{'f5' is deprecated: first deprecated in watchOS 3.0}}
+ f6(0); // expected-warning{{'f6' is deprecated: first deprecated in watchOS 3.0}}
+}
More information about the cfe-commits
mailing list