[flang-commits] [flang] DRAFT: [flang] Warn when F128 is unsupported (PR #102147)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Tue Aug 6 06:59:44 PDT 2024


https://github.com/tblah created https://github.com/llvm/llvm-project/pull/102147

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.

Closes #101207

>From 97dd94cb1a280ff74edc09a0df25cdbf9ca7cf9e Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Mon, 5 Aug 2024 17:28:39 +0000
Subject: [PATCH] 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.
---
 flang/include/flang/Tools/TargetSetup.h | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/flang/include/flang/Tools/TargetSetup.h b/flang/include/flang/Tools/TargetSetup.h
index 238d66c9241dd..90bb45a1effc4 100644
--- a/flang/include/flang/Tools/TargetSetup.h
+++ b/flang/include/flang/Tools/TargetSetup.h
@@ -11,6 +11,7 @@
 
 #include "flang/Evaluate/target.h"
 #include "llvm/Target/TargetMachine.h"
+#include <cfloat>
 
 namespace Fortran::tools {
 
@@ -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);



More information about the flang-commits mailing list