CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
98 lines
3.3 KiB
ReStructuredText
98 lines
3.3 KiB
ReStructuredText
============================
|
|
Warning suppression mappings
|
|
============================
|
|
|
|
.. contents::
|
|
:local:
|
|
|
|
Introduction
|
|
============
|
|
|
|
Warning suppression mappings enable users to suppress Clang's diagnostics at a
|
|
per-file granularity. This allows enforcing diagnostics in specific parts of the
|
|
project even if there are violations in some headers.
|
|
|
|
Goal and usage
|
|
==============
|
|
|
|
Clang allows diagnostics to be configured at a translation-unit granularity.
|
|
If a ``foo.cpp`` is compiled with ``-Wfoo``, all transitively included headers
|
|
also need to be clean. Hence, turning on new warnings in large codebases
|
|
requires cleaning up all the existing warnings. This might not be possible when
|
|
some dependencies aren't in the project owner's control or because new
|
|
violations are creeping up quicker than the clean up.
|
|
|
|
Warning suppression mappings aim to alleviate some of these concerns by making
|
|
diagnostic configuration granularity finer, at a source file level.
|
|
|
|
To achieve this, user can create a file that lists which :doc:`diagnostic
|
|
groups <DiagnosticsReference>` to suppress in which files or paths, and pass it
|
|
as a command line argument to Clang with the ``--warning-suppression-mappings``
|
|
flag.
|
|
|
|
Note that this mechanism won't enable any diagnostics on its own. Users should
|
|
still turn on warnings in their compilations with explicit ``-Wfoo`` flags.
|
|
`Controlling diagnostics pragmas
|
|
<https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas>`_
|
|
take precedence over suppression mappings. Ensuring code author's explicit
|
|
intent is always preserved.
|
|
|
|
Example
|
|
=======
|
|
|
|
.. code-block:: bash
|
|
|
|
$ cat my/user/code.cpp
|
|
#include <foo/bar.h>
|
|
namespace { void unused_func1(); }
|
|
|
|
$ cat foo/bar.h
|
|
namespace { void unused_func2(); }
|
|
|
|
$ cat suppression_mappings.txt
|
|
# Suppress -Wunused warnings in all files, apart from the ones under `foo/`.
|
|
[unused]
|
|
src:*
|
|
src:*foo/*=emit
|
|
$ clang -Wunused --warning-suppression-mappings=suppression_mappings.txt my/user/code.cpp
|
|
# prints warning: unused function 'unused_func2', but no warnings for `unused_func1`.
|
|
|
|
Format
|
|
======
|
|
|
|
Warning suppression mappings uses the same format as
|
|
:doc:`SanitizerSpecialCaseList`.
|
|
|
|
Sections describe which diagnostic group's behavior to change, e.g.
|
|
``[unused]``. When a diagnostic is matched by multiple sections, the latest
|
|
section takes precedence.
|
|
|
|
Afterwards in each section, users can have multiple entities that match source
|
|
files based on the globs. These entities look like ``src:*/my/dir/*``.
|
|
Users can also use the ``emit`` category to exclude a subdirectory from
|
|
suppression.
|
|
Source files are matched against these globs either:
|
|
|
|
- as paths relative to the current working directory
|
|
- as absolute paths.
|
|
|
|
When a source file matches multiple globs in a section, the last one takes
|
|
precedence.
|
|
|
|
.. code-block:: bash
|
|
|
|
# Lines starting with # are ignored.
|
|
# Configure suppression globs for `-Wunused` warnings
|
|
[unused]
|
|
# Suppress on all files by default.
|
|
src:*
|
|
# But enforce for all the sources under foo/.
|
|
src:*foo/*=emit
|
|
|
|
# unused-function warnings are a subgroup of `-Wunused`. So this section
|
|
# takes precedence over the previous one for unused-function warnings, but
|
|
# not for unused-variable warnings.
|
|
[unused-function]
|
|
# Only suppress for sources under bar/.
|
|
src:*bar/*
|