[Openmp-commits] [llvm] [openmp] [OpenMP] Allow Fortran tests (PR #150722)

Michael Kruse via Openmp-commits openmp-commits at lists.llvm.org
Thu Aug 28 03:52:27 PDT 2025


https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/150722

>From 70dbb33e91453bce1f5039ac63c538f02b07ce98 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 28 Aug 2025 12:14:51 +0200
Subject: [PATCH] Allow tests written in Fortran

---
 llvm/runtimes/CMakeLists.txt                  |  5 ++++
 openmp/CMakeLists.txt                         | 15 ++++++-----
 openmp/README.rst                             |  2 +-
 openmp/cmake/OpenMPTesting.cmake              |  4 +++
 openmp/runtime/test/CMakeLists.txt            |  8 +++++-
 openmp/runtime/test/lit.cfg                   | 15 +++++++++++
 openmp/runtime/test/lit.site.cfg.in           |  2 ++
 .../test/transform/unroll/heuristic_intdo.f90 | 26 +++++++++++++++++++
 8 files changed, 68 insertions(+), 9 deletions(-)
 create mode 100644 openmp/runtime/test/transform/unroll/heuristic_intdo.f90

diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index 86cfd0285aa84..d33b5af5756f5 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -524,6 +524,11 @@ if(build_runtimes)
       endif()
     endforeach()
   endif()
+
+  if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES AND "flang" IN_LIST LLVM_ENABLE_PROJECTS)
+    # Allow openmp to see the Fortran compiler
+    list(APPEND extra_args ENABLE_FORTRAN)
+  endif()
   if("openmp" IN_LIST LLVM_ENABLE_RUNTIMES OR "offload" IN_LIST LLVM_ENABLE_RUNTIMES)
     if (${LLVM_TOOL_FLANG_BUILD})
       message(STATUS "Configuring build of omp_lib.mod and omp_lib_kinds.mod via flang")
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index f3de4bc4ee87b..1e446c8778934 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -78,13 +78,6 @@ else()
     set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
   endif()
 
-  # Check for flang
-  if (NOT MSVC)
-    set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang)
-  else()
-    set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang.exe)
-  endif()
-
   # Set fortran test compiler if flang is found
   if (EXISTS "${OPENMP_TEST_Fortran_COMPILER}")
     message("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER}")
@@ -103,6 +96,14 @@ endif()
 include(config-ix)
 include(HandleOpenMPOptions)
 
+# Check for flang
+set(OPENMP_TEST_Fortran_COMPILER_default "flang")
+if (CMAKE_Fortran_COMPILER)
+    set(OPENMP_TEST_Fortran_COMPILER_default "${CMAKE_Fortran_COMPILER}")
+endif ()
+set(OPENMP_TEST_Fortran_COMPILER "${OPENMP_TEST_Fortran_COMPILER_default}" CACHE STRING
+  "Fortran compiler to use for testing OpenMP runtime libraries.")
+
 # Set up testing infrastructure.
 include(OpenMPTesting)
 
diff --git a/openmp/README.rst b/openmp/README.rst
index c34d3e8a40d7d..cc485f9a56ce0 100644
--- a/openmp/README.rst
+++ b/openmp/README.rst
@@ -121,7 +121,7 @@ Options for all Libraries
 
 **OPENMP_TEST_Fortran_COMPILER** = ``${CMAKE_Fortran_COMPILER}``
   Compiler to use for testing. Defaults to the compiler that was also used for
-  building. Will default to flang if build is in-tree.
+  building.
 
 **OPENMP_LLVM_TOOLS_DIR** = ``/path/to/built/llvm/tools``
   Additional path to search for LLVM tools needed by tests.
diff --git a/openmp/cmake/OpenMPTesting.cmake b/openmp/cmake/OpenMPTesting.cmake
index 85240aede728d..60280b7ed4893 100644
--- a/openmp/cmake/OpenMPTesting.cmake
+++ b/openmp/cmake/OpenMPTesting.cmake
@@ -238,6 +238,10 @@ function(add_openmp_testsuite target comment)
       )
     endif()
   endif()
+
+  if (TARGET flang-rt)
+    add_dependencies(${target} flang-rt)
+  endif ()
 endfunction()
 
 function(construct_check_openmp_target)
diff --git a/openmp/runtime/test/CMakeLists.txt b/openmp/runtime/test/CMakeLists.txt
index a7790804542b7..9ee3be6939811 100644
--- a/openmp/runtime/test/CMakeLists.txt
+++ b/openmp/runtime/test/CMakeLists.txt
@@ -41,7 +41,13 @@ add_library(ompt-print-callback INTERFACE)
 target_include_directories(ompt-print-callback INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/ompt)
 
 
-add_openmp_testsuite(check-libomp "Running libomp tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS omp)
+add_custom_target(libomp-test-depends)
+add_dependencies(libomp-test-depends omp)
+if (LLVM_RUNTIMES_BUILD AND OPENMP_TEST_Fortran_COMPILER AND "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
+  add_dependencies(libomp-test-depends flang-rt)
+endif ()
+
+add_openmp_testsuite(check-libomp "Running libomp tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS libomp-test-depends)
 # Add target check-ompt, but make sure to not add the tests twice to check-openmp.
 add_openmp_testsuite(check-ompt "Running OMPT tests" ${CMAKE_CURRENT_BINARY_DIR}/ompt EXCLUDE_FROM_CHECK_ALL DEPENDS omp)
 
diff --git a/openmp/runtime/test/lit.cfg b/openmp/runtime/test/lit.cfg
index 4a5aff241765c..72da1ba1411f8 100644
--- a/openmp/runtime/test/lit.cfg
+++ b/openmp/runtime/test/lit.cfg
@@ -5,6 +5,8 @@ import os
 import re
 import subprocess
 import lit.formats
+from lit.llvm.subst import ToolSubst
+from lit.llvm import llvm_config
 
 # Tell pylint that we know config and lit_config exist somewhere.
 if 'PYLINT_IMPORT' in os.environ:
@@ -39,6 +41,19 @@ config.name = 'libomp'
 # suffixes: A list of file extensions to treat as test files.
 config.suffixes = ['.c', '.cpp']
 
+if config.test_fortran_compiler:
+    lit_config.note("OpenMP Fortran tests enabled")
+    config.suffixes += ['.f90', '.F90']
+    llvm_config.add_tool_substitutions([
+        ToolSubst(
+            "%flang",
+            command=config.test_fortran_compiler,
+            unresolved="fatal",
+        ),
+    ], [config.llvm_tools_dir])
+else:
+    lit_config.note("OpenMP Fortran tests disabled")
+
 # test_source_root: The root path where tests are located.
 config.test_source_root = os.path.dirname(__file__)
 
diff --git a/openmp/runtime/test/lit.site.cfg.in b/openmp/runtime/test/lit.site.cfg.in
index fc65289e4ce64..cc8b3b252d7d1 100644
--- a/openmp/runtime/test/lit.site.cfg.in
+++ b/openmp/runtime/test/lit.site.cfg.in
@@ -2,6 +2,7 @@
 
 config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@"
 config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@"
+config.test_fortran_compiler = "@OPENMP_TEST_Fortran_COMPILER@"
 config.test_compiler_features = @OPENMP_TEST_COMPILER_FEATURES@
 config.test_compiler_has_omp_h = @OPENMP_TEST_COMPILER_HAS_OMP_H@
 config.test_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@"
@@ -24,6 +25,7 @@ config.has_omit_frame_pointer_flag = @OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTE
 config.target_arch = "@LIBOMP_ARCH@"
 config.compiler_frontend_variant = "@CMAKE_C_COMPILER_FRONTEND_VARIANT@"
 config.compiler_simulate_id = "@CMAKE_C_SIMULATE_ID@"
+config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)
diff --git a/openmp/runtime/test/transform/unroll/heuristic_intdo.f90 b/openmp/runtime/test/transform/unroll/heuristic_intdo.f90
new file mode 100644
index 0000000000000..d0ef938dd3a8f
--- /dev/null
+++ b/openmp/runtime/test/transform/unroll/heuristic_intdo.f90
@@ -0,0 +1,26 @@
+! This test checks lowering of OpenMP unroll directive
+
+! RUN: %flang %flags %openmp_flags -fopenmp-version=51 %s -o %t.exe
+! RUN: %t.exe | FileCheck %s --match-full-lines
+
+
+program unroll_heuristic
+  integer :: i
+  print *, 'do'
+
+  !$OMP UNROLL
+  do i=7, 18, 3
+    print '("i=", I0)', i
+  end do
+  !$OMP END UNROLL
+
+  print *, 'done'
+end program
+
+
+! CHECK:      do
+! CHECK-NEXT: i=7
+! CHECK-NEXT: i=10
+! CHECK-NEXT: i=13
+! CHECK-NEXT: i=16
+! CHECK-NEXT: done



More information about the Openmp-commits mailing list