[flang-commits] [flang] [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. (PR #81222)

Daniel Chen via flang-commits flang-commits at lists.llvm.org
Fri Feb 9 08:12:30 PST 2024


https://github.com/DanielCChen updated https://github.com/llvm/llvm-project/pull/81222

>From 8ce11c21ec1984b9621f616768b943c0e731be78 Mon Sep 17 00:00:00 2001
From: cdchen-ca <cdchen at ca.ibm.com>
Date: Thu, 8 Feb 2024 22:37:31 -0500
Subject: [PATCH] [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.

---
 flang/lib/Frontend/CompilerInvocation.cpp | 13 ++++++++++++-
 flang/module/iso_c_binding.f90            |  4 ++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index ffde7f50087e52..d49e8e283e0d40 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1326,10 +1326,21 @@ 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:
+    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_ptrdiff_t = c_size_t
   integer, parameter, public :: &



More information about the flang-commits mailing list