Skip to content

[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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 4 additions & 0 deletions flang/module/iso_c_binding.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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 :: &
Expand Down
11 changes: 11 additions & 0 deletions flang/test/Driver/predefined-macros-powerpc.f90
Original file line number Diff line number Diff line change
@@ -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