Skip to content

Commit cde3838

Browse files
authored
[flang][runtime] long double isn't always f80 (#106746)
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).
1 parent a0a2531 commit cde3838

File tree

1 file changed

+12
-1
lines changed
  • flang/include/flang/Optimizer/Builder/Runtime

1 file changed

+12
-1
lines changed

flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,18 @@ constexpr TypeBuilderFunc getModel<const double *>() {
341341
template <>
342342
constexpr TypeBuilderFunc getModel<long double>() {
343343
return [](mlir::MLIRContext *context) -> mlir::Type {
344-
return mlir::FloatType::getF80(context);
344+
// See TODO at the top of the file. This is configuring for the host system
345+
// - it might be incorrect when cross-compiling!
346+
constexpr size_t size = sizeof(long double);
347+
static_assert(size == 16 || size == 10 || size == 8,
348+
"unsupported long double size");
349+
if constexpr (size == 16)
350+
return mlir::FloatType::getF128(context);
351+
if constexpr (size == 10)
352+
return mlir::FloatType::getF80(context);
353+
if constexpr (size == 8)
354+
return mlir::FloatType::getF64(context);
355+
llvm_unreachable("failed static assert");
345356
};
346357
}
347358
template <>

0 commit comments

Comments
 (0)