[llvm] [cmake] Fix detecting -Wno-pass-failed (PR #162835)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 10 05:13:11 PDT 2025
https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/162835
If testing for a warning option like -Wno-<foo> with GCC, GCC won't print any diagnostic at all, leading to the options being accepted incorrectly. However later, if compiling a file that actually prints another warning, GCC will also print warnings about these -Wno-<foo> options being unrecognized.
This avoids extra warning spam like this, for every source file that does produce warnings with GCC:
At global scope:
cc1plus: note: unrecognized command-line option ‘-Wno-pass-failed’ may have been intended to silence earlier diagnostics
This used to be how most warning options were detected in HandleLLVMOptions.cmake. However, in
4feae05c6abda364a9295aecfa600d7d4e7dfeb6, many of these checks were rewritten to avoid trying compilation and just relying on hardcoded knowledge about which compilers and versions thereof support which warnings, to speed up the cmake configuration.
See e546bbfda0ab91cf78c096d8c035851cc7c3b9f3 for an earlier fix of similar options (for LLDB).
>From 8c253e8799a6f0b0babfdf80935ce2c902f59a7d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Fri, 10 Oct 2025 14:54:25 +0300
Subject: [PATCH] [cmake] Fix detecting -Wno-pass-failed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
If testing for a warning option like -Wno-<foo> with GCC, GCC won't
print any diagnostic at all, leading to the options being accepted
incorrectly. However later, if compiling a file that actually prints
another warning, GCC will also print warnings about these -Wno-<foo>
options being unrecognized.
This avoids extra warning spam like this, for every source file that
does produce warnings with GCC:
At global scope:
cc1plus: note: unrecognized command-line option ‘-Wno-pass-failed’ may have been intended to silence earlier diagnostics
This used to be how most warning options were detected in
HandleLLVMOptions.cmake. However, in
4feae05c6abda364a9295aecfa600d7d4e7dfeb6, many of these checks
were rewritten to avoid trying compilation and just relying on
hardcoded knowledge about which compilers and versions thereof
support which warnings, to speed up the cmake configuration.
See e546bbfda0ab91cf78c096d8c035851cc7c3b9f3 for an earlier
fix of similar options (for LLDB).
---
llvm/cmake/modules/HandleLLVMOptions.cmake | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index c84e2ccab8094..82c8250f61d9e 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -968,7 +968,8 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
# projects and may be injected by pragmas in libstdc++.
# FIXME: Reconsider this choice if warnings from STL headers can be reliably
# avoided (https://github.com/llvm/llvm-project/issues/157666).
- add_flag_if_supported("-Wno-pass-failed" NO_PASS_FAILED_FLAG)
+ check_cxx_compiler_flag("-Wpass-failed" PASS_FAILED_FLAG)
+ append_if(PASS_FAILED_FLAG "-Wno-pass-failed" CMAKE_CXX_FLAGS)
endif (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT LLVM_ENABLE_WARNINGS)
More information about the llvm-commits
mailing list