0

Add warning suppression mapping file to the build

This adds an (empty) warning suppression mapping file, per the linked bug. It controls its use by adding a new gn arg pointing to the file, and passing the WSM to each clang compilation if the arg is set. Since the arg is set in our `.gn` file, consumers of our `build/` directory will see no change, but can choose to use their own WSM file if they wish.

It also contains some hacks/configs to make sure the file gets uploaded by reclient/siso.

So far, the file is unused, but we'll start filling it out as we make progress enabling warnings.

Change-Id: I0493109c1c365643b97de937286ca7d0a4f89729
Bug: 404297941
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6344734
Reviewed-by: Hans Wennborg <hans@chromium.org>
Commit-Queue: Devon Loehr <dloehr@google.com>
Cr-Commit-Position: refs/heads/main@{#1438081}
This commit is contained in:
Devon Loehr 2025-03-26 06:55:13 -07:00 committed by Chromium LUCI CQ
parent 8e6856106c
commit b9f7ffacaa
7 changed files with 63 additions and 9 deletions

1
.gn

@ -74,6 +74,7 @@ default_args = {
devtools_visibility = [ "*" ]
clang_unsafe_buffers_paths = "//build/config/unsafe_buffers_paths.txt"
clang_warning_suppression_file = "//build/config/warning_suppression.txt"
}
# These are the targets to skip header checking by default. The files in targets

@ -184,6 +184,7 @@ declare_args() {
# Unsafe buffers. Location of file used by plugins to track portions of
# the codebase which have been made manifestly safe.
clang_unsafe_buffers_paths = ""
clang_warning_suppression_file = ""
}
# ==============================================================================

@ -5,3 +5,8 @@ per-file cast.gni=file://build/config/chromecast/OWNERS
per-file unsafe_buffers_paths.txt=arthursonzogni@chromium.org
per-file unsafe_buffers_paths.txt=tsepez@chromium.org
per-file warning_suppression.txt=dloehr@google.com
per-file warning_suppression.txt=thakis@chromium.org
per-file warning_suppression.txt=hans@chromium.org
per-file warning_suppression.txt=tsepez@chromium.org

@ -51,18 +51,26 @@ lld_emit_indexes_and_imports =
lld_emit_indexes_and_imports && is_a_target_toolchain
# TODO(crbug.com/326584510): Reclient does not upload `inputs` from C/C++
# targets. This file is added to `inputs` for all C targets in
# //build/config/BUILDCONFIG.gn via //build/config/clang:unsafe_buffers.
# We work around the bug in Reclient by specifying the file here.
#
# This is a comma-delimited list of paths relative to the source tree root. The
# leading space is important, if the string is non-empty. :)
rbe_bug_326584510_missing_inputs = ""
# targets. We work around the bug in Reclient by
# specifying the files here.
rbe_bug_326584510_missing_input_list = []
if (clang_use_chrome_plugins && defined(clang_unsafe_buffers_paths) &&
"$clang_unsafe_buffers_paths" != "") {
if (rbe_exec_root != rebase_path("//")) {
assert(!use_siso, "Can't use non-default rbe_exec_root with siso.")
}
from_exec_root = rebase_path(clang_unsafe_buffers_paths, rbe_exec_root)
rbe_bug_326584510_missing_inputs = " -inputs=$from_exec_root"
rbe_bug_326584510_missing_input_list +=
[ rebase_path(clang_unsafe_buffers_paths, rbe_exec_root) ]
}
if (defined(clang_warning_suppression_file) &&
"$clang_warning_suppression_file" != "") {
if (rbe_exec_root != rebase_path("//")) {
assert(!use_siso, "Can't use non-default rbe_exec_root with siso.")
}
rbe_bug_326584510_missing_input_list +=
[ rebase_path(clang_warning_suppression_file, rbe_exec_root) ]
}
# The leading space is important, if the string is non-empty.
rbe_bug_326584510_missing_inputs =
" -inputs=" + string_join(",", rbe_bug_326584510_missing_input_list)

@ -312,6 +312,7 @@ config("compiler") {
":compiler_cpu_abi",
":compiler_codegen",
":compiler_deterministic",
":clang_warning_suppression",
]
# Here we enable -fno-delete-null-pointer-checks, which makes various nullptr
@ -1650,6 +1651,31 @@ config("clang_revision") {
}
}
# Controls the usage of a warning suppression mapping (WSM) file to suppress
# warnings based on the path of the file they come from. It's controlled by the
# `clang_warning_suppression_file` gn argument , which points to a text file
# defining which warnings should be suppressed where.
# See //build/config/warning_suppression.txt for an example file; this is the
# file used by Chromium.
#
# To use a different file, or to use this functionality outside of chromium,
# set the `clang_warning_suppression_file` argument to point to the new file,
# e.g. by setting in the the project's .gn file.
config("clang_warning_suppression") {
# Some build configs use older versions of clang that don't support WSMs
if (!is_nacl && default_toolchain != "//build/toolchain/cros:target" &&
!llvm_android_mainline && is_clang &&
clang_warning_suppression_file != "") {
from_build_root =
rebase_path(clang_warning_suppression_file, root_build_dir)
inputs = [ clang_warning_suppression_file ]
cflags = [
"-Xclang",
"--warning-suppression-mappings=" + from_build_root,
]
}
}
config("rustc_revision") {
if (rustc_revision != "") {
# Similar to the above config, this is here so that all files get recompiled

@ -87,15 +87,19 @@ __input_deps = {
],
"third_party/llvm-build/Release+Asserts/bin/clang": [
"build/config/unsafe_buffers_paths.txt",
"build/config/warning_suppression.txt",
],
"third_party/llvm-build/Release+Asserts/bin/clang++": [
"build/config/unsafe_buffers_paths.txt",
"build/config/warning_suppression.txt",
],
"third_party/llvm-build/Release+Asserts/bin/clang-cl": [
"build/config/unsafe_buffers_paths.txt",
"build/config/warning_suppression.txt",
],
"third_party/llvm-build/Release+Asserts/bin/clang-cl.exe": [
"build/config/unsafe_buffers_paths.txt",
"build/config/warning_suppression.txt",
],
"third_party/llvm-build/Release+Asserts/bin/lld-link": [
"build/config/c++/libc++.natvis",

@ -0,0 +1,9 @@
# Copyright 2025 The Chromium Project. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Warning suppression mappings are listed here on a per-warning basis.
# Upstream docs: https://clang.llvm.org/docs/WarningSuppressionMappings.html
# We'll put the policy here too when it's written.
# Don't use this file until the policy is written.
# See crbug.com/404297941 for more information.