Skip to content

Commit

Permalink
WIP: [flang] Warn when F128 is unsupported
Browse files Browse the repository at this point in the history
This generates `warning: REAL(KIND=16) is not an enabled type for this target`
if that type is used in a build not correctly configured to support this type.
Uses of `selected_real_kind(30)` return -1.

The added braces to the previous if statement are so that clang-format
does not try to indent the new comment. Even if the clang-format off
directive is moved to the start, that comment still gets indented so it
looks weird. I chose to disable clang-format for the preprocessor block
to allow the nested if statement to be indented for clarity.

Note: some lit tests will fail on systems not configured to support
f128. I'll update them once we are settled on what the right error
message is.
  • Loading branch information
tblah committed Aug 6, 2024
1 parent f231d3d commit 97dd94c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion flang/include/flang/Tools/TargetSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "flang/Evaluate/target.h"
#include "llvm/Target/TargetMachine.h"
#include <cfloat>

namespace Fortran::tools {

Expand All @@ -21,9 +22,29 @@ namespace Fortran::tools {

const llvm::Triple &targetTriple{targetMachine.getTargetTriple()};
// FIXME: Handle real(3) ?
if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64)
if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64) {
targetCharacteristics.DisableType(
Fortran::common::TypeCategory::Real, /*kind=*/10);
}

// Figure out if we can support F128: see
// flang/runtime/Float128Math/math-entries.h
// clang-format off
#ifdef FLANG_RUNTIME_F128_MATH_LIB
// we can use libquadmath wrappers
constexpr bool f128Support = true;
#else
#if LDBL_MANT_DIG == 113
// we can use libm wrappers
constexpr bool f128Support = true;
#else
constexpr bool f128Support = false;
#endif // LDBL_MANT_DIG
#endif // FLANG_RUNTIME_F128_MATH_LIB
// clang-format on

if constexpr (!f128Support)
targetCharacteristics.DisableType(Fortran::common::TypeCategory::Real, 16);

targetCharacteristics.set_compilerOptionsString(compilerOptions)
.set_compilerVersionString(compilerVersion);
Expand Down

0 comments on commit 97dd94c

Please sign in to comment.