[flang-commits] [flang] 987258f - [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)
via flang-commits
flang-commits at lists.llvm.org
Tue Feb 13 08:03:57 PST 2024
Author: Daniel Chen
Date: 2024-02-13T11:03:54-05:00
New Revision: 987258f5c7801ebb4f7ce7c6a035634b275a5759
URL: https://github.com/llvm/llvm-project/commit/987258f5c7801ebb4f7ce7c6a035634b275a5759
DIFF: https://github.com/llvm/llvm-project/commit/987258f5c7801ebb4f7ce7c6a035634b275a5759.diff
LOG: [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.
Added:
flang/test/Driver/predefined-macros-powerpc.f90
Modified:
flang/lib/Frontend/CompilerInvocation.cpp
flang/module/iso_c_binding.f90
Removed:
################################################################################
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index ffde7f50087e52..4707de0e976ca7 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 9a7e68f3314463..1661fd5a6dcf6a 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_ptr
diff _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 00000000000000..b3d2b617fb1fad
--- /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
More information about the flang-commits
mailing list