Skip to content

Commit af098c0

Browse files
committed
The first commit of two importing the gfortran test suite into the repo.
This *does not* contain the test files themselves. Those will be added in a future commit. This only contains the cmake files needed to build and the tests, the license files that govern the tests themselves and changes to the existing infrastructure. A README and other documentation has been provided. Some highlights: - The tests have only been enabled on non-Windows, non-Apple, x86 and Aarch64 platforms. - The gfortran tests are largely divided into "compile" tests that exercise specific behaviors of the compiler such as error messages and the ability to adhere to the standard, and "execute" tests that test the end-to-end behavior of the compiler and the correctness of the resulting binary. In this patch, only the "execute" tests are enabled. - A number of the tests have been disabled because they either trigger a "not yet implemented" assertion in flang, they cause flang to crash for a different reason (due to bugs/unimplemented features not guarded by an unimplemented assertion), they use non-standard extensions not (currently) supported by flang, or if they fail at runtime (likely because of bugs in the compiler or flang runtime, or because of unimplemented features in the runtime). - The test files themselves will be governed by GPL. The files committed in this patch will be governed by the LLVM license. Differential Revision: https://reviews.llvm.org/D146485
1 parent 7067486 commit af098c0

32 files changed

+4045
-5
lines changed

Fortran/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@
88
# directory
99
add_subdirectory(UnitTests)
1010
add_subdirectory(SNAP)
11+
12+
# The gfortran subdirectory contains tests imported as-is from gfortran's
13+
# test suite. These have not been widely tested, so they are only enabled for
14+
# certain combinations of platforms and architectures.
15+
if (NOT WIN32 AND NOT APPLE)
16+
if (ARCH MATCHES "x86" OR ARCH MATCHES "AArch64")
17+
add_subdirectory(gfortran)
18+
endif()
19+
endif()

Fortran/gfortran/CMakeLists.txt

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
cmake_minimum_required(VERSION 3.24.0)
2+
3+
include(CheckFortranCompilerFlag)
4+
5+
# NOTE: flang does not currently (as of 2023/03/20) support the -w flag. If
6+
# support for the flag is added, this should be removed.
7+
remove_definitions(-w)
8+
9+
# If the test suite was configured by adding -flang-experimental-exec, remove
10+
# that flag from the default compilation flags. It is only needed at link-time
11+
# anyway, and for that it is explicitly added to those targets that need it.
12+
#
13+
# NOTE: This should be removed once the -flang-experimental-exec flag is no
14+
# longer needed.
15+
string(REPLACE "-flang-experimental-exec" "" TMP_FFLAGS "${CMAKE_Fortran_FLAGS}")
16+
set(CMAKE_Fortran_FLAGS "${TMP_FFLAGS}")
17+
18+
# This option is added because as of 2023/03/20, several tests in this
19+
# directory have been disabled. Some of them exercise unsupported non-standard
20+
# extensions, others trigger a "not yet implemented" assertion while some cause
21+
# flang to crash. This option forces all the tests to build and can be used to
22+
# determine if any of the disabled tests can be enabled.
23+
option(TEST_SUITE_FORTRAN_FORCE_ALL_TESTS
24+
"Build and run all gfortran tests, including those in the 'unsupported', 'unimplemented', 'skipped', and 'failing' categories."
25+
OFF)
26+
27+
# Since the FORCE_ALL_TESTS option is a bit too blunt, there are some other
28+
# options to force building some subsets of the disabled tests.
29+
30+
# The 'unsupported' tests exercise non-standard extensions that are not
31+
# currently supported. But there is a chance some may be in the future, in which
32+
# case, it may be worthwhile seeing if any can be removed from the list and
33+
# enabled permanently.
34+
option(TEST_SUITE_FORTRAN_FORCE_UNSUPPORTED_TESTS
35+
"Build and run all 'unsupported' gfortran tests. These usually test non-standard extensions."
36+
OFF)
37+
38+
# The 'unimplemented' tests trigger a "not yet implemented" assertion at
39+
# compile-time. If those features are implemented, enabling those tests may help
40+
# in identifying those that can be removed from the list and permanently enabled
41+
# because the root cause has been addressed.
42+
option(TEST_SUITE_FORTRAN_FORCE_UNIMPLEMENTED_TESTS
43+
"Build and run all 'unimplemented' gfortran tests. These are tests that fail at build-time because of unimplemented features in flang."
44+
OFF)
45+
46+
# The 'skipped' tests cause flang to crash at compile-time for "non-obvious"
47+
# reasons. They could be related to unimplemented features, or they could be
48+
# bugs in the compiler. In any case, enabling them may help identify those tests
49+
# that can be removed from the list and permanently enabled because the root
50+
# cause has been addressed.
51+
option(TEST_SUITE_FORTRAN_FORCE_SKIPPED_TESTS
52+
"Build and run all 'skipped' gfortran tests. These are tests that cause flang to crash."
53+
OFF)
54+
55+
# The 'failing' tests fail to pass either because of a bug somewhere in the
56+
# compiler or the runtime. Enabling these tests may help identify those tests
57+
# that can be removed from the list and permanently enabled because the root
58+
# cause has been addressed.
59+
option(TEST_SUITE_FORTRAN_FORCE_FAILING_TESTS
60+
"Build and run all 'failing' tests. These tests failed at runtime, perhaps due to bugs in the code generator or bugs/unimplemented features in the runtime."
61+
OFF)
62+
63+
# The ISO_Fortran_binding.h file is required to run some of the tests. This
64+
# header is copied to ${CMAKE_INSTALL_PREFIX}/include/flang at flang install
65+
# time which can be found automatically. If the compiler being tested here is
66+
# not installed, that file will not be found. In that case, the path to it must
67+
# be provided explicitly.
68+
set(TEST_SUITE_FORTRAN_ISO_C_HEADER_DIR "" CACHE STRING
69+
"Path to the directory containing ISO_Fortran_bindings.h header file.")
70+
71+
# The following cause errors if they are passed to flang via FFLAGS
72+
set(FLANG_ERRORING_FFLAGS
73+
-fallow-invalid-boz
74+
-fdec
75+
-fdec-format-defaults
76+
-fdec-static
77+
-fdec-structure
78+
# Not sure if the -fdefault-* options will be supported. Maybe in a different
79+
# form in which case, this will have to be modified to accommodate those.
80+
-fdefault-real-10
81+
-fdefault-real-16
82+
-fdump-ipa-cp-details
83+
-fdump-ipa-fnsummary-details
84+
-fdump-ipa-inline-details
85+
-fdump-rtl-expand
86+
-fdump-tree-all
87+
-fdump-tree-cunroll-details
88+
-fdump-tree-cunrolli-details
89+
-fdump-tree-fre1
90+
-fdump-tree-gimple
91+
-fdump-tree-ifcvt
92+
-fdump-tree-lversion-details
93+
-fdump-tree-omplower
94+
-fdump-tree-optimized
95+
-fdump-tree-original
96+
-fdump-tree-pcom-details
97+
-fdump-tree-pre-details
98+
-fdump-tree-profile-estimate
99+
-fdump-tree-reassoc1
100+
-fdump-tree-vect-details
101+
-ff2c
102+
-finline-matmul-limit=0
103+
-finline-matmul-limit=10
104+
-finline-matmul-limit=100
105+
-finline-matmul-limit=1000
106+
-finline-matmul-limit=2
107+
-finline-matmul-limit=30
108+
-fipa-cp
109+
-fipa-cp-clone
110+
-fipa-pta
111+
-fipa-reference
112+
-fno-dec
113+
-fno-guess-branch-probability
114+
-fno-ipa-cp
115+
-fno-ipa-modref
116+
-fno-ipa-sra
117+
-fno-pad-source
118+
-fno-tree-ccp
119+
-fno-tree-forwprop
120+
-fno-tree-fre
121+
-fno-tree-loop-optimize
122+
-fno-tree-loop-vectorize
123+
-fpad-source
124+
-fset-g77-defaults
125+
-ftest-forall-temp
126+
-ftree-loop-distribution
127+
-ftree-loop-vectorize
128+
-ftree-pre
129+
-ftree-slp-vectorize
130+
-ftree-tail-merge
131+
-ftree-vectorize
132+
-ftree-vrp
133+
-mdejagnu-cpu=power4
134+
# -Os might eventually be supported, so this might also need to be removed
135+
# at some point
136+
-Og
137+
-Os
138+
# At some point, if we ever support explicit standard flags, some of these
139+
# should be removed.
140+
-std=gnu
141+
-std=legacy
142+
-std=f95
143+
-std=f2003
144+
-std=f2008
145+
-std=f2008ts
146+
# At the time of writing, -W warnings are not supported. flang errors out
147+
# saying that only -Werror is supported.
148+
-Wall
149+
-Wampersand
150+
-Wanalyzer-too-complex
151+
-Warray-bounds
152+
-Warray-temporaries
153+
-Wconversion
154+
-Wconversion-extra
155+
-Werner
156+
-Werror
157+
-Wextra
158+
-Wfunction-elimination
159+
-Wimplicit-procedure
160+
-Wintrinsic-shadow
161+
-Wintrinsics-std
162+
-Wline-truncation
163+
-Wno-all
164+
-Wno-analyzer-null-dereference
165+
-Wno-analyzer-possible-null-dereference
166+
-Wno-analyzer-too-complex
167+
-Wno-analyzer-use-of-uninitialized-value
168+
-Wno-c-binding-type
169+
-Wno-complain-wrong-lang
170+
-Wno-error
171+
-Wno-intrinsic-shadow
172+
-Wno-intrinsics-std
173+
-Wno-lto-type-mismatch
174+
-Wno-tabs
175+
-Wno-underflow
176+
-Wrealloc-lhs
177+
-Wrealloc-lhs-all
178+
-Wreturn-type
179+
-Wstringop-overflow
180+
-Wsurprising
181+
-Wtabs
182+
-Wuninitialized
183+
-Wunused
184+
-Wunused-dummy-argument
185+
-Wunused-function
186+
-Wunused-parameter
187+
-Wunused-variable
188+
-Wzerotrip
189+
)
190+
191+
set(HEADER_SEARCH_PATH "${TEST_SUITE_FORTRAN_ISO_C_HEADER_DIR}")
192+
if (NOT HEADER_SEARCH_PATH)
193+
get_filename_component(Fortran_BINDIR ${CMAKE_Fortran_COMPILER} DIRECTORY)
194+
get_filename_component(Fortran_PREFIX ${Fortran_BINDIR} DIRECTORY)
195+
196+
set(HEADER_SEARCH_PATH "${Fortran_PREFIX}/include/flang")
197+
endif()
198+
199+
find_file(ISO_FORTRAN_C_HEADER
200+
ISO_Fortran_binding.h
201+
PATHS ${HEADER_SEARCH_PATH}
202+
REQUIRED)
203+
204+
get_filename_component(ISO_FORTRAN_C_HEADER_DIR
205+
"${ISO_FORTRAN_C_HEADER}"
206+
DIRECTORY)
207+
208+
# This pulls out options in dg-options into `${Variable}`
209+
function(gfortran_dg_options_fflags Variable File)
210+
# Some files have dg-options which we need to pick up. These should be in
211+
# the first line but often aren't.
212+
#
213+
# We also need to be careful not to pick up target-specific dg-options.
214+
set(DG_FFLAGS)
215+
216+
file(STRINGS ${File} FileLines)
217+
foreach(FileLine ${FileLines})
218+
# Looking for `dg-options "..."` or `dg-additional-options "..."` without
219+
# `{ target` afterwards (ignoring spaces).
220+
if(FileLine MATCHES "dg-(additional-)?options [{]?[ ]*\"([^\"]*)\"[ ]*[}]?(.*)")
221+
# This is needed to turn the string into a list of FFLAGS
222+
separate_arguments(FILE_FFLAGS UNIX_COMMAND ${CMAKE_MATCH_2})
223+
# This does the negative lookahead for `{ target` anywhere in the rest of
224+
# the line
225+
if(NOT "${CMAKE_MATCH_3}" MATCHES "{ +target")
226+
list(APPEND DG_FFLAGS ${FILE_FFLAGS})
227+
endif()
228+
endif()
229+
endforeach()
230+
231+
# Remove any flags that will cause flang to raise an error.
232+
if (DG_FFLAGS)
233+
list(REMOVE_ITEM DG_FFLAGS ${FLANG_ERRORING_FFLAGS})
234+
endif()
235+
236+
# Set the parent scope variable
237+
set(${Variable} ${DG_FFLAGS} PARENT_SCOPE)
238+
endfunction()
239+
240+
function(gfortran_execute_test File)
241+
cmake_parse_arguments(GFORTRAN "" "PREFIX" "FFLAGS;LDFLAGS;DEPFILES" ${ARGN})
242+
# There are a few tests with duplicate filenames, and CMake wants all target
243+
# names to be unique, so we add a disambiguator to the target name. The
244+
# disambiguator uses the path of the file relative to the top-level directory
245+
# containing all the tests from the gfortran test suite.
246+
247+
# The ${File} argument is guaranteed to be the absolute path to the source
248+
# file.
249+
string(REPLACE "${PROJECT_SOURCE_DIR}/Fortran/gfortran/" "" Name "${File}")
250+
251+
# Replace any '/' separators with 2 underscores. Just replacing it by a single
252+
# underscore results in conflicts. For instance, there is a conflict between
253+
# regression/coarray_ptr_comp_2.f08 and regression/coarray/ptr_comp_2.f08
254+
# which are unrelated tests. Other such conflicts are probably also unrelated.
255+
string(REPLACE "/" "__" Name "${Name}")
256+
257+
# Retain the extension of the source file in the final target name because
258+
# there are cases where two source files with the same basename but different
259+
# extensions and they, too, represent completely different and unrelated
260+
# tests.
261+
string(REPLACE "." "_" Name "${Name}")
262+
263+
set(_target "${GFORTRAN_PREFIX}-${Name}")
264+
265+
gfortran_dg_options_fflags(DG_FFLAGS ${File})
266+
267+
# Add any flags that were requested
268+
list(APPEND FFLAGS ${DG_FFLAGS} ${GFORTRAN_FFLAGS})
269+
list(APPEND LDFLAGS ${GFORTRAN_LDFLAGS})
270+
271+
llvm_test_executable_no_test(${_target} ${File} ${GFORTRAN_DEPFILES})
272+
llvm_test_run()
273+
274+
llvm_add_test_for_target(${_target})
275+
target_include_directories(${_target} PRIVATE ${ISO_FORTRAN_C_HEADER_DIR})
276+
277+
# This is a workaround because cmake does not currently recognize the .f03
278+
# and .f08 extensions. A patch to fix cmake has been accepted and the fix
279+
# should be available in CMake 3.27. It might be better to check the CMake
280+
# CMake version and do this conditionally.
281+
list(APPEND SOURCES ${File})
282+
list(APPEND SOURCES ${GFORTRAN_DEPFILES})
283+
foreach(Source ${SOURCES})
284+
get_filename_component(Ext ${Source} LAST_EXT)
285+
if("${Ext}" STREQUAL ".f03" OR
286+
"${Ext}" STREQUAL ".F03" OR
287+
"${Ext}" STREQUAL ".f08" OR
288+
"${Ext}" STREQUAL ".F08")
289+
set_source_files_properties(${Source} PROPERTIES LANGUAGE Fortran)
290+
endif()
291+
endforeach()
292+
293+
# NOTE: This should be removed when the -flang-experimental-exec flag is no
294+
# longer needed.
295+
target_link_options(${_target} PRIVATE -flang-experimental-exec)
296+
set_target_properties(${_target} PROPERTIES LINKER_LANGUAGE Fortran)
297+
endfunction()
298+
299+
add_subdirectory(regression)
300+
add_subdirectory(torture)

0 commit comments

Comments
 (0)