[Openmp-commits] [flang] [openmp] [Flang] Fix omp_lib.h location and search path (PR #201104)
Michael Kruse via Openmp-commits
openmp-commits at lists.llvm.org
Tue Jun 2 05:58:17 PDT 2026
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/201104
>From abfce71b9a23365eb4bcdca767c307554ce4501a Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Tue, 2 Jun 2026 11:21:20 +0200
Subject: [PATCH 1/2] Move omp_lib.h to same dir as modules
REQUIRES: line
---
flang/lib/Frontend/CompilerInvocation.cpp | 14 ------
flang/test/Driver/include-omp-header.f90 | 54 ++++++++++++-----------
flang/test/lit.cfg.py | 8 ----
openmp/module/CMakeLists.txt | 6 +--
4 files changed, 32 insertions(+), 50 deletions(-)
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 9853fc600ff6a..0cacccc56fce8 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -929,15 +929,6 @@ static std::string getIntrinsicDir(const char *argv) {
return std::string(driverPath);
}
-// Generate the path to look for OpenMP headers
-static std::string getOpenMPHeadersDir(const char *argv) {
- llvm::SmallString<128> includePath;
- includePath.assign(llvm::sys::fs::getMainExecutable(argv, nullptr));
- llvm::sys::path::remove_filename(includePath);
- includePath.append("/../include/flang/OpenMP/");
- return std::string(includePath);
-}
-
/// Parses all preprocessor input arguments and populates the preprocessor
/// options accordingly.
///
@@ -1795,11 +1786,6 @@ void CompilerInvocation::setDefaultFortranOpts() {
std::vector<std::string> searchDirectories{"."s};
fortranOptions.searchDirectories = searchDirectories;
- // Add the location of omp_lib.h to the search directories. Currently this is
- // identical to the modules' directory.
- fortranOptions.searchDirectories.emplace_back(
- getOpenMPHeadersDir(getArgv0()));
-
fortranOptions.isFixedForm = false;
}
diff --git a/flang/test/Driver/include-omp-header.f90 b/flang/test/Driver/include-omp-header.f90
index 7e54910a4b589..8548fcb23a12f 100644
--- a/flang/test/Driver/include-omp-header.f90
+++ b/flang/test/Driver/include-omp-header.f90
@@ -1,27 +1,31 @@
! REQUIRES: openmp_runtime
-! Verify that the omp_lib.h header is found and included correctly. This header file should be available at a path:
-! * relative to the driver, that's
-! * known the driver.
-! This is taken care of at the CMake and the driver levels. Note that when searching for header files, the directory of the current
-! source file takes precedence over other search paths. Hence adding omp_lib.h in the current directory will make Flang use that
-! header file instead of the one shipped with Flang.
-
-! This should just work
-! RUN: not rm omp_lib.h
-! RUN: %flang -cpp -fsyntax-only %openmp_flags %s 2>&1
-
-! Create an empty omp_lib.h header that _does not_ define omp_default_mem_alloc - this should lead to semantic errors
-! RUN: touch omp_lib.h
-! RUN: not %flang -cpp -fsyntax-only %openmp_flags %s 2>&1 | FileCheck %s
-! RUN: rm omp_lib.h
-
-! CHECK: error: Must have INTEGER type, but is REAL(4)
-
-include "omp_lib.h"
-
-integer :: x, y
-
-!$omp allocate(x, y) allocator(omp_default_mem_alloc)
-
-end
+! Check omp_lib.h works with driver
+! RUN: %flang -fsyntax-only -cpp %s -v 2>&1 | FileCheck %s --check-prefix=DRIVER
+! RUN: %flang -fsyntax-only -cpp %s -v -DHASHINCLUDE 2>&1 | FileCheck %s --check-prefix=DRIVER
+! DRIVER: -fc1
+! DRIVER-SAME: -fintrinsic-modules-path
+
+! Check frontend only works (no output expected)
+! RUN: %flang_fc1 -fsyntax-only -cpp %s
+! RUN: %flang_fc1 -fsyntax-only -cpp -DHASHINCLUDE %s
+
+! Check omp_lib.h contents
+! RUN: %flang_fc1 -cpp %s -E -fno-reformat 2>&1 | FileCheck %s --check-prefix=PREPROCESSED
+! RUN: %flang_fc1 -cpp %s -E -fno-reformat -DHASHINCLUDE 2>&1 | FileCheck %s --check-prefix=PREPROCESSED
+! PREPROCESSED: integer(kind=omp_integer_kind)openmp_version
+! PREPROCESSED: parameter(openmp_version={{[0-9]+}})
+
+
+program main
+#ifdef HASHINCLUDE
+ #include "omp_lib.h"
+#else
+ include "omp_lib.h"
+#endif
+
+ integer :: x, y
+ !$omp allocate(x, y) allocator(omp_default_mem_alloc)
+
+ print *, 'PASS: openmp_version parameter ', openmp_version
+end program main
diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index 92278a220cec0..3c6a33e010f59 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -187,14 +187,6 @@ def get_resource_module_intrinsic_dir(modfile):
# Determine if OpenMP runtime was built (enable OpenMP tests via REQUIRES in test file)
if config.flang_test_enable_openmp or openmp_mod_path:
config.available_features.add("openmp_runtime")
-
- # Search path for omp_lib.h with LLVM_ENABLE_RUNTIMES=openmp
- # FIXME: In a bootstrapping build, openmp should write this file into a
- # shared directory
- flang_extra_search_args += [
- "-I",
- f"{config.flang_obj_root}/../../runtimes/runtimes-bins/openmp/runtime/src",
- ]
else:
lit_config.warning(
f"OpenMP modules found not in driver default paths: OpenMP tests disabled; Use FLANG_TEST_ENABLE_OPENMP=ON to force-enable"
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index c0a873f9be552..0e06d84d3b2d6 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -9,7 +9,7 @@
# Build the module files if a Fortran compiler is available.
configure_file(omp_lib.F90.var "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90" @ONLY)
-configure_file(omp_lib.h.var "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.h" @ONLY)
+configure_file(omp_lib.h.var "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.h" @ONLY)
# One compilation step creates both, omp_lib.mod and omp_lib_kinds.mod. Only
# these files are used, the object file itself can be discarded.
@@ -30,8 +30,8 @@ flang_module_target(libomp-mod PUBLIC)
add_dependencies(libomp-mod ${RUNTIMES_FORTRAN_BUILD_DEPS})
install(FILES
- "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.h"
- DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}
+ "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.h"
+ DESTINATION "${RUNTIMES_INSTALL_RESOURCE_MOD_PATH}"
COMPONENT openmp
)
>From da1807d32a992b7e88bb4664c5ee4dbcc6fc97c2 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Tue, 2 Jun 2026 14:57:09 +0200
Subject: [PATCH 2/2] Test both include styles
---
flang/test/Driver/include-omp-header.f90 | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/flang/test/Driver/include-omp-header.f90 b/flang/test/Driver/include-omp-header.f90
index 8548fcb23a12f..e3ffd376f9058 100644
--- a/flang/test/Driver/include-omp-header.f90
+++ b/flang/test/Driver/include-omp-header.f90
@@ -10,8 +10,11 @@
! RUN: %flang_fc1 -fsyntax-only -cpp %s
! RUN: %flang_fc1 -fsyntax-only -cpp -DHASHINCLUDE %s
+! Check non-#include
+! RUN: %flang_fc1 -cpp %s -E -fno-reformat 2>&1 | FileCheck %s --check-prefix=INCLUDE
+! INCLUDE: include "omp_lib.h"
+
! Check omp_lib.h contents
-! RUN: %flang_fc1 -cpp %s -E -fno-reformat 2>&1 | FileCheck %s --check-prefix=PREPROCESSED
! RUN: %flang_fc1 -cpp %s -E -fno-reformat -DHASHINCLUDE 2>&1 | FileCheck %s --check-prefix=PREPROCESSED
! PREPROCESSED: integer(kind=omp_integer_kind)openmp_version
! PREPROCESSED: parameter(openmp_version={{[0-9]+}})
More information about the Openmp-commits
mailing list