2020-01-15 00:20:49 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import lit.formats
|
|
|
|
import lit.util
|
|
|
|
|
|
|
|
from lit.llvm import llvm_config
|
|
|
|
from lit.llvm.subst import ToolSubst
|
|
|
|
from lit.llvm.subst import FindTool
|
|
|
|
|
|
|
|
# Configuration file for the 'lit' test runner.
|
|
|
|
|
|
|
|
# name: The name of this test suite.
|
|
|
|
config.name = 'Flang'
|
|
|
|
|
|
|
|
# testFormat: The test format to use to interpret tests.
|
|
|
|
#
|
|
|
|
# For now we require '&&' between commands, until they get globally killed and
|
|
|
|
# the test runner updated.
|
|
|
|
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
|
|
|
|
|
|
|
|
# suffixes: A list of file extensions to treat as test files.
|
2020-09-11 17:17:31 +08:00
|
|
|
config.suffixes = ['.c', '.cpp', '.f', '.F', '.ff', '.FOR', '.for', '.f77', '.f90', '.F90',
|
[flang][driver] Add support for fixed form detection
Currently the new flang driver always runs in free form mode. This patch
adds support for fixed form mode detection based on the file extensions.
Like `f18`, `flang-new` will treat files ending with ".f", ".F" and
".ff" as fixed form. Additionally, ".for", ".FOR", ".fpp" and ".FPP"
file extensions are recognised as fixed form files. This is consistent
with gfortran [1]. In summary, files with the following extensions are
treated as fixed-form:
* ".f", ".F", ".ff", ".for", ".FOR", ".fpp", ".FPP"
For consistency with flang/test/lit.cfg.py and f18, this patch also adds
support for the following file extensions:
* ".ff", ".FOR", ".for", ".ff90", ".fpp", ".FPP"
This is added in flang/lib/Frontend/FrontendOptions.cpp. Additionally,
the following extensions are included:
* ".f03", ".F03", ".f08", ".F08"
This is for compatibility with gfortran [1] and other popular Fortran
compilers [2].
NOTE: internally Flang will only differentiate between fixed and free
form files. Currently Flang does not support switching between language
standards, so in this regard file extensions are irrelevant. More
specifically, both `file.f03` and `file.f18` are represented with
`Language::Fortran` (as opposed to e.g. `Language::Fortran03`).
Summary of changes:
- Set Fortran::parser::Options::sFixedForm according to the file type
- Add isFixedFormSuffix and isFreeFormSuffix helper functions to
FrontendTool/Utils.h
- Change FrontendOptions::GetInputKindForExtension to support the missing
file extensions that f18 supports and some additional ones
- FrontendActionTest.cpp is updated to make sure that the test input is
treated as free-form
[1] https://gcc.gnu.org/onlinedocs/gfortran/GNU-Fortran-and-GCC.html
[2] https://github.com/llvm/llvm-project/blob/master/flang/docs/OptionComparison.md#notes
Differential Revision: https://reviews.llvm.org/D94228
2021-01-05 00:49:33 +08:00
|
|
|
'.ff90', '.f95', '.F95', '.ff95', '.fpp', '.FPP', '.cuf'
|
|
|
|
'.CUF', '.f18', '.F18', '.fir', '.f03', '.F03', '.f08', '.F08']
|
2020-01-15 00:20:49 +08:00
|
|
|
|
|
|
|
config.substitutions.append(('%PATH%', config.environment['PATH']))
|
|
|
|
|
|
|
|
llvm_config.use_default_substitutions()
|
|
|
|
|
|
|
|
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
|
|
|
|
# subdirectories contain auxiliary inputs for various tests in their parent
|
|
|
|
# directories.
|
|
|
|
config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
|
|
|
|
|
2020-09-11 17:17:31 +08:00
|
|
|
# If the new Flang driver is enabled, add the corresponding feature to
|
2021-02-23 02:05:18 +08:00
|
|
|
# config.
|
2020-09-11 17:17:31 +08:00
|
|
|
if config.include_flang_new_driver_test:
|
|
|
|
config.available_features.add('new-flang-driver')
|
2021-04-23 22:46:35 +08:00
|
|
|
else:
|
|
|
|
config.available_features.add('old-flang-driver')
|
2020-09-11 17:17:31 +08:00
|
|
|
|
2020-01-15 00:20:49 +08:00
|
|
|
# test_source_root: The root path where tests are located.
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
# test_exec_root: The root path where tests should be run.
|
2020-03-06 19:21:36 +08:00
|
|
|
config.test_exec_root = os.path.join(config.flang_obj_root, 'test')
|
2020-01-15 00:20:49 +08:00
|
|
|
|
|
|
|
# Tweak the PATH to include the tools dir.
|
|
|
|
llvm_config.with_environment('PATH', config.flang_tools_dir, append_path=True)
|
|
|
|
llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
|
|
|
|
|
2020-08-02 03:53:27 +08:00
|
|
|
if config.flang_standalone_build:
|
|
|
|
# For builds with FIR, set path for tco and enable related tests
|
|
|
|
if config.flang_llvm_tools_dir != "":
|
|
|
|
config.available_features.add('fir')
|
|
|
|
if config.llvm_tools_dir != config.flang_llvm_tools_dir:
|
|
|
|
llvm_config.with_environment('PATH', config.flang_llvm_tools_dir, append_path=True)
|
2020-08-01 02:10:44 +08:00
|
|
|
|
2020-01-15 00:20:49 +08:00
|
|
|
# For each occurrence of a flang tool name, replace it with the full path to
|
2020-05-04 22:25:02 +08:00
|
|
|
# the build directory holding that tool.
|
2021-04-23 22:46:35 +08:00
|
|
|
tools = []
|
2020-09-11 17:17:31 +08:00
|
|
|
if config.include_flang_new_driver_test:
|
2021-01-25 20:07:17 +08:00
|
|
|
tools.append(ToolSubst('%flang', command=FindTool('flang-new'), unresolved='fatal'))
|
2021-02-04 19:14:57 +08:00
|
|
|
tools.append(ToolSubst('%flang_fc1', command=FindTool('flang-new'),
|
|
|
|
extra_args=['-fc1'], unresolved='fatal'))
|
2021-01-25 20:07:17 +08:00
|
|
|
else:
|
|
|
|
tools.append(ToolSubst('%flang', command=FindTool('f18'),
|
|
|
|
unresolved='fatal'))
|
2021-02-04 19:14:57 +08:00
|
|
|
tools.append(ToolSubst('%flang_fc1', command=FindTool('f18'),
|
|
|
|
unresolved='fatal'))
|
2020-09-11 17:17:31 +08:00
|
|
|
|
2021-06-16 19:11:35 +08:00
|
|
|
# Define some variables to help us test that the flang runtime doesn't depend on
|
|
|
|
# the C++ runtime libraries. For this we need a C compiler. If for some reason
|
|
|
|
# we don't have one, we can just disable the test.
|
|
|
|
if config.cc:
|
|
|
|
libruntime = os.path.join(config.flang_lib_dir, 'libFortranRuntime.a')
|
|
|
|
includes = os.path.join(config.flang_src_dir, 'runtime')
|
|
|
|
|
|
|
|
if os.path.isfile(libruntime) and os.path.isdir(includes):
|
|
|
|
config.available_features.add('c-compiler')
|
|
|
|
tools.append(ToolSubst('%cc', command=config.cc, unresolved='fatal'))
|
|
|
|
tools.append(ToolSubst('%libruntime', command=libruntime,
|
|
|
|
unresolved='fatal'))
|
|
|
|
tools.append(ToolSubst('%runtimeincludes', command=includes,
|
|
|
|
unresolved='fatal'))
|
|
|
|
|
2020-08-02 03:53:27 +08:00
|
|
|
if config.flang_standalone_build:
|
|
|
|
llvm_config.add_tool_substitutions(tools, [config.flang_llvm_tools_dir])
|
|
|
|
else:
|
|
|
|
llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
|
2020-01-15 00:20:49 +08:00
|
|
|
|
2020-03-06 19:21:36 +08:00
|
|
|
# Enable libpgmath testing
|
|
|
|
result = lit_config.params.get("LIBPGMATH")
|
|
|
|
if result:
|
2020-02-26 07:22:14 +08:00
|
|
|
config.environment["LIBPGMATH"] = True
|