Skip to content

Commit 987258f

Browse files
authored
[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.
1 parent 4f13f35 commit 987258f

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,10 +1326,23 @@ void CompilerInvocation::setDefaultPredefinitions() {
13261326
Fortran::common::setOpenMPMacro(getLangOpts().OpenMPVersion,
13271327
fortranOptions.predefinitions);
13281328
}
1329+
13291330
llvm::Triple targetTriple{llvm::Triple(this->targetOpts.triple)};
1330-
if (targetTriple.getArch() == llvm::Triple::ArchType::x86_64) {
1331+
switch (targetTriple.getArch()) {
1332+
default:
1333+
break;
1334+
case llvm::Triple::ArchType::x86_64:
13311335
fortranOptions.predefinitions.emplace_back("__x86_64__", "1");
13321336
fortranOptions.predefinitions.emplace_back("__x86_64", "1");
1337+
break;
1338+
case llvm::Triple::ArchType::ppc:
1339+
case llvm::Triple::ArchType::ppcle:
1340+
case llvm::Triple::ArchType::ppc64:
1341+
case llvm::Triple::ArchType::ppc64le:
1342+
// '__powerpc__' is a generic macro for any PowerPC cases. e.g. Max integer
1343+
// size.
1344+
fortranOptions.predefinitions.emplace_back("__powerpc__", "1");
1345+
break;
13331346
}
13341347
}
13351348

flang/module/iso_c_binding.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ module iso_c_binding
4747
c_long_long = c_int64_t, &
4848
c_signed_char = c_int8_t, &
4949
c_size_t = kind(c_sizeof(1)), &
50+
#if __powerpc__
51+
c_intmax_t = c_int64_t, &
52+
#else
5053
c_intmax_t = c_int128_t, &
54+
#endif
5155
c_intptr_t = c_size_t, &
5256
c_ptrdiff_t = c_size_t
5357
integer, parameter, public :: &
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! Test predefined macro for PowerPC architecture
2+
3+
! RUN: %flang_fc1 -cpp -E %s | FileCheck %s
4+
! REQUIRES: target=powerpc{{.*}}
5+
6+
! CHECK: integer :: var1 = 1
7+
8+
#if __powerpc__
9+
integer :: var1 = __powerpc__
10+
#endif
11+
end program

0 commit comments

Comments
 (0)