From 7809b147fa52ca4afd5e1aebd1c5cc7559b820c5 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Fri, 6 Jun 2025 07:49:38 -0600 Subject: [PATCH] [alpha.webkit.UncheckedCallArgsChecker] Forwarding r-value reference should not result in a warning (#142471) 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. --- .../Checkers/WebKit/ASTUtils.cpp | 5 ++++ .../Checkers/WebKit/call-args-checked.cpp | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index f087fc8fa19f..81fca5d719b4 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -119,6 +119,11 @@ bool tryToFindPtrOrigin( } } + if (call->isCallToStdMove() && call->getNumArgs() == 1) { + E = call->getArg(0)->IgnoreParenCasts(); + continue; + } + if (auto *callee = call->getDirectCallee()) { if (isCtorOfSafePtr(callee)) { if (StopAtFirstRefCountedObj) diff --git a/clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp b/clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp index e24b04dcd3cf..c938ba5f7de4 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 struct remove_reference { + typedef T type; +}; + +template struct remove_reference { + typedef T type; +}; + +template typename remove_reference::type&& move(T&& t); + +} // namespace std + RefCountableAndCheckable* makeObj(); CheckedRef 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)); +} + +}