-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[NoSanitizeList][NFI] Add containsPrefix to remove duplicated logics. #142027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NoSanitizeList][NFI] Add containsPrefix to remove duplicated logics. #142027
Conversation
Created using spr 1.3.6 [skip ci]
Created using spr 1.3.6
@llvm/pr-subscribers-clang Author: Qinkun Bao (qinkunbao) ChangesFull diff: https://github.com/llvm/llvm-project/pull/142027.diff 2 Files Affected:
diff --git a/clang/include/clang/Basic/NoSanitizeList.h b/clang/include/clang/Basic/NoSanitizeList.h
index 43415859fcd54..4a546351bb66d 100644
--- a/clang/include/clang/Basic/NoSanitizeList.h
+++ b/clang/include/clang/Basic/NoSanitizeList.h
@@ -29,7 +29,8 @@ class SanitizerSpecialCaseList;
class NoSanitizeList {
std::unique_ptr<SanitizerSpecialCaseList> SSCL;
SourceManager &SM;
-
+ bool containsPrefix(SanitizerMask Mask,StringRef Prefix, StringRef Name,
+ StringRef Category = StringRef()) const;
public:
NoSanitizeList(const std::vector<std::string> &NoSanitizeListPaths,
SourceManager &SM);
diff --git a/clang/lib/Basic/NoSanitizeList.cpp b/clang/lib/Basic/NoSanitizeList.cpp
index 9f0f1c64995cb..671430dfe6293 100644
--- a/clang/lib/Basic/NoSanitizeList.cpp
+++ b/clang/lib/Basic/NoSanitizeList.cpp
@@ -27,6 +27,15 @@ NoSanitizeList::NoSanitizeList(const std::vector<std::string> &NoSanitizePaths,
NoSanitizeList::~NoSanitizeList() = default;
+bool NoSanitizeList::containsPrefix(SanitizerMask Mask, StringRef Prefix,
+ StringRef Name, StringRef Category) const {
+ auto NoSan = SSCL->inSectionBlame(Mask, Prefix, Name, Category);
+ if (NoSan == llvm::SpecialCaseList::NotFound)
+ return false;
+ auto San = SSCL->inSectionBlame(Mask, Prefix, Name, "sanitize");
+ 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 +43,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 +53,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,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ntainsprefix-to-remove-duplicated-logics
…ntainsprefix-to-remove-duplicated-logics
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new helper function, containsPrefix, to deduplicate the logic used for checking sanitizer entries based on a prefix and category. The changes update the containsType and containsFile functions to reuse the new helper function.
- Added containsPrefix method in NoSanitizeList.cpp and its declaration in NoSanitizeList.h.
- Refactored containsType and containsFile to call containsPrefix.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
clang/lib/Basic/NoSanitizeList.cpp | Added containsPrefix and refactored containsType/containsFile functions |
clang/include/clang/Basic/NoSanitizeList.h | Declared the new containsPrefix method |
Created using spr 1.3.6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the NoSanitizeList logic by introducing a new containsPrefix method to remove duplicated logic in checks for types and files.
- Adds containsPrefix to encapsulate common logic for section blame comparisons.
- Updates containsType and containsFile to use the new containsPrefix method.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
clang/lib/Basic/NoSanitizeList.cpp | Adds the containsPrefix method and refactors methods to use it. |
clang/include/clang/Basic/NoSanitizeList.h | Adds method declaration for containsPrefix. |
return false; | ||
auto San = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize"); | ||
return San == llvm::SpecialCaseList::NotFound || NoSan > San; | ||
return containsPrefix(Mask, "src", FileName, Category); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update all other cases in the next patch
Fell free to have a single trivial test per prefix, e.g. just check that makes a difference.
fun:*=sanitize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to update one prefix one PR. Do you think will it be a good idea to update all other cases in one PR?
Currently, I have a pull request updating "fun" and am running tests before sending it to you for review.
#142074
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a preference, change is trivial per prefix.
See #142006 and #139128