From 156b6b0a115dcfa8b241ee59855fd33776847609 Mon Sep 17 00:00:00 2001 From: parabola94 Date: Sat, 9 Aug 2025 15:09:22 +0900 Subject: [PATCH 1/4] [flang/flang-rt] Add -isysroot flag only to tests really requiring -isysroot flag was added to all tests, but it makes Driver/darwin-version.f90 failed. In fact, only a few tests need -isysroot flag. So, -isysroot flag is now eliminated from the substitution `%flang`, and a new substitution `%isysroot` has been introduced. Moreover, Integration/iso-fortran-binding.cpp invokes clang++ via a shell script, which makes it hard to add -isysroot flag. So, it is refactored. --- flang-rt/test/Driver/ctofortran.f90 | 4 ++-- flang-rt/test/Runtime/no-cpp-dep.c | 2 +- flang-rt/test/lit.cfg.py | 7 +++--- .../test/Integration/iso-fortran-binding.cpp | 24 ++++--------------- flang/test/Integration/lit.local.cfg | 13 ++++++++++ flang/test/lit.cfg.py | 4 ++-- flang/test/lit.site.cfg.py.in | 2 ++ 7 files changed, 27 insertions(+), 29 deletions(-) create mode 100644 flang/test/Integration/lit.local.cfg diff --git a/flang-rt/test/Driver/ctofortran.f90 b/flang-rt/test/Driver/ctofortran.f90 index e385e7974cdc1..4979a4e68da59 100644 --- a/flang-rt/test/Driver/ctofortran.f90 +++ b/flang-rt/test/Driver/ctofortran.f90 @@ -2,8 +2,8 @@ ! UNSUPPORTED: offload-cuda ! RUN: split-file %s %t -! RUN: %clang -I"%include/flang" -c %t/cfile.c -o %t/cfile.o -! RUN: %flang -L"%libdir" %t/ffile.f90 %t/cfile.o -o %t/ctofortran +! RUN: %clang %isysroot -I"%include/flang" -c %t/cfile.c -o %t/cfile.o +! RUN: %flang %isysroot -L"%libdir" %t/ffile.f90 %t/cfile.o -o %t/ctofortran ! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%libdir" %t/ctofortran | FileCheck %s !--- ffile.f90 diff --git a/flang-rt/test/Runtime/no-cpp-dep.c b/flang-rt/test/Runtime/no-cpp-dep.c index c98678b69aa14..006f44b4aff7a 100644 --- a/flang-rt/test/Runtime/no-cpp-dep.c +++ b/flang-rt/test/Runtime/no-cpp-dep.c @@ -7,7 +7,7 @@ UNSUPPORTED: system-windows UNSUPPORTED: offload-cuda RUN: %if system-aix %{ export OBJECT_MODE=64 %} -RUN: %cc -std=c99 %s -I%include -L"%libdir" -lflang_rt.runtime -lm \ +RUN: %cc -std=c99 %s %isysroot -I%include -L"%libdir" -lflang_rt.runtime -lm \ RUN: %if system-aix %{-lpthread %} RUN: rm a.out */ diff --git a/flang-rt/test/lit.cfg.py b/flang-rt/test/lit.cfg.py index 032aeef2d5bf6..27f4666a4a42a 100644 --- a/flang-rt/test/lit.cfg.py +++ b/flang-rt/test/lit.cfg.py @@ -62,25 +62,24 @@ def shjoin(args, sep=" "): # lit writes a '.lit_test_times.txt' file into this directory. config.test_exec_root = config.flang_rt_binary_test_dir -# On MacOS, -isysroot is needed to build binaries. +# On MacOS, some tests need -isysroot to build binaries. isysroot_flag = [] if config.osx_sysroot: isysroot_flag = ["-isysroot", config.osx_sysroot] +config.substitutions.append(("%isysroot", " ".join(isysroot_flag))) tools = [ ToolSubst( "%flang", command=config.flang, - extra_args=isysroot_flag, unresolved="fatal", ), ToolSubst( "%clang", command=FindTool("clang"), - extra_args=isysroot_flag, unresolved="fatal", ), - ToolSubst("%cc", command=config.cc, extra_args=isysroot_flag, unresolved="fatal"), + ToolSubst("%cc", command=config.cc, unresolved="fatal"), ] llvm_config.add_tool_substitutions(tools) diff --git a/flang/test/Integration/iso-fortran-binding.cpp b/flang/test/Integration/iso-fortran-binding.cpp index aaafd7cccd07d..95a151914bbc2 100644 --- a/flang/test/Integration/iso-fortran-binding.cpp +++ b/flang/test/Integration/iso-fortran-binding.cpp @@ -1,9 +1,9 @@ +// REQUIRES: clang // UNSUPPORTED: system-windows -// RUN: split-file %s %t -// RUN: chmod +x %t/runtest.sh -// RUN: %t/runtest.sh %t %t/cppfile.cpp %flang | FileCheck %s +// RUN: rm -rf %t && mkdir %t +// RUN: %clangxx %isysroot -I %include/flang %s -o %t/a.out +// RUN: %t/a.out | FileCheck %s -//--- cppfile.cpp extern "C" { #include "ISO_Fortran_binding.h" } @@ -15,19 +15,3 @@ int main() { } // CHECK: PASS -// clang-format off -//--- runtest.sh -#!/bin/bash -TMPDIR=$1 -CPPFILE=$2 -FLANG=$3 -BINDIR=`dirname $FLANG` -CPPCOMP=$BINDIR/clang++ -if [ -x $CPPCOMP ] -then - $CPPCOMP $CPPFILE -o $TMPDIR/a.out - $TMPDIR/a.out # should print "PASS" -else - # No clang compiler, just pass by default - echo "PASS" -fi diff --git a/flang/test/Integration/lit.local.cfg b/flang/test/Integration/lit.local.cfg new file mode 100644 index 0000000000000..71db41d9112e4 --- /dev/null +++ b/flang/test/Integration/lit.local.cfg @@ -0,0 +1,13 @@ +from lit.llvm import llvm_config + +llvm_config.use_clang(required=False) +if llvm_config.config.clang: + config.available_features.add("clang") + clangxx = next((subst for subst in llvm_config.config.substitutions + if "clangxx" in subst[0]), None) + config.substitutions.append(clangxx) + +# Include path for C headers that define Flang's Fortran ABI. +config.substitutions.append( + ("%include", os.path.join(config.flang_source_dir, "include")) +) diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py index 7eb57670ac767..2c5d2e7271e21 100644 --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -118,10 +118,11 @@ "PATH", config.flang_llvm_tools_dir, append_path=True ) -# On MacOS, -isysroot is needed to build binaries. +# On MacOS, some tests need -isysroot to build binaries. isysroot_flag = [] if config.osx_sysroot: isysroot_flag = ["-isysroot", config.osx_sysroot] +config.substitutions.append(("%isysroot", " ".join(isysroot_flag))) # Check for DEFAULT_SYSROOT, because when it is set -isysroot has no effect. if config.default_sysroot: @@ -133,7 +134,6 @@ ToolSubst( "%flang", command=FindTool("flang"), - extra_args=isysroot_flag, unresolved="fatal", ), ToolSubst( diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in index ae5144010bc8b..2a016c733be59 100644 --- a/flang/test/lit.site.cfg.py.in +++ b/flang/test/lit.site.cfg.py.in @@ -6,10 +6,12 @@ import lit.util config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@") config.llvm_shlib_dir = lit_config.substitute(path(r"@SHLIBDIR@")) config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@" +config.host_triple = "@LLVM_HOST_TRIPLE@" config.target_triple = "@LLVM_TARGET_TRIPLE@" config.llvm_target_triple_env = "@LLVM_TARGET_TRIPLE_ENV@" config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@" +config.flang_source_dir = "@FLANG_SOURCE_DIR@" config.flang_obj_root = "@FLANG_BINARY_DIR@" config.flang_tools_dir = lit_config.substitute("@FLANG_TOOLS_DIR@") config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@" From 2449ff816aa876b94bddb064159eba5f104470c1 Mon Sep 17 00:00:00 2001 From: parabola94 Date: Mon, 11 Aug 2025 19:14:08 +0900 Subject: [PATCH 2/4] Call `use_clang` at the top-level --- flang/test/Integration/lit.local.cfg | 13 ------------- flang/test/lit.cfg.py | 7 +++++++ 2 files changed, 7 insertions(+), 13 deletions(-) delete mode 100644 flang/test/Integration/lit.local.cfg diff --git a/flang/test/Integration/lit.local.cfg b/flang/test/Integration/lit.local.cfg deleted file mode 100644 index 71db41d9112e4..0000000000000 --- a/flang/test/Integration/lit.local.cfg +++ /dev/null @@ -1,13 +0,0 @@ -from lit.llvm import llvm_config - -llvm_config.use_clang(required=False) -if llvm_config.config.clang: - config.available_features.add("clang") - clangxx = next((subst for subst in llvm_config.config.substitutions - if "clangxx" in subst[0]), None) - config.substitutions.append(clangxx) - -# Include path for C headers that define Flang's Fortran ABI. -config.substitutions.append( - ("%include", os.path.join(config.flang_source_dir, "include")) -) diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py index 2c5d2e7271e21..723c3f23ad200 100644 --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -172,6 +172,13 @@ else: llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir) +llvm_config.use_clang(required=False) + +# Include path for C headers that define Flang's Fortran ABI. +config.substitutions.append( + ("%include", os.path.join(config.flang_source_dir, "include")) +) + # Enable libpgmath testing result = lit_config.params.get("LIBPGMATH") if result: From 0cef883529302ad729bba6395ba31932192e0538 Mon Sep 17 00:00:00 2001 From: parabola94 Date: Tue, 12 Aug 2025 08:20:25 +0900 Subject: [PATCH 3/4] Use `flang_intrinsic_modules_dir` instead of `flang_source_dir` for the include path --- flang/test/Integration/iso-fortran-binding.cpp | 2 +- flang/test/lit.cfg.py | 6 ++---- flang/test/lit.site.cfg.py.in | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/flang/test/Integration/iso-fortran-binding.cpp b/flang/test/Integration/iso-fortran-binding.cpp index 95a151914bbc2..36ae35d9d29f7 100644 --- a/flang/test/Integration/iso-fortran-binding.cpp +++ b/flang/test/Integration/iso-fortran-binding.cpp @@ -1,7 +1,7 @@ // REQUIRES: clang // UNSUPPORTED: system-windows // RUN: rm -rf %t && mkdir %t -// RUN: %clangxx %isysroot -I %include/flang %s -o %t/a.out +// RUN: %clangxx %isysroot -I%flang_include %s -o %t/a.out // RUN: %t/a.out | FileCheck %s extern "C" { diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py index 723c3f23ad200..b28b834017fd9 100644 --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -174,10 +174,8 @@ llvm_config.use_clang(required=False) -# Include path for C headers that define Flang's Fortran ABI. -config.substitutions.append( - ("%include", os.path.join(config.flang_source_dir, "include")) -) +# Clang may need the include path for ISO_fortran_binding.h. +config.substitutions.append(("%flang_include", config.flang_intrinsic_modules_dir)) # Enable libpgmath testing result = lit_config.params.get("LIBPGMATH") diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in index 2a016c733be59..c357c7b9675ee 100644 --- a/flang/test/lit.site.cfg.py.in +++ b/flang/test/lit.site.cfg.py.in @@ -11,7 +11,6 @@ config.target_triple = "@LLVM_TARGET_TRIPLE@" config.llvm_target_triple_env = "@LLVM_TARGET_TRIPLE_ENV@" config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@" -config.flang_source_dir = "@FLANG_SOURCE_DIR@" config.flang_obj_root = "@FLANG_BINARY_DIR@" config.flang_tools_dir = lit_config.substitute("@FLANG_TOOLS_DIR@") config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@" From 131e0fdca39d2ca035ea785bd0abe467eafcdf6b Mon Sep 17 00:00:00 2001 From: parabola94 Date: Wed, 13 Aug 2025 07:11:39 +0900 Subject: [PATCH 4/4] Use `HEADER_BINARY_DIR` instead of `FLANG_INTRINSIC_MODULES_DIR` --- flang/CMakeLists.txt | 5 +++-- flang/test/lit.cfg.py | 2 +- flang/test/lit.site.cfg.py.in | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index 0bfada476348a..f74f345f2ab25 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -495,6 +495,9 @@ endif() include(AddFlang) include(FlangCommon) +include(GetClangResourceDir) + +get_clang_resource_dir(HEADER_BINARY_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include) if (FLANG_INCLUDE_TESTS) add_compile_definitions(FLANG_INCLUDE_TESTS=1) @@ -575,8 +578,6 @@ endif() # Put ISO_Fortran_binding.h into the include files of the build area now # so that we can run tests before installing -include(GetClangResourceDir) -get_clang_resource_dir(HEADER_BINARY_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include) configure_file( ${FLANG_SOURCE_DIR}/include/flang/ISO_Fortran_binding.h ${HEADER_BINARY_DIR}/ISO_Fortran_binding.h COPYONLY) diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py index b28b834017fd9..9d81aa41384ed 100644 --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -175,7 +175,7 @@ llvm_config.use_clang(required=False) # Clang may need the include path for ISO_fortran_binding.h. -config.substitutions.append(("%flang_include", config.flang_intrinsic_modules_dir)) +config.substitutions.append(("%flang_include", config.flang_headers_dir)) # Enable libpgmath testing result = lit_config.params.get("LIBPGMATH") diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in index c357c7b9675ee..cc1f4fa6cc9c5 100644 --- a/flang/test/lit.site.cfg.py.in +++ b/flang/test/lit.site.cfg.py.in @@ -14,6 +14,7 @@ config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@" config.flang_obj_root = "@FLANG_BINARY_DIR@" config.flang_tools_dir = lit_config.substitute("@FLANG_TOOLS_DIR@") config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@" +config.flang_headers_dir = "@HEADER_BINARY_DIR@" config.flang_llvm_tools_dir = "@CMAKE_BINARY_DIR@/bin" config.flang_test_triple = "@FLANG_TEST_TARGET_TRIPLE@" config.flang_examples = @LLVM_BUILD_EXAMPLES@