Skip to content

Commit c9255f4

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6
2 parents 5db4aea + c9664cb commit c9255f4

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

clang/include/clang/Basic/SanitizerSpecialCaseList.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@ class SanitizerSpecialCaseList : public llvm::SpecialCaseList {
4343
bool inSection(SanitizerMask Mask, StringRef Prefix, StringRef Query,
4444
StringRef Category = StringRef()) const;
4545

46+
// Query ignorelisted entries if any bit in Mask matches the entry's section.
47+
// Return 0 if not found. If found, return the line number (starts with 1).
48+
unsigned inSectionBlame(SanitizerMask Mask, StringRef Prefix, StringRef Query,
49+
StringRef Category = StringRef()) const;
50+
4651
protected:
4752
// Initialize SanitizerSections.
4853
void createSanitizerSections();
4954

5055
struct SanitizerSection {
5156
SanitizerSection(SanitizerMask SM, SectionEntries &E)
52-
: Mask(SM), Entries(E){};
57+
: Mask(SM), Entries(E) {};
5358

5459
SanitizerMask Mask;
5560
SectionEntries &Entries;

clang/lib/Basic/NoSanitizeList.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ bool NoSanitizeList::containsFunction(SanitizerMask Mask,
4444

4545
bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
4646
StringRef Category) const {
47+
unsigned NoSanLine = SSCL->inSectionBlame(Mask, "src", FileName, Category);
48+
unsigned SanLine = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize");
49+
// If we have two cases such as `src:a.cpp=sanitize` and `src:a.cpp`, the
50+
// current entry override the previous entry.
51+
if (NoSanLine > 0 && SanLine > 0)
52+
return NoSanLine > SanLine;
4753
return SSCL->inSection(Mask, "src", FileName, Category);
4854
}
4955

clang/lib/Basic/SanitizerSpecialCaseList.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,20 @@ void SanitizerSpecialCaseList::createSanitizerSections() {
5656
bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, StringRef Prefix,
5757
StringRef Query,
5858
StringRef Category) const {
59-
for (auto &S : SanitizerSections)
60-
if ((S.Mask & Mask) &&
61-
SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category))
62-
return true;
59+
return inSectionBlame(Mask, Prefix, Query, Category) > 0;
60+
}
6361

64-
return false;
62+
unsigned SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask,
63+
StringRef Prefix,
64+
StringRef Query,
65+
StringRef Category) const {
66+
for (auto &S : SanitizerSections) {
67+
if (S.Mask & Mask) {
68+
unsigned lineNum =
69+
SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category);
70+
if (lineNum > 0)
71+
return lineNum;
72+
}
73+
}
74+
return 0;
6575
}

clang/test/CodeGen/ubsan-src-ignorelist-category.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
// 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-prefixes=CHECK2
55

6-
// 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-prefixes=CHECK1,IGNORE
6+
// 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-prefixes=CHECK1,SANITIZE
77
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist.contradict1 -emit-llvm %t/test1.c -o - | FileCheck %s --check-prefixes=CHECK1,IGNORE
8-
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist.contradict2 -emit-llvm %t/test1.c -o - | FileCheck %s --check-prefixes=CHECK1,IGNORE
8+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist.contradict2 -emit-llvm %t/test1.c -o - | FileCheck %s --check-prefixes=CHECK1,SANITIZE
99
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist.contradict3 -emit-llvm %t/test1.c -o - | FileCheck %s --check-prefixes=CHECK1,IGNORE
10-
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist.contradict4 -emit-llvm %t/test1.c -o - | FileCheck %s --check-prefixes=CHECK1,IGNORE
10+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist.contradict4 -emit-llvm %t/test1.c -o - | FileCheck %s --check-prefixes=CHECK1,SANITIZE
1111

1212

1313
// Verify ubsan only emits checks for files in the allowlist

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
6363
.moveInto(Pair.first))
6464
return Err;
6565
Pair.second = LineNumber;
66+
} else {
67+
// We should update the new line number if an entry with the same pattern
68+
// repeats.
69+
auto &Pair = It->getValue();
70+
Pair.second = LineNumber;
6671
}
6772
return Error::success();
6873
}

0 commit comments

Comments
 (0)