[flang-commits] [flang] [llvm] [fakeflang] Also detect CMakeTestGNU.c (PR #210175)

Michael Kruse via flang-commits flang-commits at lists.llvm.org
Thu Jul 16 13:57:58 PDT 2026


https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/210175

Two fixes when using CMake < 3.28 after #209482:

 * In addition to `flang`, also recognize `fakeflang` to determine whether any workaround for CMake not completely supporting Flang is needed. `fakeflang` is used as a shim in #209482.

 * For CMake < 3.24, CMake does not reognize Flang at all and tries other methods to detect to the compiler, including the file `CMakeTestGNU.c`. Make `fakeflang` recognize it as a probe attempt.

This should fix the [openmp-offload-amdgpu-clang-flang](https://lab.llvm.org/buildbot/#/builders/67) buildbot. The buildbot is currently upgrade to a newer CMake version, and the minimum required version of CMake will become 3.31 soon.

>From 4ebdadb74df4a903e4466abe0515040811f22c18 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 16 Jul 2026 19:55:19 +0200
Subject: [PATCH 1/2] [fakeflang] Also detect CMakeTestGNU.c

---
 flang/test/Driver/fakeflang.F       | 6 ++++++
 flang/tools/fakeflang/fakeflang.cpp | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/flang/test/Driver/fakeflang.F b/flang/test/Driver/fakeflang.F
index 1c064b16c323c..f3a4e162293f6 100644
--- a/flang/test/Driver/fakeflang.F
+++ b/flang/test/Driver/fakeflang.F
@@ -3,6 +3,7 @@
 ! RUN: rm -rf %t
 ! RUN: mkdir -p %t
 ! RUN: cp %s %t/CMakeFortranCompilerId.F
+! RUN: cp %s %t/CMakeTestGNU.c
 ! RUN: cp %s %t/compiletest.F
 ! RUN: cd %t
 
@@ -18,6 +19,11 @@
 ! RUN: FileCheck %s --input-file=a.out --check-prefixes=CHECK,MSVC --match-full-lines
 ! RUN: rm a.out
 
+! CMakeTestGNU.c is a fallback used by CMake
+! RUN: fakeflang -E CMakeTestGNU.c --target=aarch64-linux-gnu 2>&1 | FileCheck %s --check-prefix=FAKEWARNING
+! RUN: FileCheck %s --input-file=a.out --check-prefixes=CHECK,GNU --match-full-lines
+! RUN: rm a.out
+
 ! FLANG_BOOTSTRAP_PROBE forces probe mode
 ! RUN: env FLANG_BOOTSTRAP_PROBE=1 fakeflang -v -c --target=x86_64-unknown-linux-gnu compiletest.F 2>&1 | FileCheck %s --check-prefix=FAKEWARNING
 ! RUN: FileCheck %s --input-file=a.out --check-prefixes=CHECK,GNU
diff --git a/flang/tools/fakeflang/fakeflang.cpp b/flang/tools/fakeflang/fakeflang.cpp
index d23a52296dbb1..8235e82e9ade4 100644
--- a/flang/tools/fakeflang/fakeflang.cpp
+++ b/flang/tools/fakeflang/fakeflang.cpp
@@ -67,7 +67,8 @@ static bool isCompilerIdProbe(llvm::ArrayRef<const char *> OrigArgs) {
     return true;
 
   return llvm::any_of(OrigArgs, [](const char *Arg) {
-    return llvm::sys::path::filename(Arg) == "CMakeFortranCompilerId.F";
+    llvm::StringRef fname = llvm::sys::path::filename(Arg);
+    return fname == "CMakeFortranCompilerId.F" || fname == "CMakeTestGNU.c";
   });
 }
 

>From 66a72cd5bd273c11dc13f3ab09645b42736f0656 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 16 Jul 2026 22:40:37 +0200
Subject: [PATCH 2/2] Workaround for compiler named 'fakeflang'

---
 flang-rt/CMakeLists.txt             | 4 +++-
 runtimes/cmake/config-Fortran.cmake | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt
index 33e268c0780f4..5e62ac669e635 100644
--- a/flang-rt/CMakeLists.txt
+++ b/flang-rt/CMakeLists.txt
@@ -27,7 +27,9 @@ set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang")
 # LLVM's requirement is only CMake 3.20, teach CMake 3.20-3.23 how to use Flang.
 if (CMAKE_VERSION VERSION_LESS "3.24")
   cmake_path(GET CMAKE_Fortran_COMPILER STEM _Fortran_COMPILER_STEM)
-  if (_Fortran_COMPILER_STEM STREQUAL "flang-new" OR _Fortran_COMPILER_STEM STREQUAL "flang")
+  if (_Fortran_COMPILER_STEM STREQUAL "flang-new" OR
+      _Fortran_COMPILER_STEM STREQUAL "flang" OR
+      _Fortran_COMPILER_STEM STREQUAL "fakeflang")
     include(CMakeForceCompiler)
     CMAKE_FORCE_Fortran_COMPILER("${CMAKE_Fortran_COMPILER}" "LLVMFlang")
 
diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake
index 8748c1b8fc35f..ba683c3ce28e6 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -90,7 +90,9 @@ if (CMAKE_Fortran_COMPILER)
   # Workarounds for older versions of CMake not recognizing FLang. Hence, we
   # cannot use CMAKE_Fortran_COMPILER_ID.
   cmake_path(GET CMAKE_Fortran_COMPILER STEM _Fortran_COMPILER_STEM)
-  if (_Fortran_COMPILER_STEM STREQUAL "flang-new" OR _Fortran_COMPILER_STEM STREQUAL "flang")
+  if (_Fortran_COMPILER_STEM STREQUAL "flang-new" OR
+      _Fortran_COMPILER_STEM STREQUAL "flang" OR
+      _Fortran_COMPILER_STEM STREQUAL "fakeflang")
     # CMake 3.24 is the first version of CMake that directly recognizes Flang.
     # LLVM's requirement is only CMake 3.20, teach CMake 3.20-3.23 how to use Flang, if used.
     if (CMAKE_VERSION VERSION_LESS "3.24")



More information about the flang-commits mailing list