Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Stitt <justinstitt@google.com>
  • Loading branch information
JustinStitt committed Sep 4, 2024
1 parent 729329f commit 0c1c6e1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
8 changes: 8 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,14 @@ Sanitizers
This new flag should allow those projects to enable integer sanitizers with
less noise.

- Arithmetic overflow sanitizers ``-fsanitize=signed-integer-overflow`` and
``-fsanitize=unsigned-integer-overflow`` as well as the implicit integer
truncation sanitizers ``-fsanitize=implicit-signed-integer-truncation`` and
``-fsanitize=implicit-unsigned-integer-truncation`` now properly support the
"type" prefix within `Sanitizer Special Case Lists (SSCL)
<https://clang.llvm.org/docs/SanitizerSpecialCaseList.html>`_. See that link
for examples.

Python Binding Changes
----------------------
- Fixed an issue that led to crashes when calling ``Type.get_exception_specification_kind``.
Expand Down
62 changes: 60 additions & 2 deletions clang/docs/SanitizerSpecialCaseList.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ file at compile-time.
Goal and usage
==============

Users of sanitizer tools, such as :doc:`AddressSanitizer`, :doc:`ThreadSanitizer`
or :doc:`MemorySanitizer` may want to disable or alter some checks for
Users of sanitizer tools, such as :doc:`AddressSanitizer`,
:doc:`ThreadSanitizer`, :doc:`MemorySanitizer` or :doc:
`UndefinedBehaviorSanitizer` may want to disable or alter some checks for
certain source-level entities to:

* speedup hot function, which is known to be correct;
Expand Down Expand Up @@ -48,6 +49,63 @@ Example
$ clang -fsanitize=address -fsanitize-ignorelist=ignorelist.txt foo.c ; ./a.out
# No error report here.
Usage with UndefinedBehaviorSanitizer
=====================================

The arithmetic overflow sanitizers ``unsigned-integer-overflow`` and
``signed-integer-overflow`` as well as the implicit integer truncation
sanitizers ``implicit-signed-integer-truncation`` and
``implicit-unsigned-integer-truncation`` support the ability to adjust
instrumentation based on type.

.. code-block:: bash
$ cat foo.c
void foo() {
int a = 2147483647; // INT_MAX
++a; // Normally, an overflow with -fsanitize=signed-integer-overflow
}
$ cat ignorelist.txt
[signed-integer-overflow]
type:int
$ clang -fsanitize=signed-integer-overflow -fsanitize-ignorelist=ignorelist.txt foo.c ; ./a.out
# no signed-integer-overflow error
Supplying ``ignorelist.txt`` with ``-fsanitize-ignorelist=ignorelist.txt``
disables overflow sanitizer instrumentation for arithmetic operations
containing values of type ``int``, for example. Custom types may be used.

The following SCL categories are supported: ``=allow``, ``=skip`` and
``=forbid``. The ``allow`` category is the default for any entry and specifies
that the query, if matched, will have its sanitizer instrumentation ignored.
Conversely, both ``skip`` and ``forbid`` cause their queries, if matched, to be
left out of the ignorelist -- essentially ensuring sanitizer instrumentation
remains for those types. This is useful for whitelisting specific types.

With this, one may disable instrumentation for all types and specifically allow
instrumentation for one or many types.

.. code-block:: bash
$ cat ignorelist.txt
[implicit-signed-integer-truncation]
type:*=allow
type:T=skip
$ cat foo.c
typedef char T;
typedef char U;
void foo(int toobig) {
T a = toobig; // instrumented
U b = toobig; // not instrumented
char c = toobig; // also not instrumented
}
Note that ``skip`` and ``forbid`` operate exactly the same in this context and
both options exist simply for conformity with the `-fprofile-list
<https://clang.llvm.org/docs/UsersManual.html#instrumenting-only-selected-files-or-functions>`_
syntax for adjusting profile instrumentation. You do not need to specify any
`default:<type>` for ``-fsanitize-ignorelist`` SSCLs, though.

Format
======

Expand Down

0 comments on commit 0c1c6e1

Please sign in to comment.