aboutsummaryrefslogtreecommitdiff
path: root/flang
diff options
context:
space:
mode:
authorDaniel Chen <cdchen@ca.ibm.com>2024-04-10 19:22:38 -0400
committerGitHub <noreply@github.com>2024-04-10 19:22:38 -0400
commit8136ac1c42dcfdd070f0bcba0f06424093df22db (patch)
treea4034f35f98e666d9763473ec3443ed840778077 /flang
parenta9d4ddd98a0bc495126027122fdca751b6841ceb (diff)
downloadllvm-8136ac1c42dcfdd070f0bcba0f06424093df22db.zip
llvm-8136ac1c42dcfdd070f0bcba0f06424093df22db.tar.gz
llvm-8136ac1c42dcfdd070f0bcba0f06424093df22db.tar.bz2
[Flang] Define c_int_fast16_t and c_int_fast32_t for PowerPC. (#88292)
On Linux, PowerPC defines `int_fast16_t` and `int_fast32_t` as `long`. Need to update the corresponding type, `c_int_fast16_t` and `c_int_fast32_t` in `iso_c_binding` module so they are interoparable.
Diffstat (limited to 'flang')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp17
-rw-r--r--flang/module/iso_c_binding.f908
-rw-r--r--flang/test/Driver/predefined-macros-powerpc2.f9013
3 files changed, 30 insertions, 8 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 8ce6ab7..e432c5a 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1333,6 +1333,15 @@ void CompilerInvocation::setDefaultPredefinitions() {
}
llvm::Triple targetTriple{llvm::Triple(this->targetOpts.triple)};
+ if (targetTriple.isPPC()) {
+ // '__powerpc__' is a generic macro for any PowerPC cases. e.g. Max integer
+ // size.
+ fortranOptions.predefinitions.emplace_back("__powerpc__", "1");
+ }
+ if (targetTriple.isOSLinux()) {
+ fortranOptions.predefinitions.emplace_back("__linux__", "1");
+ }
+
switch (targetTriple.getArch()) {
default:
break;
@@ -1340,14 +1349,6 @@ void CompilerInvocation::setDefaultPredefinitions() {
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 1661fd5..eb0f8f2 100644
--- a/flang/module/iso_c_binding.f90
+++ b/flang/module/iso_c_binding.f90
@@ -58,9 +58,17 @@ module iso_c_binding
c_int_least8_t = c_int8_t, &
c_int_fast8_t = c_int8_t, &
c_int_least16_t = c_int16_t, &
+#if defined(__linux__) && defined(__powerpc__)
+ c_int_fast16_t = c_long, &
+#else
c_int_fast16_t = c_int16_t, &
+#endif
c_int_least32_t = c_int32_t, &
+#if defined(__linux__) && defined(__powerpc__)
+ c_int_fast32_t = c_long, &
+#else
c_int_fast32_t = c_int32_t, &
+#endif
c_int_least64_t = c_int64_t, &
c_int_fast64_t = c_int64_t, &
c_int_least128_t = c_int128_t, &
diff --git a/flang/test/Driver/predefined-macros-powerpc2.f90 b/flang/test/Driver/predefined-macros-powerpc2.f90
new file mode 100644
index 0000000..6e10235
--- /dev/null
+++ b/flang/test/Driver/predefined-macros-powerpc2.f90
@@ -0,0 +1,13 @@
+! Test predefined macro for PowerPC architecture
+
+! RUN: %flang_fc1 -triple ppc64le-unknown-linux -cpp -E %s | FileCheck %s
+! REQUIRES: target=powerpc{{.*}}
+
+! CHECK: integer :: var1 = 1
+! CHECK: integer :: var2 = 1
+
+#if defined(__linux__) && defined(__powerpc__)
+ integer :: var1 = __powerpc__
+ integer :: var2 = __linux__
+#endif
+end program