Hi,
I have a small change to flang/include/flang/Runtime/cpp-type.h that I’d like to upstream and wanted to check if this looks reasonable to the community before filing a review.
Background: HAS_QUADMATHLIB is already used in flang/lib/Evaluate/host.h and flang/lib/Evaluate/intrinsics-library.cpp to enable quadmath-backed constant folding. However, cpp-type.h — which maps Fortran types to C++ types for the runtime — only checks HAS_FLOAT128 and HAS_LDBL128 when deciding whether __float128 / REAL(16) is available, and misses HAS_QUADMATHLIB.
Since HAS_QUADMATHLIB implies __float128 is accessible (quadmath requires it), the fix is to add it to both guards:
-#elif HAS_FLOAT128
+#elif HAS_FLOAT128 || HAS_QUADMATHLIB
using CppFloat128Type = __float128;
#endif
-#if __STDCPP_FLOAT128_t || HAS_LDBL128 || HAS_FLOAT128
+#if __STDCPP_FLOAT128_t || HAS_LDBL128 || HAS_FLOAT128 || HAS_QUADMATHLIB
template <> struct CppTypeForHelper<TypeCategory::Real, 16> {
using type = CppFloat128Type;
};
Without this, building with -DFLANG_RUNTIME_F128_MATH_LIB=libquadmath -DFLANG_INCLUDE_QUADMATH_H=ON produces a runtime that has the quadmath math library wired up but no CppTypeFor<Real, 16> — the type mapping that the rest of the runtime relies on for REAL(16) operations.
Does this look like an appropriate fix? Happy to open a Phabricator/GitHub review if so.
Note on affected platforms: On x86-64 (GCC ≥ 7 / Clang ≥ 7) and PPC (GCC ≥ 8), HAS_FLOAT128 is already set unconditionally, so the missing HAS_QUADMATHLIB is harmless there. The gap is visible on other architectures — we encountered it on RISC-V — where HAS_FLOAT128 is never defined but __float128 becomes available via quadmath.