Skip to content

Commit 1121cf7

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6
2 parents cda1853 + c4296c8 commit 1121cf7

File tree

3 files changed

+104
-12
lines changed

3 files changed

+104
-12
lines changed

clang/include/clang/Basic/NoSanitizeList.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class SanitizerSpecialCaseList;
2929
class NoSanitizeList {
3030
std::unique_ptr<SanitizerSpecialCaseList> SSCL;
3131
SourceManager &SM;
32+
bool containsPrefix(SanitizerMask Mask, StringRef Prefix, StringRef Name,
33+
StringRef Category = StringRef()) const;
3234

3335
public:
3436
NoSanitizeList(const std::vector<std::string> &NoSanitizeListPaths,

clang/lib/Basic/NoSanitizeList.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,39 @@ NoSanitizeList::NoSanitizeList(const std::vector<std::string> &NoSanitizePaths,
2727

2828
NoSanitizeList::~NoSanitizeList() = default;
2929

30+
bool NoSanitizeList::containsPrefix(SanitizerMask Mask, StringRef Prefix,
31+
StringRef Name, StringRef Category) const {
32+
std::pair<unsigned, unsigned> NoSan =
33+
SSCL->inSectionBlame(Mask, Prefix, Name, Category);
34+
if (NoSan == llvm::SpecialCaseList::NotFound)
35+
return false;
36+
std::pair<unsigned, unsigned> San =
37+
SSCL->inSectionBlame(Mask, Prefix, Name, "sanitize");
38+
// The statement evaluates to true under the following conditions:
39+
// 1. The string "prefix:*=sanitize" is absent.
40+
// 2. If "prefix:*=sanitize" is present, its (File Index, Line Number) is less
41+
// than that of "prefix:*".
42+
return San == llvm::SpecialCaseList::NotFound || NoSan > San;
43+
}
44+
3045
bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName,
3146
StringRef Category) const {
32-
return SSCL->inSection(Mask, "global", GlobalName, Category);
47+
return containsPrefix(Mask, "global", GlobalName, Category);
3348
}
3449

3550
bool NoSanitizeList::containsType(SanitizerMask Mask, StringRef MangledTypeName,
3651
StringRef Category) const {
37-
auto NoSan = SSCL->inSectionBlame(Mask, "type", MangledTypeName, Category);
38-
if (NoSan == llvm::SpecialCaseList::NotFound)
39-
return false;
40-
auto San = SSCL->inSectionBlame(Mask, "type", MangledTypeName, "sanitize");
41-
return San == llvm::SpecialCaseList::NotFound || NoSan > San;
52+
return containsPrefix(Mask, "type", MangledTypeName, Category);
4253
}
4354

4455
bool NoSanitizeList::containsFunction(SanitizerMask Mask,
4556
StringRef FunctionName) const {
46-
return SSCL->inSection(Mask, "fun", FunctionName);
57+
return containsPrefix(Mask, "fun", FunctionName);
4758
}
4859

4960
bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
5061
StringRef Category) const {
51-
auto NoSan = SSCL->inSectionBlame(Mask, "src", FileName, Category);
52-
if (NoSan == llvm::SpecialCaseList::NotFound)
53-
return false;
54-
auto San = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize");
55-
return San == llvm::SpecialCaseList::NotFound || NoSan > San;
62+
return containsPrefix(Mask, "src", FileName, Category);
5663
}
5764

5865
bool NoSanitizeList::containsMainFile(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 @test
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)