[clang] [alpha.webkit.UncountedCallArgsChecker] Skip std::forward in tryToFindPtrOrigin. (PR #111222)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 17:46:14 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Ryosuke Niwa (rniwa)
<details>
<summary>Changes</summary>
Ignore 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:
- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+5)
- (modified) clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp (+15)
``````````diff
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 at -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 at -1{{Call argument for 'this' parameter is uncounted and unsafe}}
+ callSetField(getFieldTrivial(), refCountedObj()); // no-warning
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/111222
More information about the cfe-commits
mailing list