[PATCH] D26385: Define __ANDROID_API__ for all Android builds.

Stephen Hines via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 7 21:41:25 PST 2016


srhines created this revision.
srhines added subscribers: danalbert, eugenis, pirama, cfe-commits.
Herald added a subscriber: tberghammer.

Bug: https://llvm.org/bugs/show_bug.cgi?id=30940

This macro (along with __ANDROID__) should always be defined for Android
targets. We set it to the major (only) version of the Android API being
compiled for. The Android version is able to be set as an integer suffix
for any valid Android target.


https://reviews.llvm.org/D26385

Files:
  lib/Basic/Targets.cpp
  test/Driver/android-targets.cpp


Index: test/Driver/android-targets.cpp
===================================================================
--- /dev/null
+++ test/Driver/android-targets.cpp
@@ -0,0 +1,83 @@
+// Test API-related defines for various Android targets.
+//
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target arm-linux-androideabi \
+// RUN:   | FileCheck %s
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target arm-linux-androideabi19 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL19
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target arm-linux-androideabi20 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL20
+//
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target aarch64-linux-android \
+// RUN:   | FileCheck %s
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target aarch64-linux-android19 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL19
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target aarch64-linux-android20 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL20
+//
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target i686-linux-android \
+// RUN:   | FileCheck %s
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target i686-linux-android19 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL19
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target i686-linux-android20 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL20
+//
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target x86_64-linux-android \
+// RUN:   | FileCheck %s
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target x86_64-linux-android19 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL19
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target x86_64-linux-android20 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL20
+//
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target mipsel-linux-android \
+// RUN:   | FileCheck %s
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target mipsel-linux-android19 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL19
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target mipsel-linux-android20 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL20
+//
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target mips64el-linux-android \
+// RUN:   | FileCheck %s
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target mips64el-linux-android19 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL19
+// RUN: %clang %s -emit-llvm -S -c -o - \
+// RUN:     -target mips64el-linux-android20 \
+// RUN:   | FileCheck %s -check-prefix=LEVEL20
+
+// CHECK: __ANDROID__defined
+// LEVEL19: __ANDROID__defined
+// LEVEL20: __ANDROID__defined
+#ifdef __ANDROID__
+void __ANDROID__defined(void) {}
+#endif
+
+// CHECK: __ANDROID_API__defined
+// LEVEL19: __ANDROID_API__defined
+// LEVEL20: __ANDROID_API__defined
+#ifdef __ANDROID_API__
+void __ANDROID_API__defined(void) {}
+int android_api = __ANDROID_API__;
+#endif
+
+// CHECK-NOT: __ANDROID_API__20
+// LEVEL19-NOT: __ANDROID_API__20
+// LEVEL20: __ANDROID_API__20
+#if __ANDROID_API__ >= 20
+void __ANDROID_API__20(void) {}
+#endif
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -465,6 +465,7 @@
       Triple.getEnvironmentVersion(Maj, Min, Rev);
       this->PlatformName = "android";
       this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
+      Builder.defineMacro("__ANDROID_API__", Twine(Maj));
     }
     if (Opts.POSIXThreads)
       Builder.defineMacro("_REENTRANT");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26385.77141.patch
Type: text/x-patch
Size: 3584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161108/c1b0aa5b/attachment.bin>


More information about the cfe-commits mailing list