[flang-commits] [flang] [flang][runtime] long double isn't always f80 (PR #106746)

via flang-commits flang-commits at lists.llvm.org
Fri Aug 30 08:02:53 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: Tom Eccles (tblah)

<details>
<summary>Changes</summary>

f80 is only a thing on x86, and even then the size of long double can be changed with compiler flags. Instead set the size according to the host system (this is what is already done for integer types).

---

I spotted this while reading some code and thought it looked like a bug. Please let me know if I misunderstood.

---
Full diff: https://github.com/llvm/llvm-project/pull/106746.diff


1 Files Affected:

- (modified) flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h (+12-1) 


``````````diff
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index 845ba385918d0d..a103861f1510b8 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -341,7 +341,18 @@ constexpr TypeBuilderFunc getModel<const double *>() {
 template <>
 constexpr TypeBuilderFunc getModel<long double>() {
   return [](mlir::MLIRContext *context) -> mlir::Type {
-    return mlir::FloatType::getF80(context);
+    // See TODO at the top of the file. This is configuring for the host system
+    // - it might be incorrect when cross-compiling!
+    constexpr size_t size = sizeof(long double);
+    static_assert(size == 16 || size == 10 || size == 8,
+                  "unsupported long double size");
+    if constexpr (size == 16)
+      return mlir::FloatType::getF128(context);
+    if constexpr (size == 10)
+      return mlir::FloatType::getF80(context);
+    if constexpr (size == 8)
+      return mlir::FloatType::getF64(context);
+    llvm_unreachable("failed static assert");
   };
 }
 template <>

``````````

</details>


https://github.com/llvm/llvm-project/pull/106746


More information about the flang-commits mailing list