Skip to content

Commit d313c09

Browse files
qinkunbaoCopilot
andauthored
[UBSan][Ignorelist] Expanding =sanitize to fun. (#142074)
See #139128 If multiple entries match the source, than the latest entry takes the precedence. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 09cd3ed commit d313c09

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

clang/lib/Basic/NoSanitizeList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool NoSanitizeList::containsType(SanitizerMask Mask, StringRef MangledTypeName,
5454

5555
bool NoSanitizeList::containsFunction(SanitizerMask Mask,
5656
StringRef FunctionName) const {
57-
return SSCL->inSection(Mask, "fun", FunctionName);
57+
return containsPrefix(Mask, "fun", FunctionName, {});
5858
}
5959

6060
bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
4+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t/order-0.ignorelist -emit-llvm %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,SANITIZE
5+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t/order-1.ignorelist -emit-llvm %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,IGNORE
6+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t/order-2.ignorelist -emit-llvm %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,SANITIZE
7+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t/order-3.ignorelist -emit-llvm %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,IGNORE
8+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t/order-4.ignorelist -emit-llvm %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,SANITIZE
9+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t/order-5.ignorelist -emit-llvm %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,IGNORE
10+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t/order-6.ignorelist -emit-llvm %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,SANITIZE
11+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t/order-7.ignorelist -emit-llvm %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,IGNORE
12+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t/order-8.ignorelist -emit-llvm %t/test.c -o - | FileCheck %s --check-prefixes=CHECK,SANITIZE
13+
14+
15+
// The same type can appear multiple times within an ignorelist. Any ``=sanitize`` type
16+
// entries enable sanitizer instrumentation, even if it was ignored by entries before.
17+
// If multiple entries match the source, then the latest entry takes the
18+
// precedence.
19+
20+
21+
//--- order-0.ignorelist
22+
fun:add
23+
fun:add=sanitize
24+
25+
//--- order-1.ignorelist
26+
fun:add=sanitize
27+
fun:add
28+
29+
//--- order-2.ignorelist
30+
fun:ad*
31+
fun:add=sanitize
32+
33+
//--- order-3.ignorelist
34+
fun:ad*=sanitize
35+
fun:add
36+
37+
//--- order-4.ignorelist
38+
fun:add
39+
fun:ad*=sanitize
40+
41+
//--- order-5.ignorelist
42+
fun:add=sanitize
43+
fun:ad*
44+
45+
//--- order-6.ignorelist
46+
fun:add
47+
fun:add=sanitize
48+
fun:a*d
49+
fun:*dd=sanitize
50+
51+
//--- order-7.ignorelist
52+
[{unsigned-integer-overflow,signed-integer-overflow}]
53+
fun:*
54+
fun:add=sanitize
55+
fun:a*d
56+
fun:*dd=sanitize
57+
[{unsigned-integer-overflow,signed-integer-overflow}]
58+
fun:*
59+
fun:add
60+
fun:a*d=sanitize
61+
fun:*d
62+
63+
//--- order-8.ignorelist
64+
[{unsigned-integer-overflow,signed-integer-overflow}]
65+
fun:*
66+
fun:add
67+
fun:a*d=sanitize
68+
fun:*dd
69+
[{unsigned-integer-overflow,signed-integer-overflow}]
70+
fun:*
71+
fun:add=sanitize
72+
fun:a*d
73+
fun:*dd=sanitize
74+
75+
76+
//--- test.c
77+
// CHECK-LABEL: define dso_local void @add
78+
void add(int A) {
79+
// IGNORE: %inc = add nsw
80+
// SANITIZE: @llvm.sadd.with.overflow.i32
81+
++A;
82+
}
83+

0 commit comments

Comments
 (0)