Skip to content

Commit a89d8ff

Browse files
committed
Define __ANDROID_API__ when specified as part of an Android target.
Summary: This macro should be defined only when the user directly specifies an API level as part of an Android target. For any regular Android target, we leave this macro undefined. Bug: https://llvm.org/bugs/show_bug.cgi?id=30940 Reviewers: eugenis, pirama Subscribers: tberghammer, cfe-commits, pirama, eugenis, danalbert Differential Revision: https://reviews.llvm.org/D26491 llvm-svn: 286543
1 parent bd1ee48 commit a89d8ff

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ class LinuxTargetInfo : public OSTargetInfo<Target> {
465465
Triple.getEnvironmentVersion(Maj, Min, Rev);
466466
this->PlatformName = "android";
467467
this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
468+
if (Maj)
469+
Builder.defineMacro("__ANDROID_API__", Twine(Maj));
468470
}
469471
if (Opts.POSIXThreads)
470472
Builder.defineMacro("_REENTRANT");

clang/test/Preprocessor/init.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8497,6 +8497,7 @@
84978497
// NORTTI:#define __STDC__ 1
84988498
//
84998499
// RUN: %clang_cc1 -triple arm-linux-androideabi -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix ANDROID %s
8500+
// ANDROID-NOT:#define __ANDROID_API__
85008501
// ANDROID:#define __ANDROID__ 1
85018502
//
85028503
// RUN: %clang_cc1 -x c++ -triple i686-linux-android -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix I386-ANDROID-CXX %s
@@ -8505,6 +8506,10 @@
85058506
// RUN: %clang_cc1 -x c++ -triple x86_64-linux-android -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix X86_64-ANDROID-CXX %s
85068507
// X86_64-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
85078508
//
8509+
// RUN: %clang_cc1 -triple arm-linux-androideabi20 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix ANDROID20 %s
8510+
// ANDROID20:#define __ANDROID_API__ 20
8511+
// ANDROID20:#define __ANDROID__ 1
8512+
//
85088513
// RUN: %clang_cc1 -triple lanai-unknown-unknown -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix LANAI %s
85098514
// LANAI: #define __lanai__ 1
85108515
//

0 commit comments

Comments
 (0)