[clang] d2e949e - [AArch64] Predefine __AARCH64_CMODEL_*__ as GCC does
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 23:28:07 PST 2020
Author: Roland McGrath
Date: 2020-02-21T23:27:36-08:00
New Revision: d2e949eed5b49ca70a8845dfaf7bac6ca40c429d
URL: https://github.com/llvm/llvm-project/commit/d2e949eed5b49ca70a8845dfaf7bac6ca40c429d
DIFF: https://github.com/llvm/llvm-project/commit/d2e949eed5b49ca70a8845dfaf7bac6ca40c429d.diff
LOG: [AArch64] Predefine __AARCH64_CMODEL_*__ as GCC does
Make Clang on aarch64 targets predefine `__AARCH64_CMODEL_SMALL__`
or `__AARCH64_CMODEL_TINY__`, etc. These are the names that GCC
uses for its predefines.
Reviewed By: tamur, MaskRay
Differential Revision: https://reviews.llvm.org/D75002
Added:
Modified:
clang/lib/Basic/Targets/AArch64.cpp
clang/test/Preprocessor/init-aarch64.c
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index cba3e3ada7ea..bd1a8834c2fa 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -194,6 +194,13 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__LP64__");
}
+ std::string CodeModel = getTargetOpts().CodeModel;
+ if (CodeModel == "default")
+ CodeModel = "small";
+ for (char &c : CodeModel)
+ c = toupper(c);
+ Builder.defineMacro("__AARCH64_CMODEL_" + CodeModel + "__");
+
// ACLE predefines. Many can only have one possible value on v8 AArch64.
Builder.defineMacro("__ARM_ACLE", "200");
Builder.defineMacro("__ARM_ARCH", "8");
diff --git a/clang/test/Preprocessor/init-aarch64.c b/clang/test/Preprocessor/init-aarch64.c
index ce769f7ac4e7..380e5e2d7261 100644
--- a/clang/test/Preprocessor/init-aarch64.c
+++ b/clang/test/Preprocessor/init-aarch64.c
@@ -7,8 +7,10 @@
// AARCH64: #define _LP64 1
// AARCH64_BE-NEXT: #define __AARCH64EB__ 1
+// AARCH64_BE-NEXT: #define __AARCH64_CMODEL_SMALL__ 1
// AARCH64_BE-NEXT: #define __AARCH_BIG_ENDIAN 1
// AARCH64_LE-NEXT: #define __AARCH64EL__ 1
+// AARCH64_LE-NEXT: #define __AARCH64_CMODEL_SMALL__ 1
// AARCH64-NEXT: #define __ARM_64BIT_STATE 1
// AARCH64-NEXT: #define __ARM_ACLE 200
// AARCH64-NEXT: #define __ARM_ALIGN_MAX_STACK_PWR 4
@@ -689,3 +691,11 @@
// AARCH64-MSVC: #define __WINT_TYPE__ unsigned short
// AARCH64-MSVC: #define __WINT_WIDTH__ 16
// AARCH64-MSVC: #define __aarch64__ 1
+
+// RUN: %clang_cc1 -triple=aarch64 -E -dM -mcmodel=small -xc /dev/null | FileCheck --check-prefix=CMODEL_SMALL %s
+// RUN: %clang_cc1 -triple=aarch64 -E -dM -mcmodel=tiny -xc /dev/null | FileCheck --check-prefix=CMODEL_TINY %s
+// RUN: %clang_cc1 -triple=aarch64 -E -dM -mcmodel=large -xc /dev/null | FileCheck --check-prefix=CMODEL_LARGE %s
+
+// CMODEL_TINY: #define __AARCH64_CMODEL_TINY__ 1
+// CMODEL_SMALL: #define __AARCH64_CMODEL_SMALL__ 1
+// CMODEL_LARGE: #define __AARCH64_CMODEL_LARGE__ 1
More information about the cfe-commits
mailing list