Author: srhines Date: Tue Nov 8 15:23:26 2016 New Revision: 286295 URL: http://llvm.org/viewvc/llvm-project?rev=286295&view=rev Log: Define __ANDROID_API__ for all Android builds.
Summary: 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. Reviewers: danalbert, eugenis Subscribers: cfe-commits, pirama, eugenis, tberghammer, danalbert Differential Revision: https://reviews.llvm.org/D26385 Added: cfe/trunk/test/Driver/android-targets.cpp Modified: cfe/trunk/lib/Basic/Targets.cpp Modified: cfe/trunk/lib/Basic/Targets.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=286295&r1=286294&r2=286295&view=diff ============================================================================== --- cfe/trunk/lib/Basic/Targets.cpp (original) +++ cfe/trunk/lib/Basic/Targets.cpp Tue Nov 8 15:23:26 2016 @@ -465,6 +465,8 @@ protected: Triple.getEnvironmentVersion(Maj, Min, Rev); this->PlatformName = "android"; this->PlatformMinVersion = VersionTuple(Maj, Min, Rev); + if (Maj) + Builder.defineMacro("__ANDROID_API__", Twine(Maj)); } if (Opts.POSIXThreads) Builder.defineMacro("_REENTRANT"); Added: cfe/trunk/test/Driver/android-targets.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/android-targets.cpp?rev=286295&view=auto ============================================================================== --- cfe/trunk/test/Driver/android-targets.cpp (added) +++ cfe/trunk/test/Driver/android-targets.cpp Tue Nov 8 15:23:26 2016 @@ -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-NOT: __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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits