diff --git a/flang/README.md b/flang/README.md --- a/flang/README.md +++ b/flang/README.md @@ -109,6 +109,12 @@ ninja ``` +By default flang tests that do not specify an explicit `--target` flag use +LLVM's default target triple. For these tests, if there is a need to test on a +different triple by overriding the default, the following needs to be added to +the cmake command above: +`-DLLVM_TARGET_TRIPLE_ENV="" -DFLANG_TEST_TARGET_TRIPLE=""`. + To run the flang tests on this build, execute the command in the "build" directory: ```bash diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt --- a/flang/test/CMakeLists.txt +++ b/flang/test/CMakeLists.txt @@ -100,3 +100,11 @@ PARAMS ${FLANG_TEST_PARAMS} DEPENDS ${FLANG_TEST_DEPENDS}) endif() + +# To modify the default target triple for flang tests. +if (DEFINED FLANG_TEST_TARGET_TRIPLE) + if (NOT DEFINED LLVM_TARGET_TRIPLE_ENV OR LLVM_TARGET_TRIPLE_ENV STREQUAL "") + message(FATAL_ERROR "LLVM_TARGET_TRIPLE_ENV must also be defined in order " + "to use FLANG_TEST_TARGET_TRIPLE.") + endif() +endif() diff --git a/flang/test/Unit/lit.cfg.py b/flang/test/Unit/lit.cfg.py --- a/flang/test/Unit/lit.cfg.py +++ b/flang/test/Unit/lit.cfg.py @@ -30,3 +30,8 @@ # Propagate PYTHON_EXECUTABLE into the environment #config.environment['PYTHON_EXECUTABLE'] = sys.executable + +# To modify the default target triple for flang tests. +if config.flang_test_triple: + config.target_triple = config.flang_test_triple + config.environment[config.llvm_target_triple_env] = config.flang_test_triple diff --git a/flang/test/Unit/lit.site.cfg.py.in b/flang/test/Unit/lit.site.cfg.py.in --- a/flang/test/Unit/lit.site.cfg.py.in +++ b/flang/test/Unit/lit.site.cfg.py.in @@ -2,6 +2,7 @@ config.llvm_src_root = "@LLVM_SOURCE_DIR@" config.llvm_obj_root = "@LLVM_BINARY_DIR@" +config.llvm_target_triple_env = "@LLVM_TARGET_TRIPLE_ENV@" config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@") config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@") config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@") @@ -9,6 +10,7 @@ config.flang_obj_root = "@FLANG_BINARY_DIR@" config.flang_src_root = "@FLANG_SOURCE_DIR@" config.flang_libs_dir = "@LLVM_LIBRARY_OUTPUT_INTDIR@" +config.flang_test_triple = "@FLANG_TEST_TARGET_TRIPLE@" config.flang_tools_dir = "@LLVM_RUNTIME_OUTPUT_INTDIR@" config.target_triple = "@LLVM_TARGET_TRIPLE@" config.python_executable = "@Python3_EXECUTABLE@" diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -45,6 +45,11 @@ for arch in config.targets_to_build.split(): config.available_features.add(arch.lower() + '-registered-target') +# To modify the default target triple for flang tests. +if config.flang_test_triple: + config.target_triple = config.flang_test_triple + config.environment[config.llvm_target_triple_env] = config.flang_test_triple + # excludes: A list of directories to exclude from the testsuite. The 'Inputs' # subdirectories contain auxiliary inputs for various tests in their parent # directories. diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in --- a/flang/test/lit.site.cfg.py.in +++ b/flang/test/lit.site.cfg.py.in @@ -5,6 +5,7 @@ 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.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_obj_root = "@FLANG_BINARY_DIR@" @@ -13,6 +14,7 @@ config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@" config.flang_llvm_tools_dir = "@CMAKE_BINARY_DIR@/bin" config.flang_lib_dir = "@CMAKE_BINARY_DIR@/lib" +config.flang_test_triple = "@FLANG_TEST_TARGET_TRIPLE@" config.flang_examples = @FLANG_BUILD_EXAMPLES@ config.python_executable = "@PYTHON_EXECUTABLE@" config.flang_standalone_build = @FLANG_STANDALONE_BUILD@