Skip to content

Commit 8136ac1

Browse files
authored
[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.
1 parent a9d4ddd commit 8136ac1

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,21 +1333,22 @@ void CompilerInvocation::setDefaultPredefinitions() {
13331333
}
13341334

13351335
llvm::Triple targetTriple{llvm::Triple(this->targetOpts.triple)};
1336+
if (targetTriple.isPPC()) {
1337+
// '__powerpc__' is a generic macro for any PowerPC cases. e.g. Max integer
1338+
// size.
1339+
fortranOptions.predefinitions.emplace_back("__powerpc__", "1");
1340+
}
1341+
if (targetTriple.isOSLinux()) {
1342+
fortranOptions.predefinitions.emplace_back("__linux__", "1");
1343+
}
1344+
13361345
switch (targetTriple.getArch()) {
13371346
default:
13381347
break;
13391348
case llvm::Triple::ArchType::x86_64:
13401349
fortranOptions.predefinitions.emplace_back("__x86_64__", "1");
13411350
fortranOptions.predefinitions.emplace_back("__x86_64", "1");
13421351
break;
1343-
case llvm::Triple::ArchType::ppc:
1344-
case llvm::Triple::ArchType::ppcle:
1345-
case llvm::Triple::ArchType::ppc64:
1346-
case llvm::Triple::ArchType::ppc64le:
1347-
// '__powerpc__' is a generic macro for any PowerPC cases. e.g. Max integer
1348-
// size.
1349-
fortranOptions.predefinitions.emplace_back("__powerpc__", "1");
1350-
break;
13511352
}
13521353
}
13531354

flang/module/iso_c_binding.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,17 @@ module iso_c_binding
5858
c_int_least8_t = c_int8_t, &
5959
c_int_fast8_t = c_int8_t, &
6060
c_int_least16_t = c_int16_t, &
61+
#if defined(__linux__) && defined(__powerpc__)
62+
c_int_fast16_t = c_long, &
63+
#else
6164
c_int_fast16_t = c_int16_t, &
65+
#endif
6266
c_int_least32_t = c_int32_t, &
67+
#if defined(__linux__) && defined(__powerpc__)
68+
c_int_fast32_t = c_long, &
69+
#else
6370
c_int_fast32_t = c_int32_t, &
71+
#endif
6472
c_int_least64_t = c_int64_t, &
6573
c_int_fast64_t = c_int64_t, &
6674
c_int_least128_t = c_int128_t, &
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
! Test predefined macro for PowerPC architecture
2+
3+
! RUN: %flang_fc1 -triple ppc64le-unknown-linux -cpp -E %s | FileCheck %s
4+
! REQUIRES: target=powerpc{{.*}}
5+
6+
! CHECK: integer :: var1 = 1
7+
! CHECK: integer :: var2 = 1
8+
9+
#if defined(__linux__) && defined(__powerpc__)
10+
integer :: var1 = __powerpc__
11+
integer :: var2 = __linux__
12+
#endif
13+
end program

0 commit comments

Comments
 (0)