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

Alexander Grund via Openmp-commits openmp-commits at lists.llvm.org
Wed Jul 30 04:38:41 PDT 2025


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

>From e987ff44cffbcc9043a235723106bb5abd9e9a5a 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] 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)



More information about the Openmp-commits mailing list