r231092 - Support __attribute__((availability)) on Android.
Dan Albert
danalbert at google.com
Tue Mar 3 10:28:38 PST 2015
Author: danalbert
Date: Tue Mar 3 12:28:38 2015
New Revision: 231092
URL: http://llvm.org/viewvc/llvm-project?rev=231092&view=rev
Log:
Support __attribute__((availability)) on Android.
Reviewers: srhines
Reviewed By: srhines
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D7929
Added:
cfe/trunk/test/Sema/attr-availability-android.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/Basic/Targets.cpp
Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=231092&r1=231091&r2=231092&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Tue Mar 3 12:28:38 2015
@@ -440,6 +440,7 @@ def Availability : InheritableAttr {
let AdditionalMembers =
[{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
return llvm::StringSwitch<llvm::StringRef>(Platform)
+ .Case("android", "Android")
.Case("ios", "iOS")
.Case("macosx", "OS X")
.Case("ios_app_extension", "iOS (App Extension)")
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=231092&r1=231091&r2=231092&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Mar 3 12:28:38 2015
@@ -363,8 +363,13 @@ protected:
DefineStd(Builder, "linux", Opts);
Builder.defineMacro("__gnu_linux__");
Builder.defineMacro("__ELF__");
- if (Triple.getEnvironment() == llvm::Triple::Android)
+ if (Triple.getEnvironment() == llvm::Triple::Android) {
Builder.defineMacro("__ANDROID__", "1");
+ unsigned Maj, Min, Rev;
+ Triple.getOSVersion(Maj, Min, Rev);
+ this->PlatformName = "android";
+ this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
+ }
if (Opts.POSIXThreads)
Builder.defineMacro("_REENTRANT");
if (Opts.CPlusPlus)
Added: cfe/trunk/test/Sema/attr-availability-android.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-availability-android.c?rev=231092&view=auto
==============================================================================
--- cfe/trunk/test/Sema/attr-availability-android.c (added)
+++ cfe/trunk/test/Sema/attr-availability-android.c Tue Mar 3 12:28:38 2015
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 "-triple" "arm-linux-androideabi16" -fsyntax-only -verify %s
+
+void f0(int) __attribute__((availability(android,introduced=14,deprecated=19)));
+void f1(int) __attribute__((availability(android,introduced=16)));
+void f2(int) __attribute__((availability(android,introduced=14,deprecated=16))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(android,introduced=19)));
+void f4(int) __attribute__((availability(android,introduced=9,deprecated=11,obsoleted=16), availability(ios,introduced=2.0,deprecated=3.0))); // expected-note{{explicitly marked unavailable}}
+void f5(int) __attribute__((availability(ios,introduced=3.2), availability(android,unavailable))); // expected-note{{'f5' has been explicitly marked unavailable here}}
+
+void test() {
+ f0(0);
+ f1(0);
+ f2(0); // expected-warning{{'f2' is deprecated: first deprecated in Android 16}}
+ f3(0);
+ f4(0); // expected-error{{f4' is unavailable: obsoleted in Android 16}}
+ f5(0); // expected-error{{'f5' is unavailable: not available on Android}}
+}
+
+// rdar://10535640
+
+enum {
+ foo __attribute__((availability(android,introduced=8.0,deprecated=9.0)))
+};
+
+enum {
+ bar __attribute__((availability(android,introduced=8.0,deprecated=9.0))) = foo
+};
+
+enum __attribute__((availability(android,introduced=8.0,deprecated=9.0))) {
+ bar1 = foo
+};
More information about the cfe-commits
mailing list