Skip to content

Commit b52dc20

Browse files
committed
WIP: [flang] Warn when F128 is unsupported
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.
1 parent d43a809 commit b52dc20

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

flang/include/flang/Tools/TargetSetup.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "flang/Evaluate/target.h"
1313
#include "llvm/Target/TargetMachine.h"
14+
#include <cfloat>
1415

1516
namespace Fortran::tools {
1617

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

2223
const llvm::Triple &targetTriple{targetMachine.getTargetTriple()};
2324
// FIXME: Handle real(3) ?
24-
if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64)
25+
if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64) {
2526
targetCharacteristics.DisableType(
2627
Fortran::common::TypeCategory::Real, /*kind=*/10);
28+
}
29+
30+
// Figure out if we can support F128: see
31+
// flang/runtime/Float128Math/math-entries.h
32+
// clang-format off
33+
#ifdef FLANG_RUNTIME_F128_MATH_LIB
34+
// we can use libquadmath wrappers
35+
constexpr bool f128Support = true;
36+
#else
37+
#if LDBL_MANT_DIG == 113
38+
// we can use libm wrappers
39+
constexpr bool f128Support = true;
40+
#else
41+
constexpr bool f128Support = false;
42+
#endif // LDBL_MANT_DIG
43+
#endif // FLANG_RUNTIME_F128_MATH_LIB
44+
// clang-format on
45+
46+
if constexpr (!f128Support)
47+
targetCharacteristics.DisableType(Fortran::common::TypeCategory::Real, 16);
2748

2849
targetCharacteristics.set_compilerOptionsString(compilerOptions)
2950
.set_compilerVersionString(compilerVersion);

0 commit comments

Comments
 (0)