The AArch32 (32-bit Arm) target always uses the ILP32 data model:
int, long and pointer are all 32 bits wide. However, unlike the
other ILP32 GCC targets (i386 and the AArch64 ILP32 ABI, both of
which define _ILP32 and __ILP32__ in their *-c.cc files), the Arm
backend defined neither macro. This left portable code with no way
to detect the data model on Arm via the standard predefined macros.
Define both _ILP32 and __ILP32__ unconditionally in the Arm C/C++
preprocessor setup, matching i386 and AArch64. __LP64__ remains
undefined, as it must be for a 32-bit data model.
gcc/ChangeLog:
PR target/106930
* config/arm/arm-c.cc (arm_cpu_builtins): Define _ILP32 and
__ILP32__.
gcc/testsuite/ChangeLog:
PR target/106930
* gcc.target/arm/ilp32-macro.c: New test.
Signed-off-by: Dominic P <[email protected]>
---
gcc/config/arm/arm-c.cc | 7 +++++++
gcc/testsuite/gcc.target/arm/ilp32-macro.c | 19 +++++++++++++++++++
2 files changed, 26 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/arm/ilp32-macro.c
diff --git a/gcc/config/arm/arm-c.cc b/gcc/config/arm/arm-c.cc
index aaf75038e..c40564674 100644
--- a/gcc/config/arm/arm-c.cc
+++ b/gcc/config/arm/arm-c.cc
@@ -316,6 +316,13 @@ arm_cpu_builtins (struct cpp_reader* pfile)
builtin_define ("__ARM_ARCH_ISA_ARM");
builtin_define ("__APCS_32__");
+ /* The AArch32 data model is always ILP32: int, long and pointer are
+ all 32 bits wide. Define the standard data-model macros so that code
+ can detect this, matching the other ILP32 targets such as i386 and
+ AArch64's ILP32 ABI. PR target/106930. */
+ builtin_define ("_ILP32");
+ builtin_define ("__ILP32__");
+
def_or_undef_macro (pfile, "__GCC_ASM_FLAG_OUTPUTS__", !TARGET_THUMB1);
def_or_undef_macro (pfile, "__thumb__", TARGET_THUMB);
diff --git a/gcc/testsuite/gcc.target/arm/ilp32-macro.c
b/gcc/testsuite/gcc.target/arm/ilp32-macro.c
new file mode 100644
index 000000000..734f7bd45
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/ilp32-macro.c
@@ -0,0 +1,19 @@
+/* Verify that the ILP32 data-model macros are defined on AArch32, which
+ always uses the ILP32 data model (int, long and pointer are 32 bits),
+ and that the LP64 macro is not defined. PR target/106930. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+#ifndef __ILP32__
+#error __ILP32__ should be defined
+#endif
+
+#ifndef _ILP32
+#error _ILP32 should be defined
+#endif
+
+#ifdef __LP64__
+#error __LP64__ should not be defined
+#endif
+
+int main (void) { return 0; }
--
2.55.0