9 Commits

Author SHA1 Message Date
Qinkun Bao
43bb68b455
[Sanitizer][Ignorelist] Expanding =sanitize to mainfile. (#142472)
See https://github.com/llvm/llvm-project/issues/139128
If multiple entries match the source, than the latest entry takes the
precedence.
2025-06-02 17:48:59 -04:00
Qinkun Bao
43c2234249
[Sanitizer][Ignorelist] Expanding =sanitize to global. (#142456)
See https://github.com/llvm/llvm-project/issues/139128
If multiple entries match the source, than the latest entry takes the
precedence.`
2025-06-02 17:47:12 -04:00
Qinkun Bao
d313c09b28
[UBSan][Ignorelist] Expanding =sanitize to fun. (#142074)
See https://github.com/llvm/llvm-project/issues/139128
If multiple entries match the source, than the latest entry takes the
precedence.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-02 17:08:04 -04:00
Qinkun Bao
2a3afa2feb
[NoSanitizeList][NFI] Add containsPrefix to remove duplicated logics. (#142027)
See https://github.com/llvm/llvm-project/pull/142006 and
https://github.com/llvm/llvm-project/issues/139128

---------

Co-authored-by: Vitaly Buka <vitalybuka@google.com>
2025-05-30 05:26:41 -04:00
Qinkun Bao
f9073e7e62
[UBSan] Move type:*=sanitize handling. (#142006)
As discussed in https://github.com/llvm/llvm-project/issues/139128, this
PR moves =sanitize handling from `ASTContext::isTypeIgnoredBySanitizer`
to `NoSanitizeList::containsType`.

Before this PR: "=sanitize" has priority regardless of the order
After this PR: If multiple entries match the source, than the latest
entry takes the precedence.
2025-05-29 19:38:33 -04:00
Qinkun Bao
45b874bc57
[UBSan] Support src:*=sanitize for multiple ignorelists. (#141640)
See: https://github.com/llvm/llvm-project/issues/139128 and
https://github.com/llvm/llvm-project/pull/140529 for the background.

The introduction of these new tests (ubsan-src-ignorelist-category.test)
`-fsanitize-ignorelist=%t/src.ignorelist
-fsanitize-ignorelist=%t/src.ignorelist.contradict9` in this PR will not
lead to failures in the previous implementation (without this PR). This
is because the existing logic distinguishes between Sections in
different ignorelists, even if their names are identical. The order of
these Sections is preserved using a `vector`.
2025-05-28 11:12:53 -04:00
Qinkun Bao
4f1291e484
[UBSan] Implement src:*=sanitize for UBSan (#140529)
Background: https://github.com/llvm/llvm-project/issues/139128

It is a draft implementation for "src:*=sanitize". It should be applied
to all sanitizers.

Any srcs assigned to the sanitize category will have their sanitizer
instrumentation remained ignored by "src:". For example,

```
src:*
src:*/test1.cc=sanitize
```

`test1.cc` will still have the UBSan instrumented.

Conflicting entries are resolved by the latest entry, which takes
precedence.

```
src:*
src:*/mylib/*=sanitize
src:*/mylib/test.cc
```
`test.cc` does not have the UBSan check (In this case,
`src:*/mylib/test.cc` overrides `src:*/mylib/*=sanitize` for `test.cc`).

```
src:*
src:*/mylib/test.cc
src:*/mylib/*=sanitize
```

`test1.cc` has the UBSan instrumented (In this case,
`src:*/mylib/*=sanitize` overrides `src:*/mylib/test.cc`).

Documents update will be in a new PR.
2025-05-27 19:19:25 -07:00
Fangrui Song
0d5a62faca [sanitizer] Add "mainfile" prefix to sanitizer special case list
When an issue exists in the main file (caller) instead of an included file
(callee), using a `src` pattern applying to the included file may be
inappropriate if it's the caller's responsibility. Add `mainfile` prefix to check
the main filename.

For the example below, the issue may reside in a.c (foo should not be called
with a misaligned pointer or foo should switch to an unaligned load), but with
`src` we can only apply to the innocent callee a.h. With this patch we can use
the more appropriate `mainfile:a.c`.
```
//--- a.h
// internal linkage
static inline int load(int *x) { return *x; }

//--- a.c, -fsanitize=alignment
#include "a.h"
int foo(void *x) { return load(x); }
```

See the updated clang/docs/SanitizerSpecialCaseList.rst for a caveat due
to C++ vague linkage functions.

Reviewed By: #sanitizers, kstoimenov, vitalybuka

Differential Revision: https://reviews.llvm.org/D129832
2022-07-15 10:39:26 -07:00
Melanie Blower
e64fcdf8d5 [clang][patch] Inclusive language, modify filename SanitizerBlacklist.h to NoSanitizeList.h
This patch responds to a comment from @vitalybuka in D96203: suggestion to
do the change incrementally, and start by modifying this file name. I modified
the file name and made the other changes that follow from that rename.

Reviewers: vitalybuka, echristo, MaskRay, jansvoboda11, aaron.ballman

Differential Revision: https://reviews.llvm.org/D96974
2021-02-22 15:11:37 -05:00