Skip to content

Commit 6398baa

Browse files
authored
[flang] Fixes for LIT testing of FLANG_RUNTIME_F128_MATH_LIB build. (#82832)
Follow-up for #81971 to fix the disabled LIT test and add LIT tests for lowering of the added math intrinsics.
1 parent dc06d75 commit 6398baa

File tree

8 files changed

+80
-24
lines changed

8 files changed

+80
-24
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,13 +1316,16 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
13161316
// add the correct libraries to link against as dependents in the object
13171317
// file.
13181318
if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
1319-
StringRef f128LibName = TC.getDriver().getFlangF128MathLibrary();
1320-
f128LibName.consume_front_insensitive("lib");
1321-
if (!f128LibName.empty()) {
1319+
StringRef F128LibName = TC.getDriver().getFlangF128MathLibrary();
1320+
F128LibName.consume_front_insensitive("lib");
1321+
if (!F128LibName.empty()) {
1322+
bool AsNeeded = !TC.getTriple().isOSAIX();
13221323
CmdArgs.push_back("-lFortranFloat128Math");
1323-
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/true);
1324-
CmdArgs.push_back(Args.MakeArgString("-l" + f128LibName));
1325-
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
1324+
if (AsNeeded)
1325+
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/true);
1326+
CmdArgs.push_back(Args.MakeArgString("-l" + F128LibName));
1327+
if (AsNeeded)
1328+
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
13261329
}
13271330
CmdArgs.push_back("-lFortranRuntime");
13281331
CmdArgs.push_back("-lFortranDecimal");

flang/test/Driver/linker-flags.f90

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
! invocation. These libraries are added on top of other standard runtime
33
! libraries that the Clang driver will include.
44

5-
! RUN: %flang -### --target=ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX
6-
! RUN: %flang -### --target=aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN
7-
! RUN: %flang -### --target=sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX
8-
! RUN: %flang -### --target=x86_64-unknown-freebsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX
9-
! RUN: %flang -### --target=x86_64-unknown-netbsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX
10-
! RUN: %flang -### --target=x86_64-unknown-openbsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX
11-
! RUN: %flang -### --target=x86_64-unknown-dragonfly %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX
12-
! RUN: %flang -### --target=x86_64-unknown-haiku %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,HAIKU
13-
! RUN: %flang -### --target=x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MINGW
5+
! RUN: %flang -### --target=ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib
6+
! RUN: %flang -### --target=aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN,DARWIN-F128%f128-lib
7+
! RUN: %flang -### --target=sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,SOLARIS-F128%f128-lib
8+
! RUN: %flang -### --target=x86_64-unknown-freebsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib
9+
! RUN: %flang -### --target=x86_64-unknown-netbsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib
10+
! RUN: %flang -### --target=x86_64-unknown-openbsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib
11+
! RUN: %flang -### --target=x86_64-unknown-dragonfly %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib
12+
! RUN: %flang -### --target=x86_64-unknown-haiku %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,HAIKU,HAIKU-F128%f128-lib
13+
! RUN: %flang -### --target=x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MINGW,MINGW-F128%f128-lib
1414
! RUN: %flang -### --target=aarch64-unknown-linux-gnu %S/Inputs/hello.f90 -lFortran_main 2>&1 | FileCheck %s --check-prefixes=DEPRECATED
1515

1616
! NOTE: Clang's driver library, clangDriver, usually adds 'oldnames' on Windows,
@@ -29,21 +29,33 @@
2929
! executable and may find the GNU linker from MinGW or Cygwin.
3030
! UNIX-LABEL: "{{.*}}ld{{(\.exe)?}}"
3131
! UNIX-SAME: "[[object_file]]"
32-
! UNIX-SAME: "--whole-archive" "-lFortran_main" "--no-whole-archive" "-lFortranRuntime" "-lFortranDecimal" "-lm"
32+
! UNIX-SAME: "--whole-archive" "-lFortran_main" "--no-whole-archive"
33+
! UNIX-F128NONE-NOT: FortranFloat128Math
34+
! SOLARIS-F128NONE-NOT: FortranFloat128Math
35+
! UNIX-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
36+
! SOLARIS-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "-z" "ignore" "-lquadmath" "-z" "record"
37+
! UNIX-SAME: "-lFortranRuntime" "-lFortranDecimal" "-lm"
3338

3439
! DARWIN-LABEL: "{{.*}}ld{{(\.exe)?}}"
3540
! DARWIN-SAME: "[[object_file]]"
3641
! DARWIN-SAME: -lFortran_main
42+
! DARWIN-F128NONE-NOT: FortranFloat128Math
43+
! DARWIN-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
3744
! DARWIN-SAME: -lFortranRuntime
3845
! DARWIN-SAME: -lFortranDecimal
3946

4047
! HAIKU-LABEL: "{{.*}}ld{{(\.exe)?}}"
4148
! HAIKU-SAME: "[[object_file]]"
42-
! HAIKU-SAME: "--whole-archive" "-lFortran_main" "--no-whole-archive" "-lFortranRuntime" "-lFortranDecimal"
49+
! HAIKU-SAME: "--whole-archive" "-lFortran_main" "--no-whole-archive"
50+
! HAIKU-F128NONE-NOT: FortranFloat128Math
51+
! HAIKU-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
52+
! HAIKU-SAME: "-lFortranRuntime" "-lFortranDecimal"
4353

4454
! MINGW-LABEL: "{{.*}}ld{{(\.exe)?}}"
4555
! MINGW-SAME: "[[object_file]]"
4656
! MINGW-SAME: -lFortran_main
57+
! MINGW-F128NONE-NOT: FortranFloat128Math
58+
! MINGW-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
4759
! MINGW-SAME: -lFortranRuntime
4860
! MINGW-SAME: -lFortranDecimal
4961

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! REQUIRES: flang-supports-f128-math
2+
! RUN: bbc -emit-fir %s -o - | FileCheck %s
3+
! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck %s
4+
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
5+
6+
! CHECK: fir.call @_FortranACAbsF128({{.*}}){{.*}}: (!fir.complex<16>) -> f128
7+
complex(16) :: a
8+
real(16) :: b
9+
b = abs(a)
10+
end

flang/test/Lower/Intrinsics/missing-math-runtime.f90

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
! There is no quad math runtime available in lowering
2-
! for now. Test that the TODO are emitted correctly.
3-
! FIXME: the lit config has to flip a feature flag so that
4-
! the tests can use different checks depending on whether
5-
! REAL(16) math support is enabled or not.
6-
! XFAIL: *
7-
! RUN: bbc -emit-fir %s -o /dev/null 2>&1 | FileCheck %s
1+
! If the compiler is built without 128-bit float math
2+
! support, an appropriate error message is emitted.
3+
! UNSUPPORTED: flang-supports-f128-math
4+
! RUN: bbc -emit-fir %s -o /dev/null >%t 2>&1 || echo
5+
! RUN: FileCheck %s --input-file=%t
86

97
complex(16) :: a
108
real(16) :: b
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
! REQUIRES: flang-supports-f128-math
2+
! RUN: bbc -emit-fir %s -o - | FileCheck %s
3+
! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck %s
4+
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
5+
6+
! CHECK: fir.call @_FortranASinF128({{.*}}){{.*}}: (f128) -> f128
7+
real(16) :: a, b
8+
b = sin(a)
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
! REQUIRES: flang-supports-f128-math
2+
! RUN: bbc -emit-fir %s -o - | FileCheck %s
3+
! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck %s
4+
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
5+
6+
! CHECK: fir.call @_FortranASqrtF128({{.*}}){{.*}}: (f128) -> f128
7+
real(16) :: a, b
8+
b = sqrt(a)
9+
end

flang/test/lit.cfg.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,17 @@
199199
result = lit_config.params.get("LIBPGMATH")
200200
if result:
201201
config.environment["LIBPGMATH"] = True
202+
203+
# Add features and substitutions to test F128 math support.
204+
# %f128-lib substitution may be used to generate check prefixes
205+
# for LIT tests checking for F128 library support.
206+
if config.flang_runtime_f128_math_lib:
207+
config.available_features.add("flang-supports-f128-math")
208+
config.available_features.add(
209+
"flang-f128-math-lib-" + config.flang_runtime_f128_math_lib
210+
)
211+
config.substitutions.append(
212+
("%f128-lib", config.flang_runtime_f128_math_lib.upper())
213+
)
214+
else:
215+
config.substitutions.append(("%f128-lib", "NONE"))

flang/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ config.cc = "@CMAKE_C_COMPILER@"
2525
config.osx_sysroot = path(r"@CMAKE_OSX_SYSROOT@")
2626
config.targets_to_build = "@TARGETS_TO_BUILD@"
2727
config.default_sysroot = "@DEFAULT_SYSROOT@"
28+
config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@"
2829

2930
import lit.llvm
3031
lit.llvm.initialize(lit_config, config)

0 commit comments

Comments
 (0)