[Openmp-commits] [openmp] Avoid concurrency issues in LibompGetArchitecture (PR #151313)

Alexander Grund via Openmp-commits openmp-commits at lists.llvm.org
Wed Jul 30 05:08:17 PDT 2025


https://github.com/Flamefire updated https://github.com/llvm/llvm-project/pull/151313

>From 12db091a62ed9330a6b0ee00c7856ee7a8a3001d Mon Sep 17 00:00:00 2001
From: Alexander Grund <alexander.grund at tu-dresden.de>
Date: Wed, 30 Jul 2025 13:38:24 +0200
Subject: [PATCH 1/2] Avoid concurrency issues in LibompGetArchitecture

Especially during `make check-all -j <n>` this CMake code might be run in parallel.
So one process could remove the file another process has just written and tries to compile.

So do not delete the file.
Additionally use just `try_compile` as running is never intended nor possible anyway.
---
 openmp/runtime/cmake/LibompGetArchitecture.cmake | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/openmp/runtime/cmake/LibompGetArchitecture.cmake b/openmp/runtime/cmake/LibompGetArchitecture.cmake
index 81aa700e3b6db..405bf99414241 100644
--- a/openmp/runtime/cmake/LibompGetArchitecture.cmake
+++ b/openmp/runtime/cmake/LibompGetArchitecture.cmake
@@ -71,7 +71,7 @@ function(libomp_get_architecture return_arch)
   file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c" ${detect_arch_src_txt})
 
   # Try to compile using the C Compiler.  It will always error out with an #error directive, so store error output to ${local_architecture}
-  try_run(run_dummy compile_dummy "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c" COMPILE_OUTPUT_VARIABLE local_architecture)
+  try_compile(compile_dummy "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c" OUTPUT_VARIABLE local_architecture)
 
   # Match the important architecture line and store only that matching string in ${local_architecture}
   string(REGEX MATCH "ARCHITECTURE=([a-zA-Z0-9_]+)" local_architecture "${local_architecture}")
@@ -81,9 +81,6 @@ function(libomp_get_architecture return_arch)
 
   # set the return value to the architecture detected (e.g., 32e, 32, arm, ppc64, etc.)
   set(${return_arch} "${local_architecture}" PARENT_SCOPE)
-
-  # Remove ${detect_arch_src_txt} from cmake/ subdirectory
-  file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c")
 endfunction()
 
 function(libomp_is_aarch64_a64fx return_is_aarch64_a64fx)

>From 64893286b931ce7dd96517b554230e09d2d24268 Mon Sep 17 00:00:00 2001
From: Alexander Grund <alexander.grund at tu-dresden.de>
Date: Wed, 30 Jul 2025 14:08:03 +0200
Subject: [PATCH 2/2] Avoid compatitiblity issues with CMake 3.25+

---
 openmp/runtime/cmake/LibompGetArchitecture.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/openmp/runtime/cmake/LibompGetArchitecture.cmake b/openmp/runtime/cmake/LibompGetArchitecture.cmake
index 405bf99414241..9148bcf355664 100644
--- a/openmp/runtime/cmake/LibompGetArchitecture.cmake
+++ b/openmp/runtime/cmake/LibompGetArchitecture.cmake
@@ -71,7 +71,7 @@ function(libomp_get_architecture return_arch)
   file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c" ${detect_arch_src_txt})
 
   # Try to compile using the C Compiler.  It will always error out with an #error directive, so store error output to ${local_architecture}
-  try_compile(compile_dummy "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c" OUTPUT_VARIABLE local_architecture)
+  try_compile(compile_dummy "${CMAKE_CURRENT_BINARY_DIR}" SOURCES "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c" OUTPUT_VARIABLE local_architecture)
 
   # Match the important architecture line and store only that matching string in ${local_architecture}
   string(REGEX MATCH "ARCHITECTURE=([a-zA-Z0-9_]+)" local_architecture "${local_architecture}")



More information about the Openmp-commits mailing list