Skip to content

Commit

Permalink
[flang] Fixes for LIT testing of FLANG_RUNTIME_F128_MATH_LIB build. (#…
Browse files Browse the repository at this point in the history
…82832)

Follow-up for #81971 to fix the disabled LIT test and add
LIT tests for lowering of the added math intrinsics.
  • Loading branch information
vzakhari committed Feb 26, 2024
1 parent dc06d75 commit 6398baa
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 24 deletions.
15 changes: 9 additions & 6 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,13 +1316,16 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
// add the correct libraries to link against as dependents in the object
// file.
if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
StringRef f128LibName = TC.getDriver().getFlangF128MathLibrary();
f128LibName.consume_front_insensitive("lib");
if (!f128LibName.empty()) {
StringRef F128LibName = TC.getDriver().getFlangF128MathLibrary();
F128LibName.consume_front_insensitive("lib");
if (!F128LibName.empty()) {
bool AsNeeded = !TC.getTriple().isOSAIX();
CmdArgs.push_back("-lFortranFloat128Math");
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/true);
CmdArgs.push_back(Args.MakeArgString("-l" + f128LibName));
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
if (AsNeeded)
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/true);
CmdArgs.push_back(Args.MakeArgString("-l" + F128LibName));
if (AsNeeded)
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
}
CmdArgs.push_back("-lFortranRuntime");
CmdArgs.push_back("-lFortranDecimal");
Expand Down
34 changes: 23 additions & 11 deletions flang/test/Driver/linker-flags.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
! invocation. These libraries are added on top of other standard runtime
! libraries that the Clang driver will include.

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

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

! DARWIN-LABEL: "{{.*}}ld{{(\.exe)?}}"
! DARWIN-SAME: "[[object_file]]"
! DARWIN-SAME: -lFortran_main
! DARWIN-F128NONE-NOT: FortranFloat128Math
! DARWIN-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
! DARWIN-SAME: -lFortranRuntime
! DARWIN-SAME: -lFortranDecimal

! HAIKU-LABEL: "{{.*}}ld{{(\.exe)?}}"
! HAIKU-SAME: "[[object_file]]"
! HAIKU-SAME: "--whole-archive" "-lFortran_main" "--no-whole-archive" "-lFortranRuntime" "-lFortranDecimal"
! HAIKU-SAME: "--whole-archive" "-lFortran_main" "--no-whole-archive"
! HAIKU-F128NONE-NOT: FortranFloat128Math
! HAIKU-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
! HAIKU-SAME: "-lFortranRuntime" "-lFortranDecimal"

! MINGW-LABEL: "{{.*}}ld{{(\.exe)?}}"
! MINGW-SAME: "[[object_file]]"
! MINGW-SAME: -lFortran_main
! MINGW-F128NONE-NOT: FortranFloat128Math
! MINGW-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
! MINGW-SAME: -lFortranRuntime
! MINGW-SAME: -lFortranDecimal

Expand Down
10 changes: 10 additions & 0 deletions flang/test/Lower/Intrinsics/cabs_real16.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
! REQUIRES: flang-supports-f128-math
! RUN: bbc -emit-fir %s -o - | FileCheck %s
! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck %s
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s

! CHECK: fir.call @_FortranACAbsF128({{.*}}){{.*}}: (!fir.complex<16>) -> f128
complex(16) :: a
real(16) :: b
b = abs(a)
end
12 changes: 5 additions & 7 deletions flang/test/Lower/Intrinsics/missing-math-runtime.f90
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
! There is no quad math runtime available in lowering
! for now. Test that the TODO are emitted correctly.
! FIXME: the lit config has to flip a feature flag so that
! the tests can use different checks depending on whether
! REAL(16) math support is enabled or not.
! XFAIL: *
! RUN: bbc -emit-fir %s -o /dev/null 2>&1 | FileCheck %s
! If the compiler is built without 128-bit float math
! support, an appropriate error message is emitted.
! UNSUPPORTED: flang-supports-f128-math
! RUN: bbc -emit-fir %s -o /dev/null >%t 2>&1 || echo
! RUN: FileCheck %s --input-file=%t

complex(16) :: a
real(16) :: b
Expand Down
9 changes: 9 additions & 0 deletions flang/test/Lower/Intrinsics/sin_real16.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
! REQUIRES: flang-supports-f128-math
! RUN: bbc -emit-fir %s -o - | FileCheck %s
! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck %s
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s

! CHECK: fir.call @_FortranASinF128({{.*}}){{.*}}: (f128) -> f128
real(16) :: a, b
b = sin(a)
end
9 changes: 9 additions & 0 deletions flang/test/Lower/Intrinsics/sqrt_real16.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
! REQUIRES: flang-supports-f128-math
! RUN: bbc -emit-fir %s -o - | FileCheck %s
! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck %s
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s

! CHECK: fir.call @_FortranASqrtF128({{.*}}){{.*}}: (f128) -> f128
real(16) :: a, b
b = sqrt(a)
end
14 changes: 14 additions & 0 deletions flang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,17 @@
result = lit_config.params.get("LIBPGMATH")
if result:
config.environment["LIBPGMATH"] = True

# Add features and substitutions to test F128 math support.
# %f128-lib substitution may be used to generate check prefixes
# for LIT tests checking for F128 library support.
if config.flang_runtime_f128_math_lib:
config.available_features.add("flang-supports-f128-math")
config.available_features.add(
"flang-f128-math-lib-" + config.flang_runtime_f128_math_lib
)
config.substitutions.append(
("%f128-lib", config.flang_runtime_f128_math_lib.upper())
)
else:
config.substitutions.append(("%f128-lib", "NONE"))
1 change: 1 addition & 0 deletions flang/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ config.cc = "@CMAKE_C_COMPILER@"
config.osx_sysroot = path(r"@CMAKE_OSX_SYSROOT@")
config.targets_to_build = "@TARGETS_TO_BUILD@"
config.default_sysroot = "@DEFAULT_SYSROOT@"
config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@"

import lit.llvm
lit.llvm.initialize(lit_config, config)
Expand Down

0 comments on commit 6398baa

Please sign in to comment.