Skip to content

Conversation

@jplehr
Copy link
Contributor

@jplehr jplehr commented Nov 25, 2025

@jplehr jplehr requested a review from Meinersbur November 25, 2025 11:56
@jplehr jplehr requested a review from a team as a code owner November 25, 2025 11:56
@llvmbot llvmbot added cmake Build system in general and CMake in particular clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' flang:driver flang Flang issues not falling into any other category flang:fir-hlfir flang:openmp flang:semantics openmp:libomp OpenMP host runtime labels Nov 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2025

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-fir-hlfir

Author: Jan Patrick Lehr (jplehr)

Changes

Reverts llvm/llvm-project#137828

Buildbot error in https://lab.llvm.org/staging/#/builders/105/builds/37275


Patch is 88.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/169489.diff

64 Files Affected:

  • (modified) clang/include/clang/Driver/ToolChain.h (-4)
  • (modified) clang/include/clang/Options/Options.td (+1-1)
  • (modified) clang/lib/Driver/Driver.cpp (-11)
  • (modified) clang/lib/Driver/ToolChain.cpp (-6)
  • (modified) clang/lib/Driver/ToolChains/Flang.cpp (-8)
  • (modified) flang-rt/CMakeLists.txt (+86-11)
  • (modified) flang-rt/cmake/modules/AddFlangRT.cmake (+4-25)
  • (modified) flang-rt/cmake/modules/AddFlangRTOffload.cmake (+4-10)
  • (removed) flang-rt/cmake/modules/FlangRTIntrospection.cmake (-37)
  • (renamed) flang-rt/cmake/modules/GetToolchainDirs.cmake (-11)
  • (modified) flang-rt/lib/runtime/CMakeLists.txt (+13-102)
  • (modified) flang-rt/test/lit.site.cfg.py.in (+1-1)
  • (modified) flang-rt/unittests/CMakeLists.txt (+3-2)
  • (modified) flang/CMakeLists.txt (+1)
  • (modified) flang/include/flang/Frontend/CompilerInvocation.h (-7)
  • (modified) flang/lib/Frontend/CompilerInvocation.cpp (+13-13)
  • (modified) flang/lib/Semantics/semantics.cpp (+5-8)
  • (added) flang/module/.clang-format (+1)
  • (renamed) flang/module/__cuda_builtins.f90 ()
  • (renamed) flang/module/__cuda_device.f90 ()
  • (renamed) flang/module/__fortran_builtins.f90 (+1-1)
  • (renamed) flang/module/__fortran_ieee_exceptions.f90 ()
  • (renamed) flang/module/__fortran_type_info.f90 ()
  • (renamed) flang/module/__ppc_intrinsics.f90 ()
  • (renamed) flang/module/__ppc_types.f90 ()
  • (renamed) flang/module/cooperative_groups.f90 (-1)
  • (renamed) flang/module/cudadevice.f90 ()
  • (renamed) flang/module/ieee_arithmetic.f90 (+1-1)
  • (renamed) flang/module/ieee_exceptions.f90 ()
  • (renamed) flang/module/ieee_features.f90 ()
  • (renamed) flang/module/iso_c_binding.f90 ()
  • (renamed) flang/module/iso_fortran_env.f90 ()
  • (renamed) flang/module/iso_fortran_env_impl.f90 ()
  • (renamed) flang/module/mma.f90 ()
  • (modified) flang/test/CMakeLists.txt (+3-28)
  • (modified) flang/test/Driver/Inputs/ieee_arithmetic.mod (-1)
  • (modified) flang/test/Driver/Inputs/iso_fortran_env.mod (-1)
  • (removed) flang/test/Driver/intrinsic-module-path.F90 (-55)
  • (added) flang/test/Driver/intrinsic-module-path.f90 (+23)
  • (modified) flang/test/Driver/lto-fatlto.f90 (+2-2)
  • (modified) flang/test/Driver/pp-fixed-form.f90 (+2-2)
  • (modified) flang/test/Lower/HLFIR/type-bound-call-mismatch.f90 (+1-1)
  • (modified) flang/test/Lower/OpenMP/simd_aarch64.f90 (+1-6)
  • (modified) flang/test/Lower/OpenMP/target-enter-data-default-openmp52.f90 (+2-2)
  • (modified) flang/test/Preprocessing/fixed-free.f (+1-1)
  • (modified) flang/test/Preprocessing/no-pp-if.f90 (+1-1)
  • (modified) flang/test/Semantics/bug163242.f90 (+1-1)
  • (modified) flang/test/Semantics/bug164303.f90 (+1-1)
  • (modified) flang/test/lit.cfg.py (+13-81)
  • (modified) flang/test/lit.site.cfg.py.in (+6-3)
  • (modified) flang/tools/CMakeLists.txt (+1)
  • (modified) flang/tools/bbc/bbc.cpp (+8-5)
  • (added) flang/tools/f18/CMakeLists.txt (+170)
  • (added) flang/tools/f18/dump.cpp (+42)
  • (modified) llvm/runtimes/CMakeLists.txt (+11-13)
  • (modified) openmp/CMakeLists.txt (-6)
  • (modified) openmp/runtime/CMakeLists.txt (+7-1)
  • (added) openmp/runtime/cmake/LibompCheckFortranFlag.cmake (+29)
  • (modified) openmp/runtime/cmake/LibompHandleFlags.cmake (+11)
  • (modified) openmp/runtime/cmake/config-ix.cmake (+4)
  • (modified) openmp/runtime/src/CMakeLists.txt (+43-20)
  • (modified) openmp/runtime/test/lit.cfg (-1)
  • (modified) openmp/runtime/test/lit.site.cfg.in (-1)
  • (modified) runtimes/CMakeLists.txt (+11-212)
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index 26af88242eb3e..1425714d34110 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -538,10 +538,6 @@ class ToolChain {
   // Returns Triple without the OSs version.
   llvm::Triple getTripleWithoutOSVersion() const;
 
-  /// Returns the target-specific path for Flang's intrinsic modules in the
-  /// resource directory if it exists.
-  std::optional<std::string> getDefaultIntrinsicModuleDir() const;
-
   // Returns the target specific runtime path if it exists.
   std::optional<std::string> getRuntimePath() const;
 
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 0e88656c5e1bc..a8fc1c4326cc5 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -6082,7 +6082,7 @@ def prebind : Flag<["-"], "prebind">;
 def preload : Flag<["-"], "preload">;
 def print_file_name_EQ : Joined<["-", "--"], "print-file-name=">,
   HelpText<"Print the full library path of <file>">, MetaVarName<"<file>">,
-  Visibility<[ClangOption, FlangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption]>;
 def print_ivar_layout : Flag<["-"], "print-ivar-layout">,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Enable Objective-C Ivar layout bitmap print trace">,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 781bc74466da1..de8d4601210ae 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6602,17 +6602,6 @@ std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const {
   if (llvm::sys::fs::exists(Twine(P)))
     return std::string(P);
 
-  // With Flang, also look for instrinsic modules
-  if (IsFlangMode()) {
-    if (std::optional<std::string> IntrPath =
-            TC.getDefaultIntrinsicModuleDir()) {
-      SmallString<128> P(*IntrPath);
-      llvm::sys::path::append(P, Name);
-      if (llvm::sys::fs::exists(Twine(P)))
-        return std::string(P);
-    }
-  }
-
   SmallString<128> D(Dir);
   llvm::sys::path::append(D, "..", Name);
   if (llvm::sys::fs::exists(Twine(D)))
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index f8520725b9b03..77a2c73f0d446 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1020,12 +1020,6 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   return {};
 }
 
-std::optional<std::string> ToolChain::getDefaultIntrinsicModuleDir() const {
-  SmallString<128> P(D.ResourceDir);
-  llvm::sys::path::append(P, "finclude", "flang");
-  return getTargetSubDirPath(P);
-}
-
 std::optional<std::string> ToolChain::getRuntimePath() const {
   SmallString<128> P(D.ResourceDir);
   llvm::sys::path::append(P, "lib");
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index bac421bb86f49..cc4755cd6a9b0 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -1060,14 +1060,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   CmdArgs.push_back("-resource-dir");
   CmdArgs.push_back(D.ResourceDir.c_str());
 
-  // Default intrinsic module dirs must be added after any user-provided
-  // -fintrinsic-modules-path to have lower precedence
-  if (std::optional<std::string> IntrModPath =
-          TC.getDefaultIntrinsicModuleDir()) {
-    CmdArgs.push_back("-fintrinsic-modules-path");
-    CmdArgs.push_back(Args.MakeArgString(*IntrModPath));
-  }
-
   // Offloading related options
   addOffloadOptions(C, Inputs, JA, Args, CmdArgs);
 
diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt
index db0d87d91ea83..50b8e834776fb 100644
--- a/flang-rt/CMakeLists.txt
+++ b/flang-rt/CMakeLists.txt
@@ -23,6 +23,40 @@ set(FLANG_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
 set(FLANG_RT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
 set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang")
 
+# 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 (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")
+    include(CMakeForceCompiler)
+    CMAKE_FORCE_Fortran_COMPILER("${CMAKE_Fortran_COMPILER}" "LLVMFlang")
+
+    set(CMAKE_Fortran_COMPILER_ID "LLVMFlang")
+    set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
+
+    set(CMAKE_Fortran_SUBMODULE_SEP "-")
+    set(CMAKE_Fortran_SUBMODULE_EXT ".mod")
+
+    set(CMAKE_Fortran_PREPROCESS_SOURCE
+      "<CMAKE_Fortran_COMPILER> -cpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+
+    set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form")
+    set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form")
+
+    set(CMAKE_Fortran_MODDIR_FLAG "-module-dir")
+
+    set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp")
+    set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nocpp")
+    set(CMAKE_Fortran_POSTPROCESS_FLAG "-ffixed-line-length-72")
+
+    set(CMAKE_Fortran_COMPILE_OPTIONS_TARGET "--target=")
+
+    set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
+    set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",")
+  endif ()
+endif ()
+enable_language(Fortran)
+
 
 list(APPEND CMAKE_MODULE_PATH
     "${FLANG_RT_SOURCE_DIR}/cmake/modules"
@@ -31,24 +65,69 @@ list(APPEND CMAKE_MODULE_PATH
 include(AddFlangRT)
 include(GetToolchainDirs)
 include(FlangCommon)
-include(FlangRTIntrospection)
 include(HandleCompilerRT)
 include(ExtendPath)
-include(CheckFortranSourceCompiles)
-include(CMakePushCheckState)
 
 
 ############################
 # Build Mode Introspection #
 ############################
 
+# Determine whether we are in the runtimes/runtimes-bins directory of a
+# bootstrap build.
+set(LLVM_TREE_AVAILABLE OFF)
+if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSION)
+  set(LLVM_TREE_AVAILABLE ON)
+endif()
+
 # Path to LLVM development tools (FileCheck, llvm-lit, not, ...)
 set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin")
 
-# Fortran compiler not optional for building Flang-RT
-enable_language(Fortran)
-
-flang_module_fortran_enable()
+# Determine build and install paths.
+# The build path is absolute, but the install dir is relative, CMake's install
+# command has to apply CMAKE_INSTALL_PREFIX itself.
+get_toolchain_library_subdir(toolchain_lib_subdir)
+if (LLVM_TREE_AVAILABLE)
+  # In a bootstrap build emit the libraries into a default search path in the
+  # build directory of the just-built compiler. This allows using the
+  # just-built compiler without specifying paths to runtime libraries.
+  #
+  # Despite Clang in the name, get_clang_resource_dir does not depend on Clang
+  # being added to the build. Flang uses the same resource dir as clang.
+  include(GetClangResourceDir)
+  get_clang_resource_dir(FLANG_RT_OUTPUT_RESOURCE_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR}/..")
+  get_clang_resource_dir(FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT)
+
+  extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" "${toolchain_lib_subdir}")
+else ()
+  # In a standalone runtimes build, do not write into LLVM_BINARY_DIR. It may be
+  # read-only and/or shared by multiple runtimes with different build
+  # configurations (e.g. Debug/Release). Use the runtime's own lib dir like any
+  # non-toolchain library.
+  # For the install prefix, still use the resource dir assuming that Flang will
+  # be installed there using the same prefix. This is to not have a difference
+  # between bootstrap and standalone runtimes builds.
+  set(FLANG_RT_OUTPUT_RESOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+  set(FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT "lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
+
+  extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" "lib${LLVM_LIBDIR_SUFFIX}")
+endif ()
+set(FLANG_RT_INSTALL_RESOURCE_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT}"
+    CACHE PATH "Path to install runtime libraries to (default: clang resource dir)")
+extend_path(FLANG_RT_INSTALL_RESOURCE_LIB_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}")
+cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_DIR)
+cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_PATH)
+# FIXME: For the libflang_rt.so, the toolchain resource lib dir is not a good
+#        destination because it is not a ld.so default search path.
+#        The machine where the executable is eventually executed may not be the
+#        machine where the Flang compiler and its resource dir is installed, so
+#        setting RPath by the driver is not an solution. It should belong into
+#        /usr/lib/<triple>/libflang_rt.so, like e.g. libgcc_s.so.
+#        But the linker as invoked by the Flang driver also requires
+#        libflang_rt.so to be found when linking and the resource lib dir is
+#        the only reliable location.
+cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_LIB_DIR)
+cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
 
 
 #################
@@ -155,10 +234,6 @@ check_cxx_source_compiles(
   "
   HAVE_DECL_STRERROR_S)
 
-# Look for support of REAL(16), if not already defined via command
-# line via -DFORTRAN_SUPPORTS_REAL16=YES/NO
-check_fortran_quadmath_support()
-
 # Search for clang_rt.builtins library. Need in addition to msvcrt.
 if (WIN32)
   find_compiler_rt_library(builtins FLANG_RT_BUILTINS_LIBRARY)
diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake
index b3f2cd07c0aed..923507764d691 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -190,12 +190,6 @@ function (add_flangrt_library name)
     endif ()
   endif ()
 
-  if (build_object)
-    add_library(${name}.compile ALIAS "${name_object}")
-  else ()
-    add_library(${name}.compile ALIAS "${default_target}")
-  endif ()
-
   foreach (tgtname IN LISTS libtargets)
     if (NOT WIN32)
       # Use same stem name for .a and .so. Common in UNIX environments.
@@ -225,17 +219,6 @@ function (add_flangrt_library name)
     # Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else.
     target_compile_features(${tgtname} PRIVATE cxx_std_17)
 
-    target_compile_options(${tgtname} PRIVATE
-      # Always enable preprocessor regardless of file extention
-      "$<$<COMPILE_LANGUAGE:Fortran>:-cpp>"
-
-      # Missing type descriptors are expected for intrinsic modules 
-      "$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-mmlir;SHELL:-ignore-missing-type-desc>"
-
-      # Flang bug workaround: Reformating of cooked token buffer causes identifier to be split between lines
-      "$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-Xflang;SHELL:-fno-reformat>"
-    )
-
     # When building the flang runtime if LTO is enabled the archive file
     # contains LLVM IR rather than object code. Currently flang is not
     # LTO aware so cannot link this file to compiled Fortran code.
@@ -243,10 +226,6 @@ function (add_flangrt_library name)
       target_compile_options(${tgtname} PRIVATE -fno-lto)
     endif ()
 
-    if (FORTRAN_SUPPORTS_REAL16)
-      target_compile_definitions(${tgtname} PRIVATE FLANG_SUPPORT_R16=1)
-    endif ()
-
     # Use compiler-specific options to disable exceptions and RTTI.
     if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
       target_compile_options(${tgtname} PRIVATE
@@ -365,13 +344,13 @@ function (add_flangrt_library name)
     if (ARG_INSTALL_WITH_TOOLCHAIN)
       set_target_properties(${tgtname}
         PROPERTIES
-          ARCHIVE_OUTPUT_DIRECTORY "${RUNTIMES_OUTPUT_RESOURCE_LIB_DIR}"
-          LIBRARY_OUTPUT_DIRECTORY "${RUNTIMES_OUTPUT_RESOURCE_LIB_DIR}"
+          ARCHIVE_OUTPUT_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_LIB_DIR}"
+          LIBRARY_OUTPUT_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_LIB_DIR}"
         )
 
       install(TARGETS ${tgtname}
-          ARCHIVE DESTINATION "${RUNTIMES_INSTALL_RESOURCE_LIB_PATH}"
-          LIBRARY DESTINATION "${RUNTIMES_INSTALL_RESOURCE_LIB_PATH}"
+          ARCHIVE DESTINATION "${FLANG_RT_INSTALL_RESOURCE_LIB_PATH}"
+          LIBRARY DESTINATION "${FLANG_RT_INSTALL_RESOURCE_LIB_PATH}"
         )
     endif ()
 
diff --git a/flang-rt/cmake/modules/AddFlangRTOffload.cmake b/flang-rt/cmake/modules/AddFlangRTOffload.cmake
index 4a6f047a86af2..cbc69f3a9656a 100644
--- a/flang-rt/cmake/modules/AddFlangRTOffload.cmake
+++ b/flang-rt/cmake/modules/AddFlangRTOffload.cmake
@@ -88,16 +88,16 @@ macro(enable_omp_offload_compilation name files)
         "${FLANG_RT_DEVICE_ARCHITECTURES}"
         )
 
-      set(OMP_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:C,CXX>:
+      set(OMP_COMPILE_OPTIONS
         -fopenmp
         -fvisibility=hidden
         -fopenmp-cuda-mode
         --offload-arch=${compile_for_architectures}
         # Force LTO for the device part.
         -foffload-lto
-        >)
-      set_property(SOURCE ${files} APPEND
-        PROPERTY COMPILE_DEFINITIONS ${OMP_COMPILE_OPTIONS}
+        )
+      set_source_files_properties(${files} PROPERTIES COMPILE_OPTIONS
+        "${OMP_COMPILE_OPTIONS}"
         )
       target_link_options(${name}.static PUBLIC ${OMP_COMPILE_OPTIONS})
 
@@ -105,12 +105,6 @@ macro(enable_omp_offload_compilation name files)
       set_source_files_properties(${files}
         PROPERTIES COMPILE_DEFINITIONS OMP_OFFLOAD_BUILD
         )
-
-     # If building flang-rt together with libomp, ensure that libomp is built first and found because -fopenmp will try to link it.
-     if (TARGET omp)
-       add_dependencies(${name} omp)
-       target_link_options(${name}.static PUBLIC "-L$<TARGET_FILE_DIR:omp>")
-     endif ()
     else()
       message(FATAL_ERROR
         "Flang-rt build with OpenMP offload is not supported for these compilers:\n"
diff --git a/flang-rt/cmake/modules/FlangRTIntrospection.cmake b/flang-rt/cmake/modules/FlangRTIntrospection.cmake
deleted file mode 100644
index ddec624e320e7..0000000000000
--- a/flang-rt/cmake/modules/FlangRTIntrospection.cmake
+++ /dev/null
@@ -1,37 +0,0 @@
-#===-- cmake/modules/FlangRTIntrospection.cmake ----------------------------===#
-#
-# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-#===------------------------------------------------------------------------===#
-
-
-# Check whether the Fortran compiler supports real(16)/quadmath types
-#
-# Implementation notes:
-#  * FORTRAN_SUPPORTS_REAL16 can be set externally in a bootstrapping-runtimes
-#    build to ensure consistency of real(16) support between compiler and
-#    runtime.
-#
-#  * Does not work with Flang and CMake < 3.24
-#
-#  * This is intentionally wrapped in a function to get its own namespace for
-#    CMAKE_REQUIRED_FLAGS and CMAKE_TRY_COMPILE_TARGET_TYPE. In particular,
-#    cmake_pop_check_state() does not reset CMAKE_TRY_COMPILE_TARGET_TYPE,
-#    causing later try_compile invocations to fail. If you see
-#    enable_language(CUDA) failing because CMAKE_RANLIB is empty, this is the
-#    reason.
-function (check_fortran_quadmath_support)
-  cmake_push_check_state(RESET)
-  set(CMAKE_REQUIRED_FLAGS "-ffree-form")
-  set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") # Skip link step
-  check_fortran_source_compiles([[
-      subroutine test_quadmath
-        real(16) :: var1
-      end
-    ]]
-    FORTRAN_SUPPORTS_REAL16
-  )
-  cmake_pop_check_state()
-endfunction ()
diff --git a/cmake/Modules/GetToolchainDirs.cmake b/flang-rt/cmake/modules/GetToolchainDirs.cmake
similarity index 94%
rename from cmake/Modules/GetToolchainDirs.cmake
rename to flang-rt/cmake/modules/GetToolchainDirs.cmake
index ce2f8c294b2bc..fba12502b5946 100644
--- a/cmake/Modules/GetToolchainDirs.cmake
+++ b/flang-rt/cmake/modules/GetToolchainDirs.cmake
@@ -47,17 +47,6 @@ function (get_toolchain_library_subdir outvar)
 endfunction ()
 
 
-# Corresponds to Flang's ToolChain::getDefaultIntrinsicModuleDir().
-function (get_toolchain_module_subdir outvar)
-  set(outval "finclude/flang")
-
-  get_toolchain_arch_dirname(arch_dirname)
-  set(outval "${outval}/${arch_dirname}")
-
-  set(${outvar} "${outval}" PARENT_SCOPE)
-endfunction ()
-
-
 # Corresponds to Clang's ToolChain::getOSLibName(). Adapted from Compiler-RT.
 function (get_toolchain_os_dirname outvar)
   if (ANDROID)
diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index a678055430233..e8f70bd544e0b 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -12,13 +12,6 @@ find_package(Backtrace)
 set(HAVE_BACKTRACE ${Backtrace_FOUND})
 set(BACKTRACE_HEADER ${Backtrace_HEADER})
 
-# Module sources that are required by other modules
-set(intrinsics_sources
-  __fortran_builtins.f90
-  __cuda_builtins.f90
-)
-
-
 # List of files that are buildable for all devices.
 set(supported_sources
   ${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
@@ -80,16 +73,7 @@ set(supported_sources
 
 # List of source not used for GPU offloading.
 set(host_sources
-  __fortran_ieee_exceptions.f90
-  __fortran_type_info.f90
-  iso_fortran_env.f90
-  ieee_arithmetic.f90
-  ieee_exceptions.f90
-  ieee_features.f90
-  iso_c_binding.f90
-  iso_fortran_env_impl.f90
-  iso_fortran_env.f90
-
+  ${FLANG_SOURCE_DIR}/module/iso_fortran_env_impl.f90
   command.cpp
   complex-powi.cpp
   complex-reduction.c
@@ -104,32 +88,8 @@ set(host_sources
   temporary-stack.cpp
   time-intrinsic.cpp
   unit-map.cpp
-
-  __cuda_device.f90
-  cooperative_groups.f90
-  cudadevice.f90
 )
 
-if (LLVM_TARGET_TRIPLE MATCHES "^ppc|^powerpc")
-  list(APPEND intrinsics_sources
-    __ppc_types.f90
-  )
-  list(APPEND host_sources
-    __ppc_intrinsics.f90
-    mma.f90
-  )
-endif ()
-
-# Compile as CUDA-Fortran, not directly supported by CMake
-set_property(SOURCE
-    __cuda_device.f90
-    cooperative_groups.f90
-    cudadevice.f90
-  APPEND PROPERTY
-    COMPILE_OPTIONS --offload-host-only -xcuda
-)
-
-
 # Sources that can be compiled directly for the GPU.
 set(gpu_sources
   ${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
@@ -215,42 +175,19 @@ else ()
   set(f128_sources "")
 endif ()
 
-if (LLVM_RUNTIMES_TARGET MATCHES "^amdgcn|^nvptx")
+if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
   set(sources ${gpu_sources})
+elseif(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
+  set(sources ${supported_sources})
 else ()
   set(sources ${supported_sources} ${host_sources} ${f128_sources})
 endif ()
 
 
-# check-flang depends on this to build intrinsic modules
-if (NOT TARGET flang-rt-mod)
-  add_custom_target(flang-rt-mod)
-endif ()
-
 if (NOT WIN32)
-  # 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.
-  add_flangrt_library(flang_rt.intrinsics.obj OBJECT
-    ${intrinsics_sources}
-  )
-
-  # This barrier exists to force all of the intrinsic modules of
-  # flang_rt.intrinsics.obj to be built before anything that depends on it.
-  # Without it, CMake/Ninja seem to think that the modules of
-  # flang_rt.intrinsics.obj can be built concurrently to those in
-  # flang_rt.runtime.
-  add_custom_target(flang_rt.intrinsics
-    COMMENT "Intrinsic module dependency barrier"
-  )
-  add_dependencies(flang_rt.intrinsics flang_rt.intrinsics.obj)
-
   add_flangrt_library(flang_rt.runtime STATIC SHARED
-    ${sources} $<TARGET_OBJECTS:flang_rt.intrinsics.obj>
-    LINK_LIBRARIES flang_rt.intrinsics.obj ${Backtrace_LIBRARY}
+    ${sources}
+    LINK_LIBRARIES ${Backtrace_LIBRARY}
     INSTALL_WITH_TOOLCHAIN
     ADDITIONAL_HEADERS ${public_headers} ${private_headers}
   )
@@ -261,13 +198,6 @@ if (NOT WIN32)
   # Select a default runtime, which is used for unit and regression tests.
   get_target_property(default_target flang_rt.runtime.default ALIASED_TARGET)
   add_library(flang_rt.runtime.unittest ALIAS "${default_target}")
-
-  # Select a target that compiles the s...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2025

@llvm/pr-subscribers-flang-driver

Author: Jan Patrick Lehr (jplehr)

Changes

Reverts llvm/llvm-project#137828

Buildbot error in https://lab.llvm.org/staging/#/builders/105/builds/37275


Patch is 88.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/169489.diff

64 Files Affected:

  • (modified) clang/include/clang/Driver/ToolChain.h (-4)
  • (modified) clang/include/clang/Options/Options.td (+1-1)
  • (modified) clang/lib/Driver/Driver.cpp (-11)
  • (modified) clang/lib/Driver/ToolChain.cpp (-6)
  • (modified) clang/lib/Driver/ToolChains/Flang.cpp (-8)
  • (modified) flang-rt/CMakeLists.txt (+86-11)
  • (modified) flang-rt/cmake/modules/AddFlangRT.cmake (+4-25)
  • (modified) flang-rt/cmake/modules/AddFlangRTOffload.cmake (+4-10)
  • (removed) flang-rt/cmake/modules/FlangRTIntrospection.cmake (-37)
  • (renamed) flang-rt/cmake/modules/GetToolchainDirs.cmake (-11)
  • (modified) flang-rt/lib/runtime/CMakeLists.txt (+13-102)
  • (modified) flang-rt/test/lit.site.cfg.py.in (+1-1)
  • (modified) flang-rt/unittests/CMakeLists.txt (+3-2)
  • (modified) flang/CMakeLists.txt (+1)
  • (modified) flang/include/flang/Frontend/CompilerInvocation.h (-7)
  • (modified) flang/lib/Frontend/CompilerInvocation.cpp (+13-13)
  • (modified) flang/lib/Semantics/semantics.cpp (+5-8)
  • (added) flang/module/.clang-format (+1)
  • (renamed) flang/module/__cuda_builtins.f90 ()
  • (renamed) flang/module/__cuda_device.f90 ()
  • (renamed) flang/module/__fortran_builtins.f90 (+1-1)
  • (renamed) flang/module/__fortran_ieee_exceptions.f90 ()
  • (renamed) flang/module/__fortran_type_info.f90 ()
  • (renamed) flang/module/__ppc_intrinsics.f90 ()
  • (renamed) flang/module/__ppc_types.f90 ()
  • (renamed) flang/module/cooperative_groups.f90 (-1)
  • (renamed) flang/module/cudadevice.f90 ()
  • (renamed) flang/module/ieee_arithmetic.f90 (+1-1)
  • (renamed) flang/module/ieee_exceptions.f90 ()
  • (renamed) flang/module/ieee_features.f90 ()
  • (renamed) flang/module/iso_c_binding.f90 ()
  • (renamed) flang/module/iso_fortran_env.f90 ()
  • (renamed) flang/module/iso_fortran_env_impl.f90 ()
  • (renamed) flang/module/mma.f90 ()
  • (modified) flang/test/CMakeLists.txt (+3-28)
  • (modified) flang/test/Driver/Inputs/ieee_arithmetic.mod (-1)
  • (modified) flang/test/Driver/Inputs/iso_fortran_env.mod (-1)
  • (removed) flang/test/Driver/intrinsic-module-path.F90 (-55)
  • (added) flang/test/Driver/intrinsic-module-path.f90 (+23)
  • (modified) flang/test/Driver/lto-fatlto.f90 (+2-2)
  • (modified) flang/test/Driver/pp-fixed-form.f90 (+2-2)
  • (modified) flang/test/Lower/HLFIR/type-bound-call-mismatch.f90 (+1-1)
  • (modified) flang/test/Lower/OpenMP/simd_aarch64.f90 (+1-6)
  • (modified) flang/test/Lower/OpenMP/target-enter-data-default-openmp52.f90 (+2-2)
  • (modified) flang/test/Preprocessing/fixed-free.f (+1-1)
  • (modified) flang/test/Preprocessing/no-pp-if.f90 (+1-1)
  • (modified) flang/test/Semantics/bug163242.f90 (+1-1)
  • (modified) flang/test/Semantics/bug164303.f90 (+1-1)
  • (modified) flang/test/lit.cfg.py (+13-81)
  • (modified) flang/test/lit.site.cfg.py.in (+6-3)
  • (modified) flang/tools/CMakeLists.txt (+1)
  • (modified) flang/tools/bbc/bbc.cpp (+8-5)
  • (added) flang/tools/f18/CMakeLists.txt (+170)
  • (added) flang/tools/f18/dump.cpp (+42)
  • (modified) llvm/runtimes/CMakeLists.txt (+11-13)
  • (modified) openmp/CMakeLists.txt (-6)
  • (modified) openmp/runtime/CMakeLists.txt (+7-1)
  • (added) openmp/runtime/cmake/LibompCheckFortranFlag.cmake (+29)
  • (modified) openmp/runtime/cmake/LibompHandleFlags.cmake (+11)
  • (modified) openmp/runtime/cmake/config-ix.cmake (+4)
  • (modified) openmp/runtime/src/CMakeLists.txt (+43-20)
  • (modified) openmp/runtime/test/lit.cfg (-1)
  • (modified) openmp/runtime/test/lit.site.cfg.in (-1)
  • (modified) runtimes/CMakeLists.txt (+11-212)
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index 26af88242eb3e..1425714d34110 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -538,10 +538,6 @@ class ToolChain {
   // Returns Triple without the OSs version.
   llvm::Triple getTripleWithoutOSVersion() const;
 
-  /// Returns the target-specific path for Flang's intrinsic modules in the
-  /// resource directory if it exists.
-  std::optional<std::string> getDefaultIntrinsicModuleDir() const;
-
   // Returns the target specific runtime path if it exists.
   std::optional<std::string> getRuntimePath() const;
 
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 0e88656c5e1bc..a8fc1c4326cc5 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -6082,7 +6082,7 @@ def prebind : Flag<["-"], "prebind">;
 def preload : Flag<["-"], "preload">;
 def print_file_name_EQ : Joined<["-", "--"], "print-file-name=">,
   HelpText<"Print the full library path of <file>">, MetaVarName<"<file>">,
-  Visibility<[ClangOption, FlangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption]>;
 def print_ivar_layout : Flag<["-"], "print-ivar-layout">,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Enable Objective-C Ivar layout bitmap print trace">,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 781bc74466da1..de8d4601210ae 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6602,17 +6602,6 @@ std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const {
   if (llvm::sys::fs::exists(Twine(P)))
     return std::string(P);
 
-  // With Flang, also look for instrinsic modules
-  if (IsFlangMode()) {
-    if (std::optional<std::string> IntrPath =
-            TC.getDefaultIntrinsicModuleDir()) {
-      SmallString<128> P(*IntrPath);
-      llvm::sys::path::append(P, Name);
-      if (llvm::sys::fs::exists(Twine(P)))
-        return std::string(P);
-    }
-  }
-
   SmallString<128> D(Dir);
   llvm::sys::path::append(D, "..", Name);
   if (llvm::sys::fs::exists(Twine(D)))
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index f8520725b9b03..77a2c73f0d446 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1020,12 +1020,6 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   return {};
 }
 
-std::optional<std::string> ToolChain::getDefaultIntrinsicModuleDir() const {
-  SmallString<128> P(D.ResourceDir);
-  llvm::sys::path::append(P, "finclude", "flang");
-  return getTargetSubDirPath(P);
-}
-
 std::optional<std::string> ToolChain::getRuntimePath() const {
   SmallString<128> P(D.ResourceDir);
   llvm::sys::path::append(P, "lib");
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index bac421bb86f49..cc4755cd6a9b0 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -1060,14 +1060,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   CmdArgs.push_back("-resource-dir");
   CmdArgs.push_back(D.ResourceDir.c_str());
 
-  // Default intrinsic module dirs must be added after any user-provided
-  // -fintrinsic-modules-path to have lower precedence
-  if (std::optional<std::string> IntrModPath =
-          TC.getDefaultIntrinsicModuleDir()) {
-    CmdArgs.push_back("-fintrinsic-modules-path");
-    CmdArgs.push_back(Args.MakeArgString(*IntrModPath));
-  }
-
   // Offloading related options
   addOffloadOptions(C, Inputs, JA, Args, CmdArgs);
 
diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt
index db0d87d91ea83..50b8e834776fb 100644
--- a/flang-rt/CMakeLists.txt
+++ b/flang-rt/CMakeLists.txt
@@ -23,6 +23,40 @@ set(FLANG_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
 set(FLANG_RT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
 set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang")
 
+# 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 (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")
+    include(CMakeForceCompiler)
+    CMAKE_FORCE_Fortran_COMPILER("${CMAKE_Fortran_COMPILER}" "LLVMFlang")
+
+    set(CMAKE_Fortran_COMPILER_ID "LLVMFlang")
+    set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
+
+    set(CMAKE_Fortran_SUBMODULE_SEP "-")
+    set(CMAKE_Fortran_SUBMODULE_EXT ".mod")
+
+    set(CMAKE_Fortran_PREPROCESS_SOURCE
+      "<CMAKE_Fortran_COMPILER> -cpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+
+    set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form")
+    set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form")
+
+    set(CMAKE_Fortran_MODDIR_FLAG "-module-dir")
+
+    set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp")
+    set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nocpp")
+    set(CMAKE_Fortran_POSTPROCESS_FLAG "-ffixed-line-length-72")
+
+    set(CMAKE_Fortran_COMPILE_OPTIONS_TARGET "--target=")
+
+    set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
+    set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",")
+  endif ()
+endif ()
+enable_language(Fortran)
+
 
 list(APPEND CMAKE_MODULE_PATH
     "${FLANG_RT_SOURCE_DIR}/cmake/modules"
@@ -31,24 +65,69 @@ list(APPEND CMAKE_MODULE_PATH
 include(AddFlangRT)
 include(GetToolchainDirs)
 include(FlangCommon)
-include(FlangRTIntrospection)
 include(HandleCompilerRT)
 include(ExtendPath)
-include(CheckFortranSourceCompiles)
-include(CMakePushCheckState)
 
 
 ############################
 # Build Mode Introspection #
 ############################
 
+# Determine whether we are in the runtimes/runtimes-bins directory of a
+# bootstrap build.
+set(LLVM_TREE_AVAILABLE OFF)
+if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSION)
+  set(LLVM_TREE_AVAILABLE ON)
+endif()
+
 # Path to LLVM development tools (FileCheck, llvm-lit, not, ...)
 set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin")
 
-# Fortran compiler not optional for building Flang-RT
-enable_language(Fortran)
-
-flang_module_fortran_enable()
+# Determine build and install paths.
+# The build path is absolute, but the install dir is relative, CMake's install
+# command has to apply CMAKE_INSTALL_PREFIX itself.
+get_toolchain_library_subdir(toolchain_lib_subdir)
+if (LLVM_TREE_AVAILABLE)
+  # In a bootstrap build emit the libraries into a default search path in the
+  # build directory of the just-built compiler. This allows using the
+  # just-built compiler without specifying paths to runtime libraries.
+  #
+  # Despite Clang in the name, get_clang_resource_dir does not depend on Clang
+  # being added to the build. Flang uses the same resource dir as clang.
+  include(GetClangResourceDir)
+  get_clang_resource_dir(FLANG_RT_OUTPUT_RESOURCE_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR}/..")
+  get_clang_resource_dir(FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT)
+
+  extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" "${toolchain_lib_subdir}")
+else ()
+  # In a standalone runtimes build, do not write into LLVM_BINARY_DIR. It may be
+  # read-only and/or shared by multiple runtimes with different build
+  # configurations (e.g. Debug/Release). Use the runtime's own lib dir like any
+  # non-toolchain library.
+  # For the install prefix, still use the resource dir assuming that Flang will
+  # be installed there using the same prefix. This is to not have a difference
+  # between bootstrap and standalone runtimes builds.
+  set(FLANG_RT_OUTPUT_RESOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+  set(FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT "lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
+
+  extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" "lib${LLVM_LIBDIR_SUFFIX}")
+endif ()
+set(FLANG_RT_INSTALL_RESOURCE_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT}"
+    CACHE PATH "Path to install runtime libraries to (default: clang resource dir)")
+extend_path(FLANG_RT_INSTALL_RESOURCE_LIB_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}")
+cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_DIR)
+cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_PATH)
+# FIXME: For the libflang_rt.so, the toolchain resource lib dir is not a good
+#        destination because it is not a ld.so default search path.
+#        The machine where the executable is eventually executed may not be the
+#        machine where the Flang compiler and its resource dir is installed, so
+#        setting RPath by the driver is not an solution. It should belong into
+#        /usr/lib/<triple>/libflang_rt.so, like e.g. libgcc_s.so.
+#        But the linker as invoked by the Flang driver also requires
+#        libflang_rt.so to be found when linking and the resource lib dir is
+#        the only reliable location.
+cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_LIB_DIR)
+cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
 
 
 #################
@@ -155,10 +234,6 @@ check_cxx_source_compiles(
   "
   HAVE_DECL_STRERROR_S)
 
-# Look for support of REAL(16), if not already defined via command
-# line via -DFORTRAN_SUPPORTS_REAL16=YES/NO
-check_fortran_quadmath_support()
-
 # Search for clang_rt.builtins library. Need in addition to msvcrt.
 if (WIN32)
   find_compiler_rt_library(builtins FLANG_RT_BUILTINS_LIBRARY)
diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake
index b3f2cd07c0aed..923507764d691 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -190,12 +190,6 @@ function (add_flangrt_library name)
     endif ()
   endif ()
 
-  if (build_object)
-    add_library(${name}.compile ALIAS "${name_object}")
-  else ()
-    add_library(${name}.compile ALIAS "${default_target}")
-  endif ()
-
   foreach (tgtname IN LISTS libtargets)
     if (NOT WIN32)
       # Use same stem name for .a and .so. Common in UNIX environments.
@@ -225,17 +219,6 @@ function (add_flangrt_library name)
     # Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else.
     target_compile_features(${tgtname} PRIVATE cxx_std_17)
 
-    target_compile_options(${tgtname} PRIVATE
-      # Always enable preprocessor regardless of file extention
-      "$<$<COMPILE_LANGUAGE:Fortran>:-cpp>"
-
-      # Missing type descriptors are expected for intrinsic modules 
-      "$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-mmlir;SHELL:-ignore-missing-type-desc>"
-
-      # Flang bug workaround: Reformating of cooked token buffer causes identifier to be split between lines
-      "$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-Xflang;SHELL:-fno-reformat>"
-    )
-
     # When building the flang runtime if LTO is enabled the archive file
     # contains LLVM IR rather than object code. Currently flang is not
     # LTO aware so cannot link this file to compiled Fortran code.
@@ -243,10 +226,6 @@ function (add_flangrt_library name)
       target_compile_options(${tgtname} PRIVATE -fno-lto)
     endif ()
 
-    if (FORTRAN_SUPPORTS_REAL16)
-      target_compile_definitions(${tgtname} PRIVATE FLANG_SUPPORT_R16=1)
-    endif ()
-
     # Use compiler-specific options to disable exceptions and RTTI.
     if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
       target_compile_options(${tgtname} PRIVATE
@@ -365,13 +344,13 @@ function (add_flangrt_library name)
     if (ARG_INSTALL_WITH_TOOLCHAIN)
       set_target_properties(${tgtname}
         PROPERTIES
-          ARCHIVE_OUTPUT_DIRECTORY "${RUNTIMES_OUTPUT_RESOURCE_LIB_DIR}"
-          LIBRARY_OUTPUT_DIRECTORY "${RUNTIMES_OUTPUT_RESOURCE_LIB_DIR}"
+          ARCHIVE_OUTPUT_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_LIB_DIR}"
+          LIBRARY_OUTPUT_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_LIB_DIR}"
         )
 
       install(TARGETS ${tgtname}
-          ARCHIVE DESTINATION "${RUNTIMES_INSTALL_RESOURCE_LIB_PATH}"
-          LIBRARY DESTINATION "${RUNTIMES_INSTALL_RESOURCE_LIB_PATH}"
+          ARCHIVE DESTINATION "${FLANG_RT_INSTALL_RESOURCE_LIB_PATH}"
+          LIBRARY DESTINATION "${FLANG_RT_INSTALL_RESOURCE_LIB_PATH}"
         )
     endif ()
 
diff --git a/flang-rt/cmake/modules/AddFlangRTOffload.cmake b/flang-rt/cmake/modules/AddFlangRTOffload.cmake
index 4a6f047a86af2..cbc69f3a9656a 100644
--- a/flang-rt/cmake/modules/AddFlangRTOffload.cmake
+++ b/flang-rt/cmake/modules/AddFlangRTOffload.cmake
@@ -88,16 +88,16 @@ macro(enable_omp_offload_compilation name files)
         "${FLANG_RT_DEVICE_ARCHITECTURES}"
         )
 
-      set(OMP_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:C,CXX>:
+      set(OMP_COMPILE_OPTIONS
         -fopenmp
         -fvisibility=hidden
         -fopenmp-cuda-mode
         --offload-arch=${compile_for_architectures}
         # Force LTO for the device part.
         -foffload-lto
-        >)
-      set_property(SOURCE ${files} APPEND
-        PROPERTY COMPILE_DEFINITIONS ${OMP_COMPILE_OPTIONS}
+        )
+      set_source_files_properties(${files} PROPERTIES COMPILE_OPTIONS
+        "${OMP_COMPILE_OPTIONS}"
         )
       target_link_options(${name}.static PUBLIC ${OMP_COMPILE_OPTIONS})
 
@@ -105,12 +105,6 @@ macro(enable_omp_offload_compilation name files)
       set_source_files_properties(${files}
         PROPERTIES COMPILE_DEFINITIONS OMP_OFFLOAD_BUILD
         )
-
-     # If building flang-rt together with libomp, ensure that libomp is built first and found because -fopenmp will try to link it.
-     if (TARGET omp)
-       add_dependencies(${name} omp)
-       target_link_options(${name}.static PUBLIC "-L$<TARGET_FILE_DIR:omp>")
-     endif ()
     else()
       message(FATAL_ERROR
         "Flang-rt build with OpenMP offload is not supported for these compilers:\n"
diff --git a/flang-rt/cmake/modules/FlangRTIntrospection.cmake b/flang-rt/cmake/modules/FlangRTIntrospection.cmake
deleted file mode 100644
index ddec624e320e7..0000000000000
--- a/flang-rt/cmake/modules/FlangRTIntrospection.cmake
+++ /dev/null
@@ -1,37 +0,0 @@
-#===-- cmake/modules/FlangRTIntrospection.cmake ----------------------------===#
-#
-# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-#===------------------------------------------------------------------------===#
-
-
-# Check whether the Fortran compiler supports real(16)/quadmath types
-#
-# Implementation notes:
-#  * FORTRAN_SUPPORTS_REAL16 can be set externally in a bootstrapping-runtimes
-#    build to ensure consistency of real(16) support between compiler and
-#    runtime.
-#
-#  * Does not work with Flang and CMake < 3.24
-#
-#  * This is intentionally wrapped in a function to get its own namespace for
-#    CMAKE_REQUIRED_FLAGS and CMAKE_TRY_COMPILE_TARGET_TYPE. In particular,
-#    cmake_pop_check_state() does not reset CMAKE_TRY_COMPILE_TARGET_TYPE,
-#    causing later try_compile invocations to fail. If you see
-#    enable_language(CUDA) failing because CMAKE_RANLIB is empty, this is the
-#    reason.
-function (check_fortran_quadmath_support)
-  cmake_push_check_state(RESET)
-  set(CMAKE_REQUIRED_FLAGS "-ffree-form")
-  set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") # Skip link step
-  check_fortran_source_compiles([[
-      subroutine test_quadmath
-        real(16) :: var1
-      end
-    ]]
-    FORTRAN_SUPPORTS_REAL16
-  )
-  cmake_pop_check_state()
-endfunction ()
diff --git a/cmake/Modules/GetToolchainDirs.cmake b/flang-rt/cmake/modules/GetToolchainDirs.cmake
similarity index 94%
rename from cmake/Modules/GetToolchainDirs.cmake
rename to flang-rt/cmake/modules/GetToolchainDirs.cmake
index ce2f8c294b2bc..fba12502b5946 100644
--- a/cmake/Modules/GetToolchainDirs.cmake
+++ b/flang-rt/cmake/modules/GetToolchainDirs.cmake
@@ -47,17 +47,6 @@ function (get_toolchain_library_subdir outvar)
 endfunction ()
 
 
-# Corresponds to Flang's ToolChain::getDefaultIntrinsicModuleDir().
-function (get_toolchain_module_subdir outvar)
-  set(outval "finclude/flang")
-
-  get_toolchain_arch_dirname(arch_dirname)
-  set(outval "${outval}/${arch_dirname}")
-
-  set(${outvar} "${outval}" PARENT_SCOPE)
-endfunction ()
-
-
 # Corresponds to Clang's ToolChain::getOSLibName(). Adapted from Compiler-RT.
 function (get_toolchain_os_dirname outvar)
   if (ANDROID)
diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index a678055430233..e8f70bd544e0b 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -12,13 +12,6 @@ find_package(Backtrace)
 set(HAVE_BACKTRACE ${Backtrace_FOUND})
 set(BACKTRACE_HEADER ${Backtrace_HEADER})
 
-# Module sources that are required by other modules
-set(intrinsics_sources
-  __fortran_builtins.f90
-  __cuda_builtins.f90
-)
-
-
 # List of files that are buildable for all devices.
 set(supported_sources
   ${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
@@ -80,16 +73,7 @@ set(supported_sources
 
 # List of source not used for GPU offloading.
 set(host_sources
-  __fortran_ieee_exceptions.f90
-  __fortran_type_info.f90
-  iso_fortran_env.f90
-  ieee_arithmetic.f90
-  ieee_exceptions.f90
-  ieee_features.f90
-  iso_c_binding.f90
-  iso_fortran_env_impl.f90
-  iso_fortran_env.f90
-
+  ${FLANG_SOURCE_DIR}/module/iso_fortran_env_impl.f90
   command.cpp
   complex-powi.cpp
   complex-reduction.c
@@ -104,32 +88,8 @@ set(host_sources
   temporary-stack.cpp
   time-intrinsic.cpp
   unit-map.cpp
-
-  __cuda_device.f90
-  cooperative_groups.f90
-  cudadevice.f90
 )
 
-if (LLVM_TARGET_TRIPLE MATCHES "^ppc|^powerpc")
-  list(APPEND intrinsics_sources
-    __ppc_types.f90
-  )
-  list(APPEND host_sources
-    __ppc_intrinsics.f90
-    mma.f90
-  )
-endif ()
-
-# Compile as CUDA-Fortran, not directly supported by CMake
-set_property(SOURCE
-    __cuda_device.f90
-    cooperative_groups.f90
-    cudadevice.f90
-  APPEND PROPERTY
-    COMPILE_OPTIONS --offload-host-only -xcuda
-)
-
-
 # Sources that can be compiled directly for the GPU.
 set(gpu_sources
   ${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
@@ -215,42 +175,19 @@ else ()
   set(f128_sources "")
 endif ()
 
-if (LLVM_RUNTIMES_TARGET MATCHES "^amdgcn|^nvptx")
+if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
   set(sources ${gpu_sources})
+elseif(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
+  set(sources ${supported_sources})
 else ()
   set(sources ${supported_sources} ${host_sources} ${f128_sources})
 endif ()
 
 
-# check-flang depends on this to build intrinsic modules
-if (NOT TARGET flang-rt-mod)
-  add_custom_target(flang-rt-mod)
-endif ()
-
 if (NOT WIN32)
-  # 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.
-  add_flangrt_library(flang_rt.intrinsics.obj OBJECT
-    ${intrinsics_sources}
-  )
-
-  # This barrier exists to force all of the intrinsic modules of
-  # flang_rt.intrinsics.obj to be built before anything that depends on it.
-  # Without it, CMake/Ninja seem to think that the modules of
-  # flang_rt.intrinsics.obj can be built concurrently to those in
-  # flang_rt.runtime.
-  add_custom_target(flang_rt.intrinsics
-    COMMENT "Intrinsic module dependency barrier"
-  )
-  add_dependencies(flang_rt.intrinsics flang_rt.intrinsics.obj)
-
   add_flangrt_library(flang_rt.runtime STATIC SHARED
-    ${sources} $<TARGET_OBJECTS:flang_rt.intrinsics.obj>
-    LINK_LIBRARIES flang_rt.intrinsics.obj ${Backtrace_LIBRARY}
+    ${sources}
+    LINK_LIBRARIES ${Backtrace_LIBRARY}
     INSTALL_WITH_TOOLCHAIN
     ADDITIONAL_HEADERS ${public_headers} ${private_headers}
   )
@@ -261,13 +198,6 @@ if (NOT WIN32)
   # Select a default runtime, which is used for unit and regression tests.
   get_target_property(default_target flang_rt.runtime.default ALIASED_TARGET)
   add_library(flang_rt.runtime.unittest ALIAS "${default_target}")
-
-  # Select a target that compiles the s...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2025

@llvm/pr-subscribers-clang-driver

Author: Jan Patrick Lehr (jplehr)

Changes

Reverts llvm/llvm-project#137828

Buildbot error in https://lab.llvm.org/staging/#/builders/105/builds/37275


Patch is 88.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/169489.diff

64 Files Affected:

  • (modified) clang/include/clang/Driver/ToolChain.h (-4)
  • (modified) clang/include/clang/Options/Options.td (+1-1)
  • (modified) clang/lib/Driver/Driver.cpp (-11)
  • (modified) clang/lib/Driver/ToolChain.cpp (-6)
  • (modified) clang/lib/Driver/ToolChains/Flang.cpp (-8)
  • (modified) flang-rt/CMakeLists.txt (+86-11)
  • (modified) flang-rt/cmake/modules/AddFlangRT.cmake (+4-25)
  • (modified) flang-rt/cmake/modules/AddFlangRTOffload.cmake (+4-10)
  • (removed) flang-rt/cmake/modules/FlangRTIntrospection.cmake (-37)
  • (renamed) flang-rt/cmake/modules/GetToolchainDirs.cmake (-11)
  • (modified) flang-rt/lib/runtime/CMakeLists.txt (+13-102)
  • (modified) flang-rt/test/lit.site.cfg.py.in (+1-1)
  • (modified) flang-rt/unittests/CMakeLists.txt (+3-2)
  • (modified) flang/CMakeLists.txt (+1)
  • (modified) flang/include/flang/Frontend/CompilerInvocation.h (-7)
  • (modified) flang/lib/Frontend/CompilerInvocation.cpp (+13-13)
  • (modified) flang/lib/Semantics/semantics.cpp (+5-8)
  • (added) flang/module/.clang-format (+1)
  • (renamed) flang/module/__cuda_builtins.f90 ()
  • (renamed) flang/module/__cuda_device.f90 ()
  • (renamed) flang/module/__fortran_builtins.f90 (+1-1)
  • (renamed) flang/module/__fortran_ieee_exceptions.f90 ()
  • (renamed) flang/module/__fortran_type_info.f90 ()
  • (renamed) flang/module/__ppc_intrinsics.f90 ()
  • (renamed) flang/module/__ppc_types.f90 ()
  • (renamed) flang/module/cooperative_groups.f90 (-1)
  • (renamed) flang/module/cudadevice.f90 ()
  • (renamed) flang/module/ieee_arithmetic.f90 (+1-1)
  • (renamed) flang/module/ieee_exceptions.f90 ()
  • (renamed) flang/module/ieee_features.f90 ()
  • (renamed) flang/module/iso_c_binding.f90 ()
  • (renamed) flang/module/iso_fortran_env.f90 ()
  • (renamed) flang/module/iso_fortran_env_impl.f90 ()
  • (renamed) flang/module/mma.f90 ()
  • (modified) flang/test/CMakeLists.txt (+3-28)
  • (modified) flang/test/Driver/Inputs/ieee_arithmetic.mod (-1)
  • (modified) flang/test/Driver/Inputs/iso_fortran_env.mod (-1)
  • (removed) flang/test/Driver/intrinsic-module-path.F90 (-55)
  • (added) flang/test/Driver/intrinsic-module-path.f90 (+23)
  • (modified) flang/test/Driver/lto-fatlto.f90 (+2-2)
  • (modified) flang/test/Driver/pp-fixed-form.f90 (+2-2)
  • (modified) flang/test/Lower/HLFIR/type-bound-call-mismatch.f90 (+1-1)
  • (modified) flang/test/Lower/OpenMP/simd_aarch64.f90 (+1-6)
  • (modified) flang/test/Lower/OpenMP/target-enter-data-default-openmp52.f90 (+2-2)
  • (modified) flang/test/Preprocessing/fixed-free.f (+1-1)
  • (modified) flang/test/Preprocessing/no-pp-if.f90 (+1-1)
  • (modified) flang/test/Semantics/bug163242.f90 (+1-1)
  • (modified) flang/test/Semantics/bug164303.f90 (+1-1)
  • (modified) flang/test/lit.cfg.py (+13-81)
  • (modified) flang/test/lit.site.cfg.py.in (+6-3)
  • (modified) flang/tools/CMakeLists.txt (+1)
  • (modified) flang/tools/bbc/bbc.cpp (+8-5)
  • (added) flang/tools/f18/CMakeLists.txt (+170)
  • (added) flang/tools/f18/dump.cpp (+42)
  • (modified) llvm/runtimes/CMakeLists.txt (+11-13)
  • (modified) openmp/CMakeLists.txt (-6)
  • (modified) openmp/runtime/CMakeLists.txt (+7-1)
  • (added) openmp/runtime/cmake/LibompCheckFortranFlag.cmake (+29)
  • (modified) openmp/runtime/cmake/LibompHandleFlags.cmake (+11)
  • (modified) openmp/runtime/cmake/config-ix.cmake (+4)
  • (modified) openmp/runtime/src/CMakeLists.txt (+43-20)
  • (modified) openmp/runtime/test/lit.cfg (-1)
  • (modified) openmp/runtime/test/lit.site.cfg.in (-1)
  • (modified) runtimes/CMakeLists.txt (+11-212)
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index 26af88242eb3e..1425714d34110 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -538,10 +538,6 @@ class ToolChain {
   // Returns Triple without the OSs version.
   llvm::Triple getTripleWithoutOSVersion() const;
 
-  /// Returns the target-specific path for Flang's intrinsic modules in the
-  /// resource directory if it exists.
-  std::optional<std::string> getDefaultIntrinsicModuleDir() const;
-
   // Returns the target specific runtime path if it exists.
   std::optional<std::string> getRuntimePath() const;
 
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 0e88656c5e1bc..a8fc1c4326cc5 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -6082,7 +6082,7 @@ def prebind : Flag<["-"], "prebind">;
 def preload : Flag<["-"], "preload">;
 def print_file_name_EQ : Joined<["-", "--"], "print-file-name=">,
   HelpText<"Print the full library path of <file>">, MetaVarName<"<file>">,
-  Visibility<[ClangOption, FlangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption]>;
 def print_ivar_layout : Flag<["-"], "print-ivar-layout">,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Enable Objective-C Ivar layout bitmap print trace">,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 781bc74466da1..de8d4601210ae 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6602,17 +6602,6 @@ std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const {
   if (llvm::sys::fs::exists(Twine(P)))
     return std::string(P);
 
-  // With Flang, also look for instrinsic modules
-  if (IsFlangMode()) {
-    if (std::optional<std::string> IntrPath =
-            TC.getDefaultIntrinsicModuleDir()) {
-      SmallString<128> P(*IntrPath);
-      llvm::sys::path::append(P, Name);
-      if (llvm::sys::fs::exists(Twine(P)))
-        return std::string(P);
-    }
-  }
-
   SmallString<128> D(Dir);
   llvm::sys::path::append(D, "..", Name);
   if (llvm::sys::fs::exists(Twine(D)))
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index f8520725b9b03..77a2c73f0d446 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1020,12 +1020,6 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   return {};
 }
 
-std::optional<std::string> ToolChain::getDefaultIntrinsicModuleDir() const {
-  SmallString<128> P(D.ResourceDir);
-  llvm::sys::path::append(P, "finclude", "flang");
-  return getTargetSubDirPath(P);
-}
-
 std::optional<std::string> ToolChain::getRuntimePath() const {
   SmallString<128> P(D.ResourceDir);
   llvm::sys::path::append(P, "lib");
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index bac421bb86f49..cc4755cd6a9b0 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -1060,14 +1060,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   CmdArgs.push_back("-resource-dir");
   CmdArgs.push_back(D.ResourceDir.c_str());
 
-  // Default intrinsic module dirs must be added after any user-provided
-  // -fintrinsic-modules-path to have lower precedence
-  if (std::optional<std::string> IntrModPath =
-          TC.getDefaultIntrinsicModuleDir()) {
-    CmdArgs.push_back("-fintrinsic-modules-path");
-    CmdArgs.push_back(Args.MakeArgString(*IntrModPath));
-  }
-
   // Offloading related options
   addOffloadOptions(C, Inputs, JA, Args, CmdArgs);
 
diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt
index db0d87d91ea83..50b8e834776fb 100644
--- a/flang-rt/CMakeLists.txt
+++ b/flang-rt/CMakeLists.txt
@@ -23,6 +23,40 @@ set(FLANG_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
 set(FLANG_RT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
 set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang")
 
+# 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 (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")
+    include(CMakeForceCompiler)
+    CMAKE_FORCE_Fortran_COMPILER("${CMAKE_Fortran_COMPILER}" "LLVMFlang")
+
+    set(CMAKE_Fortran_COMPILER_ID "LLVMFlang")
+    set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
+
+    set(CMAKE_Fortran_SUBMODULE_SEP "-")
+    set(CMAKE_Fortran_SUBMODULE_EXT ".mod")
+
+    set(CMAKE_Fortran_PREPROCESS_SOURCE
+      "<CMAKE_Fortran_COMPILER> -cpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+
+    set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form")
+    set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form")
+
+    set(CMAKE_Fortran_MODDIR_FLAG "-module-dir")
+
+    set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp")
+    set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nocpp")
+    set(CMAKE_Fortran_POSTPROCESS_FLAG "-ffixed-line-length-72")
+
+    set(CMAKE_Fortran_COMPILE_OPTIONS_TARGET "--target=")
+
+    set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
+    set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",")
+  endif ()
+endif ()
+enable_language(Fortran)
+
 
 list(APPEND CMAKE_MODULE_PATH
     "${FLANG_RT_SOURCE_DIR}/cmake/modules"
@@ -31,24 +65,69 @@ list(APPEND CMAKE_MODULE_PATH
 include(AddFlangRT)
 include(GetToolchainDirs)
 include(FlangCommon)
-include(FlangRTIntrospection)
 include(HandleCompilerRT)
 include(ExtendPath)
-include(CheckFortranSourceCompiles)
-include(CMakePushCheckState)
 
 
 ############################
 # Build Mode Introspection #
 ############################
 
+# Determine whether we are in the runtimes/runtimes-bins directory of a
+# bootstrap build.
+set(LLVM_TREE_AVAILABLE OFF)
+if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSION)
+  set(LLVM_TREE_AVAILABLE ON)
+endif()
+
 # Path to LLVM development tools (FileCheck, llvm-lit, not, ...)
 set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin")
 
-# Fortran compiler not optional for building Flang-RT
-enable_language(Fortran)
-
-flang_module_fortran_enable()
+# Determine build and install paths.
+# The build path is absolute, but the install dir is relative, CMake's install
+# command has to apply CMAKE_INSTALL_PREFIX itself.
+get_toolchain_library_subdir(toolchain_lib_subdir)
+if (LLVM_TREE_AVAILABLE)
+  # In a bootstrap build emit the libraries into a default search path in the
+  # build directory of the just-built compiler. This allows using the
+  # just-built compiler without specifying paths to runtime libraries.
+  #
+  # Despite Clang in the name, get_clang_resource_dir does not depend on Clang
+  # being added to the build. Flang uses the same resource dir as clang.
+  include(GetClangResourceDir)
+  get_clang_resource_dir(FLANG_RT_OUTPUT_RESOURCE_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR}/..")
+  get_clang_resource_dir(FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT)
+
+  extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" "${toolchain_lib_subdir}")
+else ()
+  # In a standalone runtimes build, do not write into LLVM_BINARY_DIR. It may be
+  # read-only and/or shared by multiple runtimes with different build
+  # configurations (e.g. Debug/Release). Use the runtime's own lib dir like any
+  # non-toolchain library.
+  # For the install prefix, still use the resource dir assuming that Flang will
+  # be installed there using the same prefix. This is to not have a difference
+  # between bootstrap and standalone runtimes builds.
+  set(FLANG_RT_OUTPUT_RESOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+  set(FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT "lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
+
+  extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" "lib${LLVM_LIBDIR_SUFFIX}")
+endif ()
+set(FLANG_RT_INSTALL_RESOURCE_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH_DEFAULT}"
+    CACHE PATH "Path to install runtime libraries to (default: clang resource dir)")
+extend_path(FLANG_RT_INSTALL_RESOURCE_LIB_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}")
+cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_DIR)
+cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_PATH)
+# FIXME: For the libflang_rt.so, the toolchain resource lib dir is not a good
+#        destination because it is not a ld.so default search path.
+#        The machine where the executable is eventually executed may not be the
+#        machine where the Flang compiler and its resource dir is installed, so
+#        setting RPath by the driver is not an solution. It should belong into
+#        /usr/lib/<triple>/libflang_rt.so, like e.g. libgcc_s.so.
+#        But the linker as invoked by the Flang driver also requires
+#        libflang_rt.so to be found when linking and the resource lib dir is
+#        the only reliable location.
+cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_LIB_DIR)
+cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
 
 
 #################
@@ -155,10 +234,6 @@ check_cxx_source_compiles(
   "
   HAVE_DECL_STRERROR_S)
 
-# Look for support of REAL(16), if not already defined via command
-# line via -DFORTRAN_SUPPORTS_REAL16=YES/NO
-check_fortran_quadmath_support()
-
 # Search for clang_rt.builtins library. Need in addition to msvcrt.
 if (WIN32)
   find_compiler_rt_library(builtins FLANG_RT_BUILTINS_LIBRARY)
diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake
index b3f2cd07c0aed..923507764d691 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -190,12 +190,6 @@ function (add_flangrt_library name)
     endif ()
   endif ()
 
-  if (build_object)
-    add_library(${name}.compile ALIAS "${name_object}")
-  else ()
-    add_library(${name}.compile ALIAS "${default_target}")
-  endif ()
-
   foreach (tgtname IN LISTS libtargets)
     if (NOT WIN32)
       # Use same stem name for .a and .so. Common in UNIX environments.
@@ -225,17 +219,6 @@ function (add_flangrt_library name)
     # Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else.
     target_compile_features(${tgtname} PRIVATE cxx_std_17)
 
-    target_compile_options(${tgtname} PRIVATE
-      # Always enable preprocessor regardless of file extention
-      "$<$<COMPILE_LANGUAGE:Fortran>:-cpp>"
-
-      # Missing type descriptors are expected for intrinsic modules 
-      "$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-mmlir;SHELL:-ignore-missing-type-desc>"
-
-      # Flang bug workaround: Reformating of cooked token buffer causes identifier to be split between lines
-      "$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-Xflang;SHELL:-fno-reformat>"
-    )
-
     # When building the flang runtime if LTO is enabled the archive file
     # contains LLVM IR rather than object code. Currently flang is not
     # LTO aware so cannot link this file to compiled Fortran code.
@@ -243,10 +226,6 @@ function (add_flangrt_library name)
       target_compile_options(${tgtname} PRIVATE -fno-lto)
     endif ()
 
-    if (FORTRAN_SUPPORTS_REAL16)
-      target_compile_definitions(${tgtname} PRIVATE FLANG_SUPPORT_R16=1)
-    endif ()
-
     # Use compiler-specific options to disable exceptions and RTTI.
     if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
       target_compile_options(${tgtname} PRIVATE
@@ -365,13 +344,13 @@ function (add_flangrt_library name)
     if (ARG_INSTALL_WITH_TOOLCHAIN)
       set_target_properties(${tgtname}
         PROPERTIES
-          ARCHIVE_OUTPUT_DIRECTORY "${RUNTIMES_OUTPUT_RESOURCE_LIB_DIR}"
-          LIBRARY_OUTPUT_DIRECTORY "${RUNTIMES_OUTPUT_RESOURCE_LIB_DIR}"
+          ARCHIVE_OUTPUT_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_LIB_DIR}"
+          LIBRARY_OUTPUT_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_LIB_DIR}"
         )
 
       install(TARGETS ${tgtname}
-          ARCHIVE DESTINATION "${RUNTIMES_INSTALL_RESOURCE_LIB_PATH}"
-          LIBRARY DESTINATION "${RUNTIMES_INSTALL_RESOURCE_LIB_PATH}"
+          ARCHIVE DESTINATION "${FLANG_RT_INSTALL_RESOURCE_LIB_PATH}"
+          LIBRARY DESTINATION "${FLANG_RT_INSTALL_RESOURCE_LIB_PATH}"
         )
     endif ()
 
diff --git a/flang-rt/cmake/modules/AddFlangRTOffload.cmake b/flang-rt/cmake/modules/AddFlangRTOffload.cmake
index 4a6f047a86af2..cbc69f3a9656a 100644
--- a/flang-rt/cmake/modules/AddFlangRTOffload.cmake
+++ b/flang-rt/cmake/modules/AddFlangRTOffload.cmake
@@ -88,16 +88,16 @@ macro(enable_omp_offload_compilation name files)
         "${FLANG_RT_DEVICE_ARCHITECTURES}"
         )
 
-      set(OMP_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:C,CXX>:
+      set(OMP_COMPILE_OPTIONS
         -fopenmp
         -fvisibility=hidden
         -fopenmp-cuda-mode
         --offload-arch=${compile_for_architectures}
         # Force LTO for the device part.
         -foffload-lto
-        >)
-      set_property(SOURCE ${files} APPEND
-        PROPERTY COMPILE_DEFINITIONS ${OMP_COMPILE_OPTIONS}
+        )
+      set_source_files_properties(${files} PROPERTIES COMPILE_OPTIONS
+        "${OMP_COMPILE_OPTIONS}"
         )
       target_link_options(${name}.static PUBLIC ${OMP_COMPILE_OPTIONS})
 
@@ -105,12 +105,6 @@ macro(enable_omp_offload_compilation name files)
       set_source_files_properties(${files}
         PROPERTIES COMPILE_DEFINITIONS OMP_OFFLOAD_BUILD
         )
-
-     # If building flang-rt together with libomp, ensure that libomp is built first and found because -fopenmp will try to link it.
-     if (TARGET omp)
-       add_dependencies(${name} omp)
-       target_link_options(${name}.static PUBLIC "-L$<TARGET_FILE_DIR:omp>")
-     endif ()
     else()
       message(FATAL_ERROR
         "Flang-rt build with OpenMP offload is not supported for these compilers:\n"
diff --git a/flang-rt/cmake/modules/FlangRTIntrospection.cmake b/flang-rt/cmake/modules/FlangRTIntrospection.cmake
deleted file mode 100644
index ddec624e320e7..0000000000000
--- a/flang-rt/cmake/modules/FlangRTIntrospection.cmake
+++ /dev/null
@@ -1,37 +0,0 @@
-#===-- cmake/modules/FlangRTIntrospection.cmake ----------------------------===#
-#
-# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-#===------------------------------------------------------------------------===#
-
-
-# Check whether the Fortran compiler supports real(16)/quadmath types
-#
-# Implementation notes:
-#  * FORTRAN_SUPPORTS_REAL16 can be set externally in a bootstrapping-runtimes
-#    build to ensure consistency of real(16) support between compiler and
-#    runtime.
-#
-#  * Does not work with Flang and CMake < 3.24
-#
-#  * This is intentionally wrapped in a function to get its own namespace for
-#    CMAKE_REQUIRED_FLAGS and CMAKE_TRY_COMPILE_TARGET_TYPE. In particular,
-#    cmake_pop_check_state() does not reset CMAKE_TRY_COMPILE_TARGET_TYPE,
-#    causing later try_compile invocations to fail. If you see
-#    enable_language(CUDA) failing because CMAKE_RANLIB is empty, this is the
-#    reason.
-function (check_fortran_quadmath_support)
-  cmake_push_check_state(RESET)
-  set(CMAKE_REQUIRED_FLAGS "-ffree-form")
-  set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") # Skip link step
-  check_fortran_source_compiles([[
-      subroutine test_quadmath
-        real(16) :: var1
-      end
-    ]]
-    FORTRAN_SUPPORTS_REAL16
-  )
-  cmake_pop_check_state()
-endfunction ()
diff --git a/cmake/Modules/GetToolchainDirs.cmake b/flang-rt/cmake/modules/GetToolchainDirs.cmake
similarity index 94%
rename from cmake/Modules/GetToolchainDirs.cmake
rename to flang-rt/cmake/modules/GetToolchainDirs.cmake
index ce2f8c294b2bc..fba12502b5946 100644
--- a/cmake/Modules/GetToolchainDirs.cmake
+++ b/flang-rt/cmake/modules/GetToolchainDirs.cmake
@@ -47,17 +47,6 @@ function (get_toolchain_library_subdir outvar)
 endfunction ()
 
 
-# Corresponds to Flang's ToolChain::getDefaultIntrinsicModuleDir().
-function (get_toolchain_module_subdir outvar)
-  set(outval "finclude/flang")
-
-  get_toolchain_arch_dirname(arch_dirname)
-  set(outval "${outval}/${arch_dirname}")
-
-  set(${outvar} "${outval}" PARENT_SCOPE)
-endfunction ()
-
-
 # Corresponds to Clang's ToolChain::getOSLibName(). Adapted from Compiler-RT.
 function (get_toolchain_os_dirname outvar)
   if (ANDROID)
diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index a678055430233..e8f70bd544e0b 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -12,13 +12,6 @@ find_package(Backtrace)
 set(HAVE_BACKTRACE ${Backtrace_FOUND})
 set(BACKTRACE_HEADER ${Backtrace_HEADER})
 
-# Module sources that are required by other modules
-set(intrinsics_sources
-  __fortran_builtins.f90
-  __cuda_builtins.f90
-)
-
-
 # List of files that are buildable for all devices.
 set(supported_sources
   ${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
@@ -80,16 +73,7 @@ set(supported_sources
 
 # List of source not used for GPU offloading.
 set(host_sources
-  __fortran_ieee_exceptions.f90
-  __fortran_type_info.f90
-  iso_fortran_env.f90
-  ieee_arithmetic.f90
-  ieee_exceptions.f90
-  ieee_features.f90
-  iso_c_binding.f90
-  iso_fortran_env_impl.f90
-  iso_fortran_env.f90
-
+  ${FLANG_SOURCE_DIR}/module/iso_fortran_env_impl.f90
   command.cpp
   complex-powi.cpp
   complex-reduction.c
@@ -104,32 +88,8 @@ set(host_sources
   temporary-stack.cpp
   time-intrinsic.cpp
   unit-map.cpp
-
-  __cuda_device.f90
-  cooperative_groups.f90
-  cudadevice.f90
 )
 
-if (LLVM_TARGET_TRIPLE MATCHES "^ppc|^powerpc")
-  list(APPEND intrinsics_sources
-    __ppc_types.f90
-  )
-  list(APPEND host_sources
-    __ppc_intrinsics.f90
-    mma.f90
-  )
-endif ()
-
-# Compile as CUDA-Fortran, not directly supported by CMake
-set_property(SOURCE
-    __cuda_device.f90
-    cooperative_groups.f90
-    cudadevice.f90
-  APPEND PROPERTY
-    COMPILE_OPTIONS --offload-host-only -xcuda
-)
-
-
 # Sources that can be compiled directly for the GPU.
 set(gpu_sources
   ${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
@@ -215,42 +175,19 @@ else ()
   set(f128_sources "")
 endif ()
 
-if (LLVM_RUNTIMES_TARGET MATCHES "^amdgcn|^nvptx")
+if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
   set(sources ${gpu_sources})
+elseif(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
+  set(sources ${supported_sources})
 else ()
   set(sources ${supported_sources} ${host_sources} ${f128_sources})
 endif ()
 
 
-# check-flang depends on this to build intrinsic modules
-if (NOT TARGET flang-rt-mod)
-  add_custom_target(flang-rt-mod)
-endif ()
-
 if (NOT WIN32)
-  # 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.
-  add_flangrt_library(flang_rt.intrinsics.obj OBJECT
-    ${intrinsics_sources}
-  )
-
-  # This barrier exists to force all of the intrinsic modules of
-  # flang_rt.intrinsics.obj to be built before anything that depends on it.
-  # Without it, CMake/Ninja seem to think that the modules of
-  # flang_rt.intrinsics.obj can be built concurrently to those in
-  # flang_rt.runtime.
-  add_custom_target(flang_rt.intrinsics
-    COMMENT "Intrinsic module dependency barrier"
-  )
-  add_dependencies(flang_rt.intrinsics flang_rt.intrinsics.obj)
-
   add_flangrt_library(flang_rt.runtime STATIC SHARED
-    ${sources} $<TARGET_OBJECTS:flang_rt.intrinsics.obj>
-    LINK_LIBRARIES flang_rt.intrinsics.obj ${Backtrace_LIBRARY}
+    ${sources}
+    LINK_LIBRARIES ${Backtrace_LIBRARY}
     INSTALL_WITH_TOOLCHAIN
     ADDITIONAL_HEADERS ${public_headers} ${private_headers}
   )
@@ -261,13 +198,6 @@ if (NOT WIN32)
   # Select a default runtime, which is used for unit and regression tests.
   get_target_property(default_target flang_rt.runtime.default ALIASED_TARGET)
   add_library(flang_rt.runtime.unittest ALIAS "${default_target}")
-
-  # Select a target that compiles the s...
[truncated]

@ronlieb ronlieb self-requested a review November 25, 2025 12:03
@github-actions
Copy link

🐧 Linux x64 Test Results

  • 166322 tests passed
  • 2872 tests skipped
  • 1 test failed

Failed Tests

(click on a test name to see its output)

LLVM

LLVM.CodeGen/AMDGPU/valu-mask-write-hazard.mir
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize64 -verify-machineinstrs -run-pass post-RA-hazard-rec -o - /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/valu-mask-write-hazard.mir | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck -check-prefixes=GCN,GFX11 /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/valu-mask-write-hazard.mir
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize64 -verify-machineinstrs -run-pass post-RA-hazard-rec -o - /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/valu-mask-write-hazard.mir
# note: command had no output on stdout or stderr
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck -check-prefixes=GCN,GFX11 /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/valu-mask-write-hazard.mir
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/valu-mask-write-hazard.mir:1057:16: error: GFX11-NEXT: expected string not found in input
# |  ; GFX11-NEXT: S_WAITCNT_DEPCTR 65533
# |                ^
# | <stdin>:5165:63: note: scanning from here
# |  V_CMP_NE_U32_e32 0, $vgpr5, implicit-def $vcc, implicit $exec
# |                                                               ^
# | <stdin>:5166:2: note: possible intended match here
# |  S_WAITCNT_DEPCTR 65437
# |  ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/valu-mask-write-hazard.mir:1090:16: error: GFX11-NEXT: expected string not found in input
# |  ; GFX11-NEXT: S_WAITCNT_DEPCTR 65533
# |                ^
# | <stdin>:5269:63: note: scanning from here
# |  V_CMP_NE_U32_e32 0, $vgpr5, implicit-def $vcc, implicit $exec
# |                                                               ^
# | <stdin>:5270:2: note: possible intended match here
# |  S_WAITCNT_DEPCTR 65437
# |  ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/valu-mask-write-hazard.mir:1126:16: error: GFX11-NEXT: expected string not found in input
# |  ; GFX11-NEXT: S_WAITCNT_DEPCTR 65533
# |                ^
# | <stdin>:5374:63: note: scanning from here
# |  V_CMP_NE_U32_e32 0, $vgpr5, implicit-def $vcc, implicit $exec
# |                                                               ^
# | <stdin>:5375:2: note: possible intended match here
# |  S_WAITCNT_DEPCTR 65437
# |  ^
# | 
# | Input file: <stdin>
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/valu-mask-write-hazard.mir
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |              .
# |              .
# |              .
# |           5160: body: | 
# |           5161:  bb.0: 
# |           5162:  $vgpr3 = V_CNDMASK_B32_e32 $vgpr1, $vgpr2, implicit $vcc, implicit $exec 
# |           5163:  $vgpr4 = V_CNDMASK_B32_e64 0, $vgpr1, 0, $vgpr2, $sgpr0_sgpr1, implicit $exec 
# |           5164:  $vgpr5 = V_CNDMASK_B32_e64 0, $vgpr1, 0, $vgpr2, $sgpr2_sgpr3, implicit $exec 
# |           5165:  V_CMP_NE_U32_e32 0, $vgpr5, implicit-def $vcc, implicit $exec 
# | next:1057'0                                                                   X error: no match found
# |           5166:  S_WAITCNT_DEPCTR 65437 
# | next:1057'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# | next:1057'1      ?                       possible intended match
# |           5167:  $sgpr0_sgpr1 = V_CMP_EQ_U32_e64 2, $sgpr10, implicit $exec 
# | next:1057'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           5168:  S_WAITCNT_DEPCTR 61855 
# | next:1057'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# |           5169:  $sgpr2_sgpr3 = V_CMP_EQ_U32_e64 3, $sgpr10, implicit $exec 
# | next:1057'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           5170:  S_WAITCNT_DEPCTR 61855 
# | next:1057'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# |           5171:  S_ENDPGM 0 
# | next:1057'0     ~~~~~~~~~~~~
# |              .
# |              .
# |              .
# |           5264: body: | 
# |           5265:  bb.0: 
# |           5266:  $vgpr3 = V_CNDMASK_B32_e32 $vgpr1, $vgpr2, implicit $vcc, implicit $exec 
# |           5267:  $vgpr4 = V_CNDMASK_B32_e64 0, $vgpr1, 0, $vgpr2, $sgpr0_sgpr1, implicit $exec 
# |           5268:  $vgpr5 = V_CNDMASK_B32_e64 0, $vgpr1, 0, $vgpr2, $sgpr2_sgpr3, implicit $exec 
# |           5269:  V_CMP_NE_U32_e32 0, $vgpr5, implicit-def $vcc, implicit $exec 
# | next:1090'0                                                                   X error: no match found
# |           5270:  S_WAITCNT_DEPCTR 65437 
# | next:1090'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# | next:1090'1      ?                       possible intended match
# |           5271:  $sgpr0_sgpr1 = V_CMP_EQ_U32_e64 2, $sgpr10, implicit $exec 
# | next:1090'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           5272:  S_WAITCNT_DEPCTR 61855 
# | next:1090'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# |           5273:  $sgpr4_sgpr5 = S_MOV_B64 $vcc 
# | next:1090'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           5274:  $sgpr2_sgpr3 = V_CMP_EQ_U32_e64 3, $sgpr10, implicit $exec 
# | next:1090'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           5275:  S_WAITCNT_DEPCTR 61855 
# | next:1090'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# |              .
# |              .
# |              .
# |           5369: body: | 
# |           5370:  bb.0: 
# |           5371:  $vgpr3 = V_CNDMASK_B32_e32 $vgpr1, $vgpr2, implicit $vcc, implicit $exec 
# |           5372:  $vgpr4 = V_CNDMASK_B32_e64 0, $vgpr1, 0, $vgpr2, $sgpr0_sgpr1, implicit $exec 
# |           5373:  $vgpr5 = V_CNDMASK_B32_e64 0, $vgpr1, 0, $vgpr2, $sgpr2_sgpr3, implicit $exec 
# |           5374:  V_CMP_NE_U32_e32 0, $vgpr5, implicit-def $vcc, implicit $exec 
# | next:1126'0                                                                   X error: no match found
# |           5375:  S_WAITCNT_DEPCTR 65437 
# | next:1126'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# | next:1126'1      ?                       possible intended match
# |           5376:  $sgpr0_sgpr1 = V_CMP_EQ_U32_e64 2, $sgpr10, implicit $exec 
# | next:1126'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           5377:  S_WAITCNT_DEPCTR 61855 
# | next:1126'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# |           5378:  $sgpr5 = S_MOV_B32 $sgpr1 
# | next:1126'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           5379:  $sgpr2_sgpr3 = V_CMP_EQ_U32_e64 3, $sgpr10, implicit $exec 
# | next:1126'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           5380:  S_WAITCNT_DEPCTR 61855 
# | next:1126'0     ~~~~~~~~~~~~~~~~~~~~~~~~
# |              .
# |              .
# |              .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

@jplehr
Copy link
Contributor Author

jplehr commented Nov 25, 2025

The test that is failing the CI is unrelated to this PR.

@jplehr jplehr merged commit 4bc654d into main Nov 25, 2025
76 of 79 checks passed
@jplehr jplehr deleted the revert-137828-flang_builtin-mods branch November 25, 2025 12:54
@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 25, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux-android running on sanitizer-buildbot-android while building clang,flang-rt,flang,llvm,openmp,runtimes at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/186/builds/14260

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
[       OK ] AddressSanitizer.AtoiAndFriendsOOBTest (2211 ms)
[ RUN      ] AddressSanitizer.HasFeatureAddressSanitizerTest
[       OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN      ] AddressSanitizer.CallocReturnsZeroMem
[       OK ] AddressSanitizer.CallocReturnsZeroMem (13 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN      ] AddressSanitizer.IgnoreTest
[       OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN      ] AddressSanitizer.SignalTest
[       OK ] AddressSanitizer.SignalTest (203 ms)
[ RUN      ] AddressSanitizer.ReallocTest
[       OK ] AddressSanitizer.ReallocTest (37 ms)
[ RUN      ] AddressSanitizer.WrongFreeTest
[       OK ] AddressSanitizer.WrongFreeTest (119 ms)
[ RUN      ] AddressSanitizer.LongJmpTest
[       OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN      ] AddressSanitizer.ThreadStackReuseTest
[       OK ] AddressSanitizer.ThreadStackReuseTest (8 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN      ] AddressSanitizer.UseThenFreeThenUseTest
[       OK ] AddressSanitizer.UseThenFreeThenUseTest (124 ms)
[ RUN      ] AddressSanitizer.FileNameInGlobalReportTest
[       OK ] AddressSanitizer.FileNameInGlobalReportTest (111 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN      ] AddressSanitizer.MlockTest
[       OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN      ] AddressSanitizer.LongDoubleNegativeTest
[       OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[----------] 19 tests from AddressSanitizer (27953 ms total)

[----------] Global test environment tear-down
[==========] 22 tests from 2 test suites ran. (27956 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST

Step 34 (run instrumented asan tests [aarch64/bluejay-userdebug/TQ3A.230805.001]) failure: run instrumented asan tests [aarch64/bluejay-userdebug/TQ3A.230805.001] (failure)
...
[ RUN      ] AddressSanitizer.HasFeatureAddressSanitizerTest
[       OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN      ] AddressSanitizer.CallocReturnsZeroMem
[       OK ] AddressSanitizer.CallocReturnsZeroMem (13 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN      ] AddressSanitizer.IgnoreTest
[       OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN      ] AddressSanitizer.SignalTest
[       OK ] AddressSanitizer.SignalTest (203 ms)
[ RUN      ] AddressSanitizer.ReallocTest
[       OK ] AddressSanitizer.ReallocTest (37 ms)
[ RUN      ] AddressSanitizer.WrongFreeTest
[       OK ] AddressSanitizer.WrongFreeTest (119 ms)
[ RUN      ] AddressSanitizer.LongJmpTest
[       OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN      ] AddressSanitizer.ThreadStackReuseTest
[       OK ] AddressSanitizer.ThreadStackReuseTest (8 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN      ] AddressSanitizer.UseThenFreeThenUseTest
[       OK ] AddressSanitizer.UseThenFreeThenUseTest (124 ms)
[ RUN      ] AddressSanitizer.FileNameInGlobalReportTest
[       OK ] AddressSanitizer.FileNameInGlobalReportTest (111 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN      ] AddressSanitizer.MlockTest
[       OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN      ] AddressSanitizer.LongDoubleNegativeTest
[       OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[----------] 19 tests from AddressSanitizer (27953 ms total)

[----------] Global test environment tear-down
[==========] 22 tests from 2 test suites ran. (27956 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST
program finished with exit code 0
elapsedTime=2335.070564

Meinersbur added a commit that referenced this pull request Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' cmake Build system in general and CMake in particular flang:driver flang:fir-hlfir flang:openmp flang:semantics flang Flang issues not falling into any other category openmp:libomp OpenMP host runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants