[clang] 2a3afa2 - [NoSanitizeList][NFI] Add containsPrefix to remove duplicated logics. (#142027)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 30 02:26:44 PDT 2025
Author: Qinkun Bao
Date: 2025-05-30T05:26:41-04:00
New Revision: 2a3afa2feb90844ad0f8b0bc57663e2aec06cd0a
URL: https://github.com/llvm/llvm-project/commit/2a3afa2feb90844ad0f8b0bc57663e2aec06cd0a
DIFF: https://github.com/llvm/llvm-project/commit/2a3afa2feb90844ad0f8b0bc57663e2aec06cd0a.diff
LOG: [NoSanitizeList][NFI] Add containsPrefix to remove duplicated logics. (#142027)
See https://github.com/llvm/llvm-project/pull/142006 and
https://github.com/llvm/llvm-project/issues/139128
---------
Co-authored-by: Vitaly Buka <vitalybuka at google.com>
Added:
Modified:
clang/include/clang/Basic/NoSanitizeList.h
clang/lib/Basic/NoSanitizeList.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/NoSanitizeList.h b/clang/include/clang/Basic/NoSanitizeList.h
index 43415859fcd54..a7a7a29d50a9a 100644
--- a/clang/include/clang/Basic/NoSanitizeList.h
+++ b/clang/include/clang/Basic/NoSanitizeList.h
@@ -29,6 +29,8 @@ class SanitizerSpecialCaseList;
class NoSanitizeList {
std::unique_ptr<SanitizerSpecialCaseList> SSCL;
SourceManager &SM;
+ bool containsPrefix(SanitizerMask Mask, StringRef Prefix, StringRef Name,
+ StringRef Category) const;
public:
NoSanitizeList(const std::vector<std::string> &NoSanitizeListPaths,
diff --git a/clang/lib/Basic/NoSanitizeList.cpp b/clang/lib/Basic/NoSanitizeList.cpp
index 9f0f1c64995cb..a1ca31ea0e970 100644
--- a/clang/lib/Basic/NoSanitizeList.cpp
+++ b/clang/lib/Basic/NoSanitizeList.cpp
@@ -27,6 +27,21 @@ NoSanitizeList::NoSanitizeList(const std::vector<std::string> &NoSanitizePaths,
NoSanitizeList::~NoSanitizeList() = default;
+bool NoSanitizeList::containsPrefix(SanitizerMask Mask, StringRef Prefix,
+ StringRef Name, StringRef Category) const {
+ std::pair<unsigned, unsigned> NoSan =
+ SSCL->inSectionBlame(Mask, Prefix, Name, Category);
+ if (NoSan == llvm::SpecialCaseList::NotFound)
+ return false;
+ std::pair<unsigned, unsigned> San =
+ SSCL->inSectionBlame(Mask, Prefix, Name, "sanitize");
+ // The statement evaluates to true under the following conditions:
+ // 1. The string "prefix:*=sanitize" is absent.
+ // 2. If "prefix:*=sanitize" is present, its (File Index, Line Number) is less
+ // than that of "prefix:*".
+ return San == llvm::SpecialCaseList::NotFound || NoSan > San;
+}
+
bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName,
StringRef Category) const {
return SSCL->inSection(Mask, "global", GlobalName, Category);
@@ -34,11 +49,7 @@ bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName,
bool NoSanitizeList::containsType(SanitizerMask Mask, StringRef MangledTypeName,
StringRef Category) const {
- auto NoSan = SSCL->inSectionBlame(Mask, "type", MangledTypeName, Category);
- if (NoSan == llvm::SpecialCaseList::NotFound)
- return false;
- auto San = SSCL->inSectionBlame(Mask, "type", MangledTypeName, "sanitize");
- return San == llvm::SpecialCaseList::NotFound || NoSan > San;
+ return containsPrefix(Mask, "type", MangledTypeName, Category);
}
bool NoSanitizeList::containsFunction(SanitizerMask Mask,
@@ -48,11 +59,7 @@ bool NoSanitizeList::containsFunction(SanitizerMask Mask,
bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
StringRef Category) const {
- auto NoSan = SSCL->inSectionBlame(Mask, "src", FileName, Category);
- if (NoSan == llvm::SpecialCaseList::NotFound)
- return false;
- auto San = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize");
- return San == llvm::SpecialCaseList::NotFound || NoSan > San;
+ return containsPrefix(Mask, "src", FileName, Category);
}
bool NoSanitizeList::containsMainFile(SanitizerMask Mask, StringRef FileName,
More information about the cfe-commits
mailing list