Skip to content

Commit 45c6d0d

Browse files
Meinersburronlieb
authored andcommitted
[Flang-RT] Environment introspection for quadmath.h (llvm#130411)
When compiling Flang-RT with Clang, query Clang for the GCC installation it uses. If found, create `quadmath_wrapper.h` that points to the `quadmath.h` of that GCC installation. `quadmath.h` is only available when compiling with gcc, and Clang has no equivalent even though gcc's version compiles fine with Clang (at least up to and including gcc 13). It is still available into gcc's installation resource dir (in constrast to a system-wide indirectory such as `/usr/include` or `/usr/local/include`) and therefore not available to any compiler other than the gcc of that installation. quadmath may also be a different OS package than gcc itself, so it is not necessarily presesent. Clang actually already appropriates a GCC installation for its libraries such that `libquadmath.a` is already found, but it does not do so for the include paths. Because adding that directory to the header search path may have wide-reaching consquences, we create only a wrapper header that points to the real `quadmath.h` in the same GCC installation that Clang uses.
1 parent 2e92145 commit 45c6d0d

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

flang-rt/CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,14 @@ elseif (FLANG_RT_GCC_RESOURCE_DIR)
294294
endif ()
295295

296296
# Check if 128-bit float computations can be done via long double.
297-
check_cxx_source_compiles(
298-
"#include <cfloat>
299-
#if LDBL_MANT_DIG != 113
300-
#error LDBL_MANT_DIG != 113
301-
#endif
302-
int main() { return 0; }
303-
"
304-
HAVE_LDBL_MANT_DIG_113)
297+
#check_cxx_source_compiles(
298+
# "#include <cfloat>
299+
# #if LDBL_MANT_DIG != 113
300+
# #error LDBL_MANT_DIG != 113
301+
# #endif
302+
# int main() { return 0; }
303+
# "
304+
# HAVE_LDBL_MANT_DIG_113)
305305

306306

307307
#####################
@@ -325,7 +325,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES)
325325

326326

327327
configure_file(cmake/config.h.cmake.in config.h)
328-
328+
if (FLANG_RT_INCLUDE_QUADMATH_H)
329+
configure_file("cmake/quadmath_wrapper.h.in" "${FLANG_RT_BINARY_DIR}/quadmath_wrapper.h")
330+
endif ()
329331

330332
# The bootstrap build will create a phony target with the same as the top-level
331333
# directory ("flang-rt") and delegate it to the runtimes build dir.

flang-rt/cmake/clang_gcc_root.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int main() { return 0; }

flang-rt/cmake/quadmath_wrapper.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*===-- cmake/quadmath_wrapper.h.in ---------------------=-----------*- C -*-===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===----------------------------------------------------------------------===*/
8+
9+
#include ${FLANG_RT_INCLUDE_QUADMATH_H}

flang-rt/lib/quadmath/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ target_include_directories(FortranFloat128MathILib INTERFACE
7878

7979
if (FLANG_RUNTIME_F128_MATH_LIB)
8080
if (${FLANG_RUNTIME_F128_MATH_LIB} STREQUAL "libquadmath")
81-
check_include_file(quadmath.h FOUND_QUADMATH_HEADER)
82-
if(FOUND_QUADMATH_HEADER)
81+
if(FLANG_RT_INCLUDE_QUADMATH_H)
8382
add_compile_definitions(HAS_QUADMATHLIB)
8483
else()
8584
message(FATAL_ERROR

flang-rt/lib/quadmath/complex-math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "flang/Runtime/entry-names.h"
1414

1515
#if HAS_QUADMATHLIB
16-
#include "quadmath.h"
16+
#include "quadmath_wrapper.h"
1717
#define CAbs(x) cabsq(x)
1818
#define CAcos(x) cacosq(x)
1919
#define CAcosh(x) cacoshq(x)

flang-rt/lib/quadmath/math-entries.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ DEFINE_FALLBACK_F128(Yn)
112112

113113
#if HAS_QUADMATHLIB
114114
// Define wrapper callers for libquadmath.
115-
#include "quadmath.h"
115+
#include "quadmath_wrapper.h"
116116
DEFINE_SIMPLE_ALIAS(Abs, fabsq)
117117
DEFINE_SIMPLE_ALIAS(Acos, acosq)
118118
DEFINE_SIMPLE_ALIAS(Acosh, acoshq)

0 commit comments

Comments
 (0)