[libc-commits] [libc] [libc][cmake] Suppress -Wpsabi note on GCC and clean up resource-dir check. (PR #227968)

via libc-commits libc-commits at lists.llvm.org
Wed Sep 30 23:07:20 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: lntue

<details>
<summary>Changes</summary>

- Add `-Wno-psabi` to GCC compile options to suppress ABI change notes for 80-bit long double unions.
- Pass `ERROR_QUIET` to clang-specific `--print-resource-dir` query in `libc/CMakeLists.txt` so it does not output errors on GCC and MSVC.

Assisted-by: Gemini

---
Full diff: https://github.com/llvm/llvm-project/pull/227968.diff


3 Files Affected:

- (modified) libc/CMakeLists.txt (+75-34) 
- (modified) libc/cmake/modules/LLVMLibCCompileOptionRules.cmake (+1) 
- (modified) libc/cmake/modules/LLVMLibCTestRules.cmake (+1) 


``````````diff
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 292e4c90a26a8..ccae01cbc675e 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -127,44 +127,85 @@ set(LIBC_TEST_HERMETIC_ONLY "" OFF CACHE BOOL "Only enable hermetic tests.")
 
 list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT ${LIBC_COMMON_TUNE_OPTIONS})
 
-# Check --print-resource-dir to find the compiler resource dir if this flag
-# is supported by the compiler.
-execute_process(
-  OUTPUT_STRIP_TRAILING_WHITESPACE
-  COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
-  RESULT_VARIABLE COMMAND_RETURN_CODE
-  OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
-)
-# Retrieve the host compiler's resource dir.
-if(COMMAND_RETURN_CODE EQUAL 0)
-  set(COMPILER_RESOURCE_DIR
-    "${COMPILER_RESOURCE_DIR}" CACHE PATH "path to compiler resource dir"
-  )
-  message(STATUS "Set COMPILER_RESOURCE_DIR to "
-    "${COMPILER_RESOURCE_DIR} using --print-resource-dir")
-else()
-  # Try with GCC option: -print-search-dirs, which will output in the form:
-  #   install: <path>
-  #   programs: ........
-  # So we try to capture the <path> after "install: " in the first line of the
-  # output.
-  execute_process(
-    OUTPUT_STRIP_TRAILING_WHITESPACE
-    COMMAND ${CMAKE_CXX_COMPILER} -print-search-dirs
-    RESULT_VARIABLE COMMAND_RETURN_CODE
-    OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
-  )
-  if(COMMAND_RETURN_CODE EQUAL 0)
-    string(REPLACE " " ";" COMPILER_RESOURCE_DIR ${COMPILER_RESOURCE_DIR})
-    string(REPLACE "\n" ";" COMPILER_RESOURCE_DIR "${COMPILER_RESOURCE_DIR}")
-    list(GET COMPILER_RESOURCE_DIR 1 COMPILER_RESOURCE_DIR)
-    message(STATUS "Set COMPILER_RESOURCE_DIR to "
-      "${COMPILER_RESOURCE_DIR} using --print-search-dirs")
+# Find the compiler resource dir for compilers that support it.
+if(NOT DEFINED COMPILER_RESOURCE_DIR OR "${COMPILER_RESOURCE_DIR}" STREQUAL "")
+  if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+    execute_process(
+      COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
+      RESULT_VARIABLE COMMAND_RETURN_CODE
+      OUTPUT_VARIABLE RES_DIR
+      ERROR_QUIET
+      OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+    if(COMMAND_RETURN_CODE EQUAL 0)
+      set(COMPILER_RESOURCE_DIR
+        "${RES_DIR}" CACHE PATH "path to compiler resource dir"
+      )
+      message(STATUS "Set COMPILER_RESOURCE_DIR to "
+        "${COMPILER_RESOURCE_DIR} using --print-resource-dir")
+    endif()
+  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+    execute_process(
+      COMMAND ${CMAKE_CXX_COMPILER} -print-search-dirs
+      RESULT_VARIABLE COMMAND_RETURN_CODE
+      OUTPUT_VARIABLE RES_DIR
+      ERROR_QUIET
+      OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+    if(COMMAND_RETURN_CODE EQUAL 0 AND RES_DIR MATCHES "install:[ \t]*([^\r\n]+)")
+      string(STRIP "${CMAKE_MATCH_1}" RES_DIR)
+      set(COMPILER_RESOURCE_DIR
+        "${RES_DIR}" CACHE PATH "path to compiler resource dir"
+      )
+      message(STATUS "Set COMPILER_RESOURCE_DIR to "
+        "${COMPILER_RESOURCE_DIR} using --print-search-dirs")
+    endif()
+  elseif(MSVC)
+    if(LIBC_TARGET_OS_IS_GPU)
+      message(FATAL_ERROR "COMPILER_RESOURCE_DIR must be set for GPU builds")
+    else()
+      set(COMPILER_RESOURCE_DIR OFF CACHE PATH "path to compiler resource dir")
+      message(STATUS "COMPILER_RESOURCE_DIR not set (not supported by MSVC)")
+    endif()
   else()
+    # Try generic options for other compilers.
+    execute_process(
+      COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
+      RESULT_VARIABLE COMMAND_RETURN_CODE
+      OUTPUT_VARIABLE RES_DIR
+      ERROR_QUIET
+      OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+    if(COMMAND_RETURN_CODE EQUAL 0)
+      set(COMPILER_RESOURCE_DIR
+        "${RES_DIR}" CACHE PATH "path to compiler resource dir"
+      )
+      message(STATUS "Set COMPILER_RESOURCE_DIR to "
+        "${COMPILER_RESOURCE_DIR} using --print-resource-dir")
+    else()
+      execute_process(
+        COMMAND ${CMAKE_CXX_COMPILER} -print-search-dirs
+        RESULT_VARIABLE COMMAND_RETURN_CODE
+        OUTPUT_VARIABLE RES_DIR
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+      )
+      if(COMMAND_RETURN_CODE EQUAL 0 AND RES_DIR MATCHES "install:[ \t]*([^\r\n]+)")
+        string(STRIP "${CMAKE_MATCH_1}" RES_DIR)
+        set(COMPILER_RESOURCE_DIR
+          "${RES_DIR}" CACHE PATH "path to compiler resource dir"
+        )
+        message(STATUS "Set COMPILER_RESOURCE_DIR to "
+          "${COMPILER_RESOURCE_DIR} using --print-search-dirs")
+      endif()
+    endif()
+  endif()
+
+  if(NOT COMPILER_RESOURCE_DIR AND NOT MSVC)
     if(LIBC_TARGET_OS_IS_GPU)
       message(FATAL_ERROR "COMPILER_RESOURCE_DIR must be set for GPU builds")
     else()
-      set(COMPILER_RESOURCE_DIR OFF)
+      set(COMPILER_RESOURCE_DIR OFF CACHE PATH "path to compiler resource dir")
       message(STATUS "COMPILER_RESOURCE_DIR not set
                       --print-resource-dir not supported by host compiler")
     endif()
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 79f2d80bcba7a..d177e0dbcf1f2 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -307,6 +307,7 @@ function(_get_common_compile_options output_var flags)
     if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
       # Silence this warning because _Complex is a part of C99.
       list(APPEND compile_options "-fext-numeric-literals")
+      list(APPEND compile_options "-Wno-psabi")
     else()
       list(APPEND compile_options "-Wno-c99-extensions")
       list(APPEND compile_options "-Wno-gnu-imaginary-constant")
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 917e0ce2a9b05..8c6b078d07f4b 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -90,6 +90,7 @@ function(_get_common_test_compile_options output_var c_test flags)
       if(NOT c_test)
         list(APPEND compile_options "-fext-numeric-literals")
       endif()
+      list(APPEND compile_options "-Wno-psabi")
     else()
       list(APPEND compile_options "-Wno-c99-extensions")
       list(APPEND compile_options "-Wno-gnu-imaginary-constant")

``````````

</details>


https://github.com/llvm/llvm-project/pull/227968


More information about the libc-commits mailing list