File chromium-warning-suppression-mappings.patch of Package chromium

From b9f7ffacaa06eb2b1ef1d8f1600845a048ada0d6 Mon Sep 17 00:00:00 2001
From: Devon Loehr <[email protected]>
Date: Wed, 26 Mar 2025 06:55:13 -0700
Subject: [PATCH] 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 <[email protected]>
Commit-Queue: Devon Loehr <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1438081}

diff --git a/.gn b/.gn
index 3f65718281973..54d2631ec2032 100644
--- a/.gn
+++ b/.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
diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn
index 3f3ea354f3ee6..a9d2caeb1c92e 100644
--- a/build/config/BUILDCONFIG.gn
+++ b/build/config/BUILDCONFIG.gn
@@ -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 = ""
 }
 
 # ==============================================================================
diff --git a/build/config/OWNERS b/build/config/OWNERS
index 8a097f03eee10..2dbcc3916d893 100644
--- a/build/config/OWNERS
+++ b/build/config/OWNERS
@@ -5,3 +5,8 @@ per-file cast.gni=file://build/config/chromecast/OWNERS
 
 per-file [email protected]
 per-file [email protected]
+
+per-file [email protected]
+per-file [email protected]
+per-file [email protected]
+per-file [email protected]
diff --git a/build/config/clang/clang.gni b/build/config/clang/clang.gni
index e120a847c6d43..2ad331d38f6b6 100644
--- a/build/config/clang/clang.gni
+++ b/build/config/clang/clang.gni
@@ -51,19 +51,20 @@
     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" != "") {
+  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)
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index 037d3b769add3..5b07f038e6bab 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -313,8 +313,19 @@
     ":rustc_revision",
     ":compiler_codegen",
     ":compiler_deterministic",
+    ":clang_warning_suppression",
   ]
 
+  # TODO(https://crbug.com/404297941): Disable clang_warning_suppression
+  # configuration because the ICECC build doesn't distribute the
+  # warning_suppression.txt file to other ICECC nodes. As a result, the nodes
+  # cannot locate the file during target compilation. Therefore, we are
+  # disabling the clang_warning_suppression configuration for ICECC builds for
+  # now.
+  if (cc_wrapper == "icecc") {
+    configs -= [ ":clang_warning_suppression" ]
+  }
+
   # Here we enable -fno-delete-null-pointer-checks, which makes various nullptr
   # operations (e.g. dereferencing) into defined behavior. This avoids deletion
   # of some security-critical code: see https://crbug.com/1139129.
@@ -1544,6 +1555,28 @@
   }
 }
 
+# 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 = [ "--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
diff --git a/build/config/siso/clang_all.star b/build/config/siso/clang_all.star
index 9aea43bd81883..ca062f967b5d1 100644
--- a/build/config/siso/clang_all.star
+++ b/build/config/siso/clang_all.star
@@ -13,6 +13,7 @@
 
 __clang_plugin_configs = [
     "build/config/unsafe_buffers_paths.txt",
+    "build/config/warning_suppression.txt",
     # crbug.com/418842344: Angle, PDFium use a different plugin config.
     "unsafe_buffers_paths.txt",
 ]
diff --git a/build/config/warning_suppression.txt b/build/config/warning_suppression.txt
new file mode 100644
index 0000000000000..4f78ea84d3a93
--- /dev/null
+++ b/build/config/warning_suppression.txt
@@ -0,0 +1,37 @@
+# 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.
+
+# This file is used to suppress warnings based on the file they originate from,
+# as opposed to disabling warnings via -Wno flags which apply to all the files
+# involved in each compilation. For more information, see
+# https://clang.llvm.org/docs/WarningSuppressionMappings.html
+# For background information on their use in chromium, see crbug.com/404297941
+
+# Warning Suppression Policy: updates to this file should be tightly controlled,
+# for reasons discussed in crbug.com/404297941. In particular:
+#
+# 1. This file should never grow (as measured by the number of files suppressed)
+#    except when a new warning is enabled.
+# 2. This file should only be used to opt out whole directories, never
+#    individual files.
+# 3. This file should be used as a last resort; if it's possible to fix the warning or suppress
+#    it without using the file, do so.
+#    1. For first-party code, just fix it directly, or use `#pragma GCC diagnostic ignored`.
+#    2. For third-party code, first attempt to fix it upstream.
+#    3. If that's not possible, attempt to suppress the warning using `-Wno` flags in a gn file.
+# 4. All entries should have a path to eventually be removed.
+#
+# In practice, rules (3) and (4) mean that the only accepted use case for this file is to
+# speed up rolls or enable a warning slightly sooner, for cases where an upstream fix has been
+# proposed but is likely to take a long time to get merged and rolled into chromium.
+#
+# We may make an exception to the policy for extremely high-value warnings that backslide a lot
+# (such as unsafe buffers), but this is expected to be rare.
+
+# Formatting note: Don't put comments on the same line as a glob pattern! Clang
+# will get confused and the warning won't be suppressed.
+
+[unnecessary-virtual-specifier]
+# Can be removed when https://github.com/google/nearby/pull/3392 is merged and rolled
+src:*/third_party/nearby/*
\ No newline at end of file
openSUSE Build Service is sponsored by
OSZAR »