[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 17 19:31:43 PDT 2024


================
@@ -1,7 +1,28 @@
+// Verify ubsan doesn't emit checks for ignorelisted types
+// RUN: echo "[{unsigned-integer-overflow,signed-integer-overflow}]" > %t-int.ignorelist
+// RUN: echo "type:int" >> %t-int.ignorelist
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t-int.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=INT
+
+// RUN: echo "type:int" > %t-nosection.ignorelist
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t-nosection.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=INT
+
+// RUN: echo "type:int=allow" > %t-allow-same-as-no-category.ignorelist
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t-allow-same-as-no-category.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=INT
+
+// RUN: echo "[{unsigned-integer-overflow,signed-integer-overflow}]" > %t-myty.ignorelist
+// RUN: echo "type:*" >> %t-myty.ignorelist
+// RUN: echo "type:myty=skip" >> %t-myty.ignorelist
----------------
vitalybuka wrote:

I don't see a benefit of keeping all this test in one file
it will only to degrade readability and debugging

N files like this seems better
```
// RUN: rm -rf %t
// RUN: split-file %s %t

// Verify ubsan doesn't emit checks for ignorelisted types
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t/test.ignorelist -emit-llvm %t/test.cpp -o - | FileCheck %s --check-prefix=INT --implicit-check-not="call {{.*}} @llvm"

//--- test.cpp
// INT-LABEL: ignore_int
void ignore_int(int A, int B, unsigned C, unsigned D, long E) {
// INT: llvm.uadd.with.overflow.i32
  (void)(C+D);
  (void)(A+B);
// INT: llvm.sadd.with.overflow.i64
  (void)(++E);
}

//--- test.ignorelist
[{unsigned-integer-overflow,signed-integer-overflow}]
type:int
```

Note1: Use `split-file`
Note2: Use `implicit-check-not` instead of -NOT. 

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


More information about the cfe-commits mailing list