[flang-commits] [flang] [llvm] [flang] Support REAL(16) through glibc's *f128 entry points (PR #219698)

Dmitry Mikushin via flang-commits flang-commits at lists.llvm.org
Mon Sep 7 16:06:01 PDT 2026


dmikushin wrote:

Good question — they answer different questions, and this PR leaves the `HAS_LDBL128` one alone.

`HAS_LDBL128` is `LDBL_MANT_DIG == 113` (`flang/include/flang/Common/float128.h`): it asks whether `long double` *is* binary128. Where that holds — AArch64, s390x, PPC64 with IEEE long double — `REAL(16)` maps onto `long double` and the math is ordinary libm, which is the `#elif HAS_LDBL128` arm of `math-entries.h` with `std::sin` and friends. Nothing here touches that arm, and on those targets nothing changes.

This route is for the case where that is false — x86-64, where `long double` is the 80-bit type, so `REAL(16)` is `_Float128` and needs a binary128 library of its own. Upstream's only answer there is libquadmath.

The closest existing check is not `HAS_LDBL128` but the one in the trailing `else()` of `flang-rt/lib/quadmath/CMakeLists.txt`: `check_library_exists(m sinf128 "" FOUND_LIBMF128)` → `HAS_LIBMF128`. That detection is already in tree, but the `target_sources` under it is commented out (*"Enable this, when math-entries.h and complex-math.h is ready"*) and `#elif HAS_LIBMF128` in `math-entries.h` is `#error "Float128Math build with glibc>=2.26 is unsupported yet"`. So what was missing was the implementation rather than the detection; this PR supplies it, and makes the route explicitly selectable instead of autodetect-only.

The check itself is a compile test rather than a symbol test because the two disagree exactly where it hurts. On glibc 2.44: `readelf --dyn-syms libm.so.6` lists `sinf128`, `sqrtf128` **and** `cabsf128`, yet `&cabsf128` does not compile in C++ at all — glibc declares the complex `f128` entries for C only — and in C only with `__STDC_WANT_IEC_60559_TYPES_EXT__`. `check_library_exists` therefore passes on a build where every complex entry point fails to compile, which is precisely what the first revision of this PR did on premerge. Hence the test takes the address of one scalar and one complex entry point, and the complex ones are declared explicitly with a `static_assert` on `sizeof == 32`.

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


More information about the flang-commits mailing list