-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[alpha.webkit.UncountedCallArgsChecker] Skip std::forward in tryToFindPtrOrigin. #111222
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…dPtrOrigin. Ignore std::forward when it appears while looking for the pointer origin.
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesIgnore std::forward when it appears while looking for the pointer origin. Full diff: https://github.com/llvm/llvm-project/pull/111222.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 394cb26f03cf99..b7b2f8a16f07b3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -101,6 +101,11 @@ bool tryToFindPtrOrigin(
if (isSingleton(callee))
return callback(E, true);
+ if (callee->isInStdNamespace() && safeGetName(callee) == "forward") {
+ E = call->getArg(0);
+ continue;
+ }
+
if (isPtrConversion(callee)) {
E = call->getArg(0);
continue;
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 97efb354f0371d..b6ab369f69a87d 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -588,6 +588,8 @@ class UnrelatedClass {
getFieldTrivial().nonTrivial23();
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
}
+
+ void setField(RefCounted*);
};
class UnrelatedClass2 {
@@ -598,11 +600,24 @@ class UnrelatedClass2 {
RefCounted &getFieldTrivialRecursively() { return getFieldTrivial().getFieldTrivial(); }
RefCounted *getFieldTrivialTernary() { return Field ? Field->getFieldTernary() : nullptr; }
+ template<typename T, typename ... AdditionalArgs>
+ void callSetField(T&& item, AdditionalArgs&&... args)
+ {
+ item.setField(std::forward<AdditionalArgs>(args)...);
+ }
+
+ template<typename T, typename ... AdditionalArgs>
+ void callSetField2(T&& item, AdditionalArgs&&... args)
+ {
+ item.setField(std::move<AdditionalArgs>(args)...);
+ }
+
void test() {
getFieldTrivialRecursively().trivial1(); // no-warning
getFieldTrivialTernary()->trivial2(); // no-warning
getFieldTrivialRecursively().someFunction();
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
+ callSetField(getFieldTrivial(), refCountedObj()); // no-warning
}
};
|
haoNoQ
approved these changes
Oct 9, 2024
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.
Aha LGTM!
ericastor
pushed a commit
to ericastor/llvm-project
that referenced
this pull request
Oct 10, 2024
…dPtrOrigin. (llvm#111222) Ignore std::forward when it appears while looking for the pointer origin.
DanielCChen
pushed a commit
to DanielCChen/llvm-project
that referenced
this pull request
Oct 16, 2024
…dPtrOrigin. (llvm#111222) Ignore std::forward when it appears while looking for the pointer origin.
rniwa
added a commit
to rniwa/llvm-project
that referenced
this pull request
Feb 3, 2025
…dPtrOrigin. (llvm#111222) Ignore std::forward when it appears while looking for the pointer origin.
devincoughlin
pushed a commit
to swiftlang/llvm-project
that referenced
this pull request
Feb 25, 2025
…dPtrOrigin. (llvm#111222) Ignore std::forward when it appears while looking for the pointer origin.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ignore std::forward when it appears while looking for the pointer origin.