[clang] [alpha.webkit.UncheckedCallArgsChecker] Forwarding r-value reference should not result in a warning (PR #142471)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 2 13:02:26 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Ryosuke Niwa (rniwa)
<details>
<summary>Changes</summary>
This PR fixes the bug that the checker emits a warning when a function takes T&& and passes it to another function using std::move. We should treat std::move like any other pointer conversion and the origin of the pointer to be that of the argument.
---
Full diff: https://github.com/llvm/llvm-project/pull/142471.diff
2 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+5)
- (modified) clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp (+23)
``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index f087fc8fa19fd..7dedb8f8f6766 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -118,6 +118,11 @@ bool tryToFindPtrOrigin(
}
}
}
+
+ if (call->isCallToStdMove() && call->getNumArgs() == 1) {
+ E = call->getArg(0)->IgnoreParenCasts();
+ continue;
+ }
if (auto *callee = call->getDirectCallee()) {
if (isCtorOfSafePtr(callee)) {
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp b/clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp
index e24b04dcd3cf9..c938ba5f7de46 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp
@@ -2,6 +2,20 @@
#include "mock-types.h"
+namespace std {
+
+template <typename T> struct remove_reference {
+ typedef T type;
+};
+
+template <typename T> struct remove_reference<T&> {
+ typedef T type;
+};
+
+template<typename T> typename remove_reference<T>::type&& move(T&& t);
+
+} // namespace std
+
RefCountableAndCheckable* makeObj();
CheckedRef<RefCountableAndCheckable> makeObjChecked();
void someFunction(RefCountableAndCheckable*);
@@ -54,3 +68,12 @@ void foo() {
}
}
+
+namespace call_with_std_move {
+
+void consume(CheckedObj&&);
+void foo(CheckedObj&& obj) {
+ consume(std::move(obj));
+}
+
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/142471
More information about the cfe-commits
mailing list