[clang] [alpha.webkit.UncountedCallArgsChecker] Skip std::forward in tryToFindPtrOrigin. (PR #111222)
Ryosuke Niwa via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 17:45:44 PDT 2024
https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/111222
Ignore std::forward when it appears while looking for the pointer origin.
>From a67655fa83adab03351aa02d0982dd6a20726939 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Fri, 4 Oct 2024 17:44:11 -0700
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Skip std::forward in
tryToFindPtrOrigin.
Ignore std::forward when it appears while looking for the pointer origin.
---
.../StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp | 5 +++++
.../Checkers/WebKit/uncounted-obj-arg.cpp | 15 +++++++++++++++
2 files changed, 20 insertions(+)
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
}
};
More information about the cfe-commits
mailing list