[Openmp-commits] [llvm] [openmp] [flang-rt][CMake] Avoid 'use, intrinsic ::' (PR #205634)
Michael Kruse via Openmp-commits
openmp-commits at lists.llvm.org
Thu Jun 25 06:26:08 PDT 2026
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/205634
>From 36b2989d48f7bf83705136eabe907a89f7d743ea Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 24 Jun 2026 19:30:48 +0200
Subject: [PATCH 1/5] Conditionally enable
RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND
---
flang-rt/lib/runtime/CMakeLists.txt | 11 ++++++++++-
openmp/module/CMakeLists.txt | 2 +-
runtimes/cmake/config-Fortran.cmake | 27 +++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index 9db7037355498..c30e1b56802b8 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -295,7 +295,7 @@ if (FLANG_RT_FORTRAN_MODULES)
# updated if a USE'd .mod file changes (a .mod stores the checksums of all
# .mod files it depends on and therefore needs to be updated as well), inject
# an file-level dependency via OBJECT_DEPENDS.
-
+ if (RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND)
add_flangrt_library(flang_rt.mod.fortran.builtins OBJECT
__fortran_builtins.f90
)
@@ -330,6 +330,15 @@ if (FLANG_RT_FORTRAN_MODULES)
flang_module_target(flang_rt.mod PUBLIC)
add_module_barrier(flang-rt-mod flang_rt.mod)
+ else ()
+ # Workaround not needed
+ add_flangrt_library(flang_rt.mod OBJECT
+ ${intrinsics_sources}
+ ${module_sources}
+ )
+ flang_module_target(flang_rt.mod PUBLIC)
+ add_module_barrier(flang-rt-mod flang_rt.mod)
+ endif ()
if (RUNTIMES_FORTRAN_MODULES)
set(_mod_install_dest "${RUNTIMES_INSTALL_RESOURCE_MOD_PATH}/..")
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index 451cbf9cc8fc8..9b6b473a34b60 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -34,7 +34,7 @@ endif ()
flang_module_target(libomp-mod PUBLIC)
add_dependencies(libomp-mod ${RUNTIMES_FORTRAN_BUILD_DEPS})
-if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
+if (RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND AND "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90"
APPEND PROPERTY OBJECT_DEPENDS
"${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}"
diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake
index 74fd15021f0a0..db030d7011215 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -23,6 +23,8 @@
# RUNTIMES_INSTALL_RESOURCE_MOD_PATH - Where to install intrinsic module files
# in the install prefix. Relative to CMAKE_INSTALL_PREFIX. Only used when
# RUNTIMES_FORTRAN_MODULES is ON.
+#
+# RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND
# Check whether the Fortran compiler already has access to builtin modules. Sets
@@ -188,6 +190,31 @@ option(RUNTIMES_FORTRAN_MODULES "Make Fortran .mod files available to Flang; sho
# Determine the paths for Fortran .mod files.
if (RUNTIMES_FORTRAN_MODULES)
+ set(RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND ON)
+ if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
+ # "Unix Makefiles" generator supports CMAKE_Fortran_BUILDING_IN(S)TRINSIC_MODULES
+ set(RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND OFF)
+ elseif (CMAKE_GENERATOR MATCHES "^Ninja")
+ # Ninja generator supports CMAKE_Fortran_BUILDING_IN(S)TRINSIC_MODULES
+ # starting with CMake 4.5
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL "4.5")
+ set(RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND OFF)
+ endif ()
+ endif ()
+ if (RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND)
+ message(STATUS "CMAKE_Fortran_BUILDING_IN(S)TRINSIC_MODULES: workaround enabled")
+ else ()
+ message(STATUS "CMAKE_Fortran_BUILDING_IN(S)TRINSIC_MODULES: assumed to work")
+ endif ()
+ set(RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND "${RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND}" PARENT_SCOPE)
+
+ # Always track intrinsic module dependencies; Even if not supported in the
+ # current setup, at worst they are ignored.
+ set(CMAKE_Fortran_BUILDING_INTRINSIC_MODULES ON)
+ set(CMAKE_Fortran_BUILDING_INSTRINSIC_MODULES ON)
+
+
+
# Flang expects its builtin modules in Clang's resource directory.
get_toolchain_module_subdir(toolchain_mod_subdir)
extend_path(RUNTIMES_OUTPUT_RESOURCE_MOD_DIR "${RUNTIMES_OUTPUT_RESOURCE_DIR}" "${toolchain_mod_subdir}")
>From 2423cb2c28e1b38a1dfcca34aa1f02bd05afcfc1 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 24 Jun 2026 20:19:18 +0200
Subject: [PATCH 2/5] flangrt_fix-mod-build
---
flang-rt/lib/runtime/CMakeLists.txt | 75 ++++++++++++++++-------------
openmp/module/CMakeLists.txt | 2 +-
runtimes/cmake/config-Fortran.cmake | 2 +-
3 files changed, 44 insertions(+), 35 deletions(-)
diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index c30e1b56802b8..2956f472371a6 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -13,6 +13,7 @@ set(HAVE_BACKTRACE ${Backtrace_FOUND})
set(BACKTRACE_HEADER ${Backtrace_HEADER})
# Module sources that are required by other modules
+# Compiled sequentially to ensure dependencies
set(intrinsics_sources
__fortran_builtins.f90
__cuda_builtins.f90
@@ -296,49 +297,57 @@ if (FLANG_RT_FORTRAN_MODULES)
# .mod files it depends on and therefore needs to be updated as well), inject
# an file-level dependency via OBJECT_DEPENDS.
if (RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND)
- add_flangrt_library(flang_rt.mod.fortran.builtins OBJECT
- __fortran_builtins.f90
- )
- set_property(SOURCE __fortran_builtins.f90 PROPERTY OBJECT_OUTPUTS "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}")
- flang_module_target(flang_rt.mod.fortran.builtins PUBLIC)
- add_module_barrier(flang_rt.mod.fortran.builtins.barrier flang_rt.mod.fortran.builtins)
+ # When a target depends on an object library, CMake seems to try to only build
+ # the object files that the target actual needs. If we are only interested
+ # in the module files, nothing gets built at all. To ensure that the module
+ # files are built, insert a custom target that is opaque to CMake so it cannot
+ # apply this optimization. Dependees on module files must depend on this
+ # barrier instead. An actual COMMAND (that does nothing) seems to be necessary
+ # on Windows to work.
+ set(intr_mod_deps "")
+ set(intr_mod_barriers "")
+ macro (module_dependency _srcfile)
+ set(_libname "flang_rt.mod.${_srcfile}")
+ set(_barriername "flang_rt.mod.${_srcfile}.barrier")
+ set(_objpath "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/${_srcfile}${CMAKE_Fortran_OUTPUT_EXTENSION}")
+
+ add_flangrt_library("${_libname}" OBJECT "${_srcfile}")
+ set_property(SOURCE "${_srcfile}" PROPERTY OBJECT_OUTPUTS "${_objpath}")
+ set_property(SOURCE "${_srcfile}" APPEND PROPERTY OBJECT_DEPENDS "${intr_mod_deps}"
+ )
+ flang_module_target("${_libname}" PUBLIC)
+ if (intr_mod_barriers)
+ add_dependencies("${_libname}" ${intr_mod_barriers})
+ endif ()
+ add_module_barrier("${_barriername}" "${_libname}")
- add_flangrt_library(flang_rt.mod.cuda.builtins OBJECT
- __cuda_builtins.f90
- )
- set_property(SOURCE __cuda_builtins.f90 PROPERTY OBJECT_OUTPUTS "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__cuda_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}")
- add_dependencies(flang_rt.mod.cuda.builtins flang_rt.mod.fortran.builtins.barrier)
- set_property(SOURCE __cuda_builtins.f90
- APPEND PROPERTY OBJECT_DEPENDS
- "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}"
- )
- flang_module_target(flang_rt.mod.cuda.builtins PUBLIC)
- add_module_barrier(flang_rt.mod.cuda.builtins.barrier flang_rt.mod.cuda.builtins)
+ list(APPEND intr_mod_deps "${_objpath}")
+ list(APPEND intr_mod_barriers "${_barriername}")
+ endmacro ()
- # The modules themselves
- add_flangrt_library(flang_rt.mod OBJECT
- ${module_sources}
- )
- add_dependencies(flang_rt.mod flang_rt.mod.fortran.builtins.barrier flang_rt.mod.cuda.builtins.barrier)
- foreach(_srcfile IN LISTS module_sources)
- set_property(SOURCE ${_srcfile}
- APPEND PROPERTY OBJECT_DEPENDS
- "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}"
- "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__cuda_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}"
- )
- endforeach()
+ foreach (_srcfile IN LISTS intrinsics_sources)
+ module_dependency("${_srcfile}")
+ endforeach ()
- flang_module_target(flang_rt.mod PUBLIC)
- add_module_barrier(flang-rt-mod flang_rt.mod)
+ # The modules that CMake correctly tracks dependencies of
+ add_flangrt_library(flang_rt.mod OBJECT
+ ${module_sources}
+ )
+ add_dependencies(flang_rt.mod ${intr_mod_barriers})
+ foreach(_srcfile IN LISTS module_sources)
+ set_property(SOURCE ${_srcfile}
+ APPEND PROPERTY OBJECT_DEPENDS "${intr_mod_deps}"
+ )
+ endforeach()
else ()
# Workaround not needed
add_flangrt_library(flang_rt.mod OBJECT
${intrinsics_sources}
${module_sources}
)
- flang_module_target(flang_rt.mod PUBLIC)
- add_module_barrier(flang-rt-mod flang_rt.mod)
endif ()
+ flang_module_target(flang_rt.mod PUBLIC)
+ add_module_barrier(flang-rt-mod flang_rt.mod)
if (RUNTIMES_FORTRAN_MODULES)
set(_mod_install_dest "${RUNTIMES_INSTALL_RESOURCE_MOD_PATH}/..")
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index 9b6b473a34b60..cd39c1b953229 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -37,7 +37,7 @@ add_dependencies(libomp-mod ${RUNTIMES_FORTRAN_BUILD_DEPS})
if (RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND AND "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90"
APPEND PROPERTY OBJECT_DEPENDS
- "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}"
+ "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins.f90${CMAKE_Fortran_OUTPUT_EXTENSION}"
)
endif ()
diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake
index db030d7011215..80c59b1aaee99 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -206,7 +206,7 @@ if (RUNTIMES_FORTRAN_MODULES)
else ()
message(STATUS "CMAKE_Fortran_BUILDING_IN(S)TRINSIC_MODULES: assumed to work")
endif ()
- set(RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND "${RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND}" PARENT_SCOPE)
+ #set(RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND "${RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND}" PARENT_SCOPE)
# Always track intrinsic module dependencies; Even if not supported in the
# current setup, at worst they are ignored.
>From 71c5e7f0ffcf2ebd58812d2e2812b22663be1631 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 24 Jun 2026 21:39:15 +0200
Subject: [PATCH 3/5] Actually set Fortran_BUILDING_INTRINSIC_MODULES
---
runtimes/cmake/config-Fortran.cmake | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake
index 80c59b1aaee99..a819ad542b657 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -206,12 +206,6 @@ if (RUNTIMES_FORTRAN_MODULES)
else ()
message(STATUS "CMAKE_Fortran_BUILDING_IN(S)TRINSIC_MODULES: assumed to work")
endif ()
- #set(RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND "${RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND}" PARENT_SCOPE)
-
- # Always track intrinsic module dependencies; Even if not supported in the
- # current setup, at worst they are ignored.
- set(CMAKE_Fortran_BUILDING_INTRINSIC_MODULES ON)
- set(CMAKE_Fortran_BUILDING_INSTRINSIC_MODULES ON)
@@ -271,6 +265,12 @@ function (flang_module_target tgtname)
"$<$<COMPILE_LANGUAGE:Fortran>:-fintrinsic-modules-path=${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}>"
)
+ set_target_properties(${tgtname}
+ PROPERTIES
+ Fortran_BUILDING_INTRINSIC_MODULES ON
+ Fortran_BUILDING_INSTRINSIC_MODULES ON
+ )
+
if (CMAKE_Fortran_COMPILER_ID MATCHES "LLVM")
target_compile_options(${tgtname} PRIVATE
# Flang bug workaround: Reformating of cooked token buffer causes
>From bb67b75f7fc47b349c6160ba081f4ef94293b641 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 24 Jun 2026 22:16:02 +0200
Subject: [PATCH 4/5] Just do not use 'use, intrinsic'
---
flang-rt/lib/runtime/CMakeLists.txt | 93 ++------------------
flang-rt/lib/runtime/__fortran_type_info.f90 | 2 +-
flang-rt/lib/runtime/cooperative_groups.f90 | 4 +-
flang-rt/lib/runtime/cudadevice.f90 | 6 +-
openmp/module/CMakeLists.txt | 7 --
openmp/module/omp_lib.F90.var | 40 ++++-----
runtimes/cmake/config-Fortran.cmake | 37 ++------
7 files changed, 42 insertions(+), 147 deletions(-)
diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index 2956f472371a6..13ce726c19002 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -12,15 +12,10 @@ find_package(Backtrace)
set(HAVE_BACKTRACE ${Backtrace_FOUND})
set(BACKTRACE_HEADER ${Backtrace_HEADER})
-# Module sources that are required by other modules
-# Compiled sequentially to ensure dependencies
-set(intrinsics_sources
- __fortran_builtins.f90
- __cuda_builtins.f90
-)
-
# Fortran sources for builtin .mod files
set(module_sources
+ __fortran_builtins.f90
+ __cuda_builtins.f90
__fortran_ieee_exceptions.f90
__fortran_type_info.f90
flang_debug.f90
@@ -216,10 +211,8 @@ file(GLOB_RECURSE private_headers
)
if (LLVM_TARGET_TRIPLE MATCHES "^ppc|^powerpc")
- list(APPEND intrinsics_sources
- __ppc_types.f90
- )
list(APPEND module_sources
+ __ppc_types.f90
__ppc_intrinsics.f90
mma.f90
)
@@ -265,21 +258,6 @@ if (TARGET FortranFloat128MathILib)
endif ()
-# When a target depends on an object library, CMake seems to try to only build
-# the object files that the target actual needs. If we are only interested
-# in the module files, nothing gets built at all. To ensure that the module
-# files are built, insert a custom target that is opaque to CMake so it cannot
-# apply this optimization. Dependees on module files must depend on this
-# barrier instead. An actual COMMAND (that does nothing) seems to be necessary
-# on Windows to work.
-function (add_module_barrier barriername objlib)
- add_custom_target(${barriername}
- COMMAND ${CMAKE_COMMAND} -E true
- )
- add_dependencies(${barriername} ${objlib})
-endfunction ()
-
-
# Build module files if requested.
# The object files written by Flang for these are unused. In the future parts
# of flang-rt may itself be implemented in Fortran in which case these Fortran
@@ -287,67 +265,10 @@ endfunction ()
# libflang_rt.runtime{.a/.so}. If they also provide an importable .mod, add them
# to flang_module_target(... PUBLIC).
if (FLANG_RT_FORTRAN_MODULES)
- # CMake ignores intrinsic USE dependencies
- # CMake has an option Fortran_BUILDING_INSTRINSIC_MODULES/Fortran_BUILDING_INTRINSIC_MODULES
- # to disable this behavior, unfortunately it does not work with Ninja
- # (https://gitlab.kitware.com/cmake/cmake/-/issues/26803)
- # As a workaround, we build those intrinsic modules first such that the main
- # runtime can depend on it. To ensure that modules files are also transitively
- # updated if a USE'd .mod file changes (a .mod stores the checksums of all
- # .mod files it depends on and therefore needs to be updated as well), inject
- # an file-level dependency via OBJECT_DEPENDS.
- if (RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND)
- # When a target depends on an object library, CMake seems to try to only build
- # the object files that the target actual needs. If we are only interested
- # in the module files, nothing gets built at all. To ensure that the module
- # files are built, insert a custom target that is opaque to CMake so it cannot
- # apply this optimization. Dependees on module files must depend on this
- # barrier instead. An actual COMMAND (that does nothing) seems to be necessary
- # on Windows to work.
- set(intr_mod_deps "")
- set(intr_mod_barriers "")
- macro (module_dependency _srcfile)
- set(_libname "flang_rt.mod.${_srcfile}")
- set(_barriername "flang_rt.mod.${_srcfile}.barrier")
- set(_objpath "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/${_srcfile}${CMAKE_Fortran_OUTPUT_EXTENSION}")
-
- add_flangrt_library("${_libname}" OBJECT "${_srcfile}")
- set_property(SOURCE "${_srcfile}" PROPERTY OBJECT_OUTPUTS "${_objpath}")
- set_property(SOURCE "${_srcfile}" APPEND PROPERTY OBJECT_DEPENDS "${intr_mod_deps}"
- )
- flang_module_target("${_libname}" PUBLIC)
- if (intr_mod_barriers)
- add_dependencies("${_libname}" ${intr_mod_barriers})
- endif ()
- add_module_barrier("${_barriername}" "${_libname}")
-
- list(APPEND intr_mod_deps "${_objpath}")
- list(APPEND intr_mod_barriers "${_barriername}")
- endmacro ()
-
- foreach (_srcfile IN LISTS intrinsics_sources)
- module_dependency("${_srcfile}")
- endforeach ()
-
- # The modules that CMake correctly tracks dependencies of
- add_flangrt_library(flang_rt.mod OBJECT
- ${module_sources}
- )
- add_dependencies(flang_rt.mod ${intr_mod_barriers})
- foreach(_srcfile IN LISTS module_sources)
- set_property(SOURCE ${_srcfile}
- APPEND PROPERTY OBJECT_DEPENDS "${intr_mod_deps}"
- )
- endforeach()
- else ()
- # Workaround not needed
- add_flangrt_library(flang_rt.mod OBJECT
- ${intrinsics_sources}
- ${module_sources}
- )
- endif ()
- flang_module_target(flang_rt.mod PUBLIC)
- add_module_barrier(flang-rt-mod flang_rt.mod)
+ add_flangrt_library(flang-rt-mod OBJECT
+ ${module_sources}
+ )
+ flang_module_target(flang-rt-mod PUBLIC)
if (RUNTIMES_FORTRAN_MODULES)
set(_mod_install_dest "${RUNTIMES_INSTALL_RESOURCE_MOD_PATH}/..")
diff --git a/flang-rt/lib/runtime/__fortran_type_info.f90 b/flang-rt/lib/runtime/__fortran_type_info.f90
index 0f1c3d018d009..d8cf385b8665e 100644
--- a/flang-rt/lib/runtime/__fortran_type_info.f90
+++ b/flang-rt/lib/runtime/__fortran_type_info.f90
@@ -13,7 +13,7 @@
module __fortran_type_info
- use, intrinsic :: __fortran_builtins, &
+ use __fortran_builtins, &
only: __builtin_c_ptr, __builtin_c_devptr, __builtin_c_funptr
implicit none
diff --git a/flang-rt/lib/runtime/cooperative_groups.f90 b/flang-rt/lib/runtime/cooperative_groups.f90
index 5ca0c3aa1f3a5..5c141d4d254db 100644
--- a/flang-rt/lib/runtime/cooperative_groups.f90
+++ b/flang-rt/lib/runtime/cooperative_groups.f90
@@ -10,8 +10,8 @@
module cooperative_groups
-use, intrinsic :: __fortran_builtins, only: c_devptr => __builtin_c_devptr
-use :: cudadevice ! implicit dependency, made explicit for CMake
+use __fortran_builtins, only: c_devptr => __builtin_c_devptr
+use cudadevice ! implicit dependency, made explicit for CMake
implicit none
diff --git a/flang-rt/lib/runtime/cudadevice.f90 b/flang-rt/lib/runtime/cudadevice.f90
index be041ba9d0a71..ea4787dd62e40 100644
--- a/flang-rt/lib/runtime/cudadevice.f90
+++ b/flang-rt/lib/runtime/cudadevice.f90
@@ -10,9 +10,9 @@
module cudadevice
use __cuda_device
- use, intrinsic :: __fortran_builtins, only: dim3 => __builtin_dim3
- use, intrinsic :: __fortran_builtins, only: c_devptr => __builtin_c_devptr
- use, intrinsic :: __fortran_builtins, only: c_devloc => __builtin_c_devloc
+ use __fortran_builtins, only: dim3 => __builtin_dim3
+ use __fortran_builtins, only: c_devptr => __builtin_c_devptr
+ use __fortran_builtins, only: c_devloc => __builtin_c_devloc
implicit none
! Synchronization Functions
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index cd39c1b953229..f905cfbde0a04 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -33,13 +33,6 @@ if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx")
endif ()
flang_module_target(libomp-mod PUBLIC)
-add_dependencies(libomp-mod ${RUNTIMES_FORTRAN_BUILD_DEPS})
-if (RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND AND "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
- set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90"
- APPEND PROPERTY OBJECT_DEPENDS
- "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins.f90${CMAKE_Fortran_OUTPUT_EXTENSION}"
- )
-endif ()
install(FILES
"${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.h"
diff --git a/openmp/module/omp_lib.F90.var b/openmp/module/omp_lib.F90.var
index 464056847ab92..2db2a33e90127 100644
--- a/openmp/module/omp_lib.F90.var
+++ b/openmp/module/omp_lib.F90.var
@@ -12,7 +12,7 @@
module omp_lib_kinds
- use, intrinsic :: iso_c_binding
+ use :: iso_c_binding
! Set PRIVATE by default to explicitly only export what is meant
! to be exported by this MODULE.
@@ -640,20 +640,20 @@
end subroutine omp_display_env
function omp_target_alloc(size, device_num) bind(c)
- use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int
+ use :: iso_c_binding, only: c_ptr, c_size_t, c_int
type(c_ptr) omp_target_alloc
integer(c_size_t), value :: size
integer(c_int), value :: device_num
end function omp_target_alloc
subroutine omp_target_free(device_ptr, device_num) bind(c)
- use, intrinsic :: iso_c_binding, only: c_ptr, c_int
+ use :: iso_c_binding, only: c_ptr, c_int
type(c_ptr), value :: device_ptr
integer(c_int), value :: device_num
end subroutine omp_target_free
function omp_target_is_present(ptr, device_num) bind(c)
- use, intrinsic :: iso_c_binding, only: c_ptr, c_int
+ use :: iso_c_binding, only: c_ptr, c_int
integer(c_int) omp_target_is_present
type(c_ptr), value :: ptr
integer(c_int), value :: device_num
@@ -661,7 +661,7 @@
function omp_target_memcpy(dst, src, length, dst_offset, src_offset, &
dst_device_num, src_device_num) bind(c)
- use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int
+ use :: iso_c_binding, only: c_ptr, c_size_t, c_int
integer(c_int) omp_target_memcpy
type(c_ptr), value :: dst, src
integer(c_size_t), value :: length, dst_offset, src_offset
@@ -671,7 +671,7 @@
function omp_target_memcpy_rect(dst, src, element_size, num_dims, &
volume, dst_offsets, src_offsets, dst_dimensions, &
src_dimensions, dst_device_num, src_device_num) bind(c)
- use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int
+ use :: iso_c_binding, only: c_ptr, c_size_t, c_int
integer(c_int) omp_target_memcpy_rect
type(c_ptr), value :: dst, src
integer(c_size_t), value :: element_size
@@ -684,7 +684,7 @@
src_offset, dst_device_num, src_device_num, depobj_count, &
depobj_list) bind(c)
use omp_lib_kinds
- use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int
+ use :: iso_c_binding, only: c_ptr, c_size_t, c_int
integer(c_int) omp_target_memcpy_async
type(c_ptr), value :: dst, src
integer(c_size_t), value :: length, dst_offset, src_offset
@@ -698,7 +698,7 @@
src_dimensions, dst_device_num, src_device_num, depobj_count, &
depobj_list) bind(c)
use omp_lib_kinds
- use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int
+ use :: iso_c_binding, only: c_ptr, c_size_t, c_int
integer(c_int) omp_target_memcpy_rect_async
type(c_ptr), value :: dst, src
integer(c_size_t), value :: element_size
@@ -710,7 +710,7 @@
end function omp_target_memcpy_rect_async
function omp_target_memset(ptr, val, count, device_num) bind(c)
- use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_size_t
+ use :: iso_c_binding, only : c_ptr, c_int, c_size_t
type(c_ptr) :: omp_target_memset
type(c_ptr), value :: ptr
integer(c_int), value :: val
@@ -721,7 +721,7 @@
function omp_target_memset_async(ptr, val, count, device_num, &
depobj_count, depobj_list) bind(c)
use omp_lib_kinds
- use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_size_t
+ use :: iso_c_binding, only : c_ptr, c_int, c_size_t
type(c_ptr) :: omp_target_memset_async
type(c_ptr), value :: ptr
integer(c_int), value :: val
@@ -733,7 +733,7 @@
function omp_target_associate_ptr(host_ptr, device_ptr, size, &
device_offset, device_num) bind(c)
- use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int
+ use :: iso_c_binding, only: c_ptr, c_size_t, c_int
integer(c_int) omp_target_associate_ptr
type(c_ptr), value :: host_ptr, device_ptr
integer(c_size_t), value :: size, device_offset
@@ -741,21 +741,21 @@
end function omp_target_associate_ptr
function omp_get_mapped_ptr(ptr, device_num) bind(c)
- use, intrinsic :: iso_c_binding, only: c_ptr, c_int
+ use :: iso_c_binding, only: c_ptr, c_int
type(c_ptr) omp_get_mapped_ptr
type(c_ptr), value :: ptr
integer(c_int), value :: device_num
end function omp_get_mapped_ptr
function omp_target_disassociate_ptr(ptr, device_num) bind(c)
- use, intrinsic :: iso_c_binding, only: c_ptr, c_int
+ use :: iso_c_binding, only: c_ptr, c_int
integer(c_int) omp_target_disassociate_ptr
type(c_ptr), value :: ptr
integer(c_int), value :: device_num
end function omp_target_disassociate_ptr
function omp_target_is_accessible(ptr, size, device_num) bind(c)
- use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t, c_int
+ use :: iso_c_binding, only : c_ptr, c_size_t, c_int
integer(c_int) omp_target_is_accessible
type(c_ptr), value :: ptr
integer(c_size_t), value :: size
@@ -764,7 +764,7 @@
function omp_alloc(size, allocator) bind(c)
use omp_lib_kinds
- use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t
+ use :: iso_c_binding, only : c_ptr, c_size_t
type(c_ptr) omp_alloc
integer(c_size_t), value :: size
integer(omp_allocator_handle_kind), value :: allocator
@@ -772,7 +772,7 @@
function omp_aligned_alloc(alignment, size, allocator) bind(c)
use omp_lib_kinds
- use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t
+ use :: iso_c_binding, only : c_ptr, c_size_t
type(c_ptr) omp_aligned_alloc
integer(c_size_t), value :: alignment, size
integer(omp_allocator_handle_kind), value :: allocator
@@ -780,7 +780,7 @@
function omp_calloc(nmemb, size, allocator) bind(c)
use omp_lib_kinds
- use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t
+ use :: iso_c_binding, only : c_ptr, c_size_t
type(c_ptr) omp_calloc
integer(c_size_t), value :: nmemb, size
integer(omp_allocator_handle_kind), value :: allocator
@@ -788,7 +788,7 @@
function omp_aligned_calloc(alignment, nmemb, size, allocator) bind(c)
use omp_lib_kinds
- use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t
+ use :: iso_c_binding, only : c_ptr, c_size_t
type(c_ptr) omp_aligned_calloc
integer(c_size_t), value :: alignment, nmemb, size
integer(omp_allocator_handle_kind), value :: allocator
@@ -796,7 +796,7 @@
function omp_realloc(ptr, size, allocator, free_allocator) bind(c)
use omp_lib_kinds
- use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t
+ use :: iso_c_binding, only : c_ptr, c_size_t
type(c_ptr) omp_realloc
type(c_ptr), value :: ptr
integer(c_size_t), value :: size
@@ -806,7 +806,7 @@
subroutine omp_free(ptr, allocator) bind(c)
use omp_lib_kinds
- use, intrinsic :: iso_c_binding, only : c_ptr
+ use :: iso_c_binding, only : c_ptr
type(c_ptr), value :: ptr
integer(omp_allocator_handle_kind), value :: allocator
end subroutine omp_free
diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake
index a819ad542b657..7bc035d8e916a 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -23,8 +23,6 @@
# RUNTIMES_INSTALL_RESOURCE_MOD_PATH - Where to install intrinsic module files
# in the install prefix. Relative to CMAKE_INSTALL_PREFIX. Only used when
# RUNTIMES_FORTRAN_MODULES is ON.
-#
-# RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND
# Check whether the Fortran compiler already has access to builtin modules. Sets
@@ -76,14 +74,8 @@ endfunction ()
set(RUNTIMES_ENABLE_FORTRAN OFF)
-# Insert at least one element for
-#
-# add_dependencies(target ${RUNTIMES_FORTRAN_BUILD_DEPS})
-#
-# to not fail
-add_custom_target(fortran-dummy-dep)
-set(RUNTIMES_FORTRAN_BUILD_DEPS fortran-dummy-dep)
+set(RUNTIMES_FORTRAN_BUILD_DEPS "")
if (CMAKE_Fortran_COMPILER)
# Workarounds for older versions of CMake not recognizing FLang. Hence, we
@@ -190,25 +182,6 @@ option(RUNTIMES_FORTRAN_MODULES "Make Fortran .mod files available to Flang; sho
# Determine the paths for Fortran .mod files.
if (RUNTIMES_FORTRAN_MODULES)
- set(RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND ON)
- if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
- # "Unix Makefiles" generator supports CMAKE_Fortran_BUILDING_IN(S)TRINSIC_MODULES
- set(RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND OFF)
- elseif (CMAKE_GENERATOR MATCHES "^Ninja")
- # Ninja generator supports CMAKE_Fortran_BUILDING_IN(S)TRINSIC_MODULES
- # starting with CMake 4.5
- if (CMAKE_VERSION VERSION_GREATER_EQUAL "4.5")
- set(RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND OFF)
- endif ()
- endif ()
- if (RUNTIMES_NEED_INTRINSIC_MODULES_WORKAROUND)
- message(STATUS "CMAKE_Fortran_BUILDING_IN(S)TRINSIC_MODULES: workaround enabled")
- else ()
- message(STATUS "CMAKE_Fortran_BUILDING_IN(S)TRINSIC_MODULES: assumed to work")
- endif ()
-
-
-
# Flang expects its builtin modules in Clang's resource directory.
get_toolchain_module_subdir(toolchain_mod_subdir)
extend_path(RUNTIMES_OUTPUT_RESOURCE_MOD_DIR "${RUNTIMES_OUTPUT_RESOURCE_DIR}" "${toolchain_mod_subdir}")
@@ -265,12 +238,20 @@ function (flang_module_target tgtname)
"$<$<COMPILE_LANGUAGE:Fortran>:-fintrinsic-modules-path=${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}>"
)
+ # Make CMake not ignore "use, intrinsic ::"-dependencies
+ # Only considered by
+ # * CMake >= 3.22 with the "Unix Makefiles" generator
+ # * CMake >= 4.5 with the Ninja generator
set_target_properties(${tgtname}
PROPERTIES
Fortran_BUILDING_INTRINSIC_MODULES ON
Fortran_BUILDING_INSTRINSIC_MODULES ON
)
+ if (NOT tgtname STREQUAL "flang-rt-mod" AND RUNTIMES_FORTRAN_BUILD_DEPS)
+ target_link_libraries(libomp-mod PRIVATE ${RUNTIMES_FORTRAN_BUILD_DEPS})
+ endif ()
+
if (CMAKE_Fortran_COMPILER_ID MATCHES "LLVM")
target_compile_options(${tgtname} PRIVATE
# Flang bug workaround: Reformating of cooked token buffer causes
>From 911e6729e418b65301fb37acc68d7ad8d7f14468 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 25 Jun 2026 13:34:37 +0200
Subject: [PATCH 5/5] Avoid hardcoding target names
---
runtimes/cmake/config-Fortran.cmake | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake
index 7bc035d8e916a..6d2d3bdbf60ea 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -238,18 +238,20 @@ function (flang_module_target tgtname)
"$<$<COMPILE_LANGUAGE:Fortran>:-fintrinsic-modules-path=${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}>"
)
- # Make CMake not ignore "use, intrinsic ::"-dependencies
- # Only considered by
- # * CMake >= 3.22 with the "Unix Makefiles" generator
- # * CMake >= 4.5 with the Ninja generator
+ # Make CMake not ignore "use, intrinsic ::"-dependencies. Unfortunately,
+ # it is not universally handled by CMake s.t. we currently must not use
+ # "use, intrinsic ::" in our sources.
+ # * CMake 3.22: Added Fortran_BUILDING_INSTRINSIC_MODULES handling "Unix Makefiles" generator
+ # * CMake 4.0: Renamed INSTRINSIC to INTRINSIC (typo fix); INSTRINSIC spelling kept but deprecated
+ # * CMake 4.5: Added handling by Ninja generators as well
set_target_properties(${tgtname}
PROPERTIES
Fortran_BUILDING_INTRINSIC_MODULES ON
Fortran_BUILDING_INSTRINSIC_MODULES ON
)
- if (NOT tgtname STREQUAL "flang-rt-mod" AND RUNTIMES_FORTRAN_BUILD_DEPS)
- target_link_libraries(libomp-mod PRIVATE ${RUNTIMES_FORTRAN_BUILD_DEPS})
+ if (RUNTIMES_FORTRAN_BUILD_DEPS AND NOT tgtname IN_LIST RUNTIMES_FORTRAN_BUILD_DEPS)
+ target_link_libraries(${tgtname} PRIVATE ${RUNTIMES_FORTRAN_BUILD_DEPS})
endif ()
if (CMAKE_Fortran_COMPILER_ID MATCHES "LLVM")
More information about the Openmp-commits
mailing list