Skip to content

Commit 2a3afa2

Browse files
[NoSanitizeList][NFI] Add containsPrefix to remove duplicated logics. (#142027)
See #142006 and #139128 --------- Co-authored-by: Vitaly Buka <vitalybuka@google.com>
1 parent ea096c9 commit 2a3afa2

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
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) const;
3234

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

clang/lib/Basic/NoSanitizeList.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,29 @@ 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 {
3247
return SSCL->inSection(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,
@@ -48,11 +59,7 @@ bool NoSanitizeList::containsFunction(SanitizerMask Mask,
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,

0 commit comments

Comments
 (0)