[clang] Implement src:*=sanitize for UBSan (PR #139772)

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Tue May 13 22:57:43 PDT 2025


================
@@ -0,0 +1,23 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist -emit-llvm %t/test1.c -o - | FileCheck %s -check-prefix=CHECK-ALLOWLIST
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist -emit-llvm %t/test2.c -o - | FileCheck %s -check-prefix=CHECK-IGNORELIST
+
+
+// Verify ubsan only emits checks for files in the allowlist
+
+//--- src.ignorelist
+src:*
----------------
vitalybuka wrote:

So I have some ideas how to fix this:

1. Right now order does not matter, if we say that it's matter now, we don't break existing stuff
2.  Let's make <prefix>=sanitize reset all above <prefix> and <prefix>=<category>
3. So inSection need to return linenum in file which will compare with linenum of =sanitize. There is a version of function for that


Problem: SanitizerSpecialCaseList tracks linenum, but if you check parsing code, it can represent multiple files!

I suggest to start with updating SpecialCaseList to track (fileindex, linenum).

But, SpecialCaseList::Sections for whatever reasons is StringMap,
so it's ordered by name, and it's not used anyway.

Let's first PR to make SpecialCaseList::Sections -> vector<Section> similar SanitizerSpecialCaseList?

https://github.com/llvm/llvm-project/pull/139772


More information about the cfe-commits mailing list