diff options
author | Daniel Chen <cdchen@ca.ibm.com> | 2024-02-13 11:03:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-13 11:03:54 -0500 |
commit | 987258f5c7801ebb4f7ce7c6a035634b275a5759 (patch) | |
tree | 18b73e60c5eb3b371b893a082c8f6ca0fe8de358 | |
parent | 4f13f353cc8dc472a3f00932bc42179776f0f684 (diff) | |
download | llvm-987258f5c7801ebb4f7ce7c6a035634b275a5759.zip llvm-987258f5c7801ebb4f7ce7c6a035634b275a5759.tar.gz llvm-987258f5c7801ebb4f7ce7c6a035634b275a5759.tar.bz2 |
[Flang] Add __powerpc__ macro to set c_intmax_t to c_int64_t rather than c_int128_t as PowerPC only supports up to c_int64_t. (#81222)
PowerPC only supports up to `c_int64_t`. Add macro `__powerpc__` and
preprocess it for setting `c_intmax_t` in `iso_c_binding` intrinsic
module.
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 15 | ||||
-rw-r--r-- | flang/module/iso_c_binding.f90 | 4 | ||||
-rw-r--r-- | flang/test/Driver/predefined-macros-powerpc.f90 | 11 |
3 files changed, 29 insertions, 1 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index ffde7f5..4707de0 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -1326,10 +1326,23 @@ void CompilerInvocation::setDefaultPredefinitions() { Fortran::common::setOpenMPMacro(getLangOpts().OpenMPVersion, fortranOptions.predefinitions); } + llvm::Triple targetTriple{llvm::Triple(this->targetOpts.triple)}; - if (targetTriple.getArch() == llvm::Triple::ArchType::x86_64) { + switch (targetTriple.getArch()) { + default: + break; + case llvm::Triple::ArchType::x86_64: fortranOptions.predefinitions.emplace_back("__x86_64__", "1"); fortranOptions.predefinitions.emplace_back("__x86_64", "1"); + break; + case llvm::Triple::ArchType::ppc: + case llvm::Triple::ArchType::ppcle: + case llvm::Triple::ArchType::ppc64: + case llvm::Triple::ArchType::ppc64le: + // '__powerpc__' is a generic macro for any PowerPC cases. e.g. Max integer + // size. + fortranOptions.predefinitions.emplace_back("__powerpc__", "1"); + break; } } diff --git a/flang/module/iso_c_binding.f90 b/flang/module/iso_c_binding.f90 index 9a7e68f..1661fd5 100644 --- a/flang/module/iso_c_binding.f90 +++ b/flang/module/iso_c_binding.f90 @@ -47,7 +47,11 @@ module iso_c_binding c_long_long = c_int64_t, & c_signed_char = c_int8_t, & c_size_t = kind(c_sizeof(1)), & +#if __powerpc__ + c_intmax_t = c_int64_t, & +#else c_intmax_t = c_int128_t, & +#endif c_intptr_t = c_size_t, & c_ptrdiff_t = c_size_t integer, parameter, public :: & diff --git a/flang/test/Driver/predefined-macros-powerpc.f90 b/flang/test/Driver/predefined-macros-powerpc.f90 new file mode 100644 index 0000000..b3d2b61 --- /dev/null +++ b/flang/test/Driver/predefined-macros-powerpc.f90 @@ -0,0 +1,11 @@ +! Test predefined macro for PowerPC architecture + +! RUN: %flang_fc1 -cpp -E %s | FileCheck %s +! REQUIRES: target=powerpc{{.*}} + +! CHECK: integer :: var1 = 1 + +#if __powerpc__ + integer :: var1 = __powerpc__ +#endif +end program |