Skip to content

[alpha.webkit.UncheckedCallArgsChecker] Forwarding r-value reference should not result in a warning #142471

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
merged 2 commits into from
Jun 6, 2025

Conversation

rniwa
Copy link
Contributor

@rniwa rniwa commented Jun 2, 2025

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.

…should not result in a warning

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.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Jun 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 2, 2025

@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)

Changes

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 --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));
+}
+
+}

Copy link

github-actions bot commented Jun 2, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@ziqingluo-90 ziqingluo-90 self-assigned this Jun 6, 2025
Copy link
Contributor

@ziqingluo-90 ziqingluo-90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty straightforward to me.

@rniwa
Copy link
Contributor Author

rniwa commented Jun 6, 2025

Thanks for the review!

@rniwa rniwa merged commit 7809b14 into llvm:main Jun 6, 2025
11 checks passed
@rniwa rniwa deleted the fix-webkit-forward-std-move branch June 6, 2025 13:49
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 6, 2025

LLVM Buildbot has detected a new failure on builder lldb-x86_64-debian running on lldb-x86_64-debian while building clang at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/162/builds/24009

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Lua/lua-python.test (2983 of 2994)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Python/Crashlog/text.test (2984 of 2994)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Lua/bindings.test (2985 of 2994)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Lua/breakpoint_function_callback.test (2986 of 2994)
UNSUPPORTED: lldb-shell :: SymbolFile/PDB/compilands.test (2987 of 2994)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Lua/convenience_variables.test (2988 of 2994)
UNSUPPORTED: lldb-shell :: Expr/TestObjCIDCast.test (2989 of 2994)
PASS: lldb-api :: tools/lldb-server/TestLldbGdbServer.py (2990 of 2994)
PASS: lldb-api :: terminal/TestEditlineCompletions.py (2991 of 2994)
UNRESOLVED: lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py (2992 of 2994)
******************** TEST 'lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py' FAILED ********************
Script:
--
/usr/bin/python3 /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./lib --env LLVM_INCLUDE_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/include --env LLVM_TOOLS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./bin --arch x86_64 --build-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex --lldb-module-cache-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/lldb --compiler /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/clang --dsymutil /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/worker/2.0.1/lldb-x86_64-debian/build/./bin --lldb-obj-root /home/worker/2.0.1/lldb-x86_64-debian/build/tools/lldb --lldb-libs-dir /home/worker/2.0.1/lldb-x86_64-debian/build/./lib --cmake-build-type Release -t /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/tools/lldb-dap/launch -p TestDAP_launch.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 7809b147fa52ca4afd5e1aebd1c5cc7559b820c5)
  clang revision 7809b147fa52ca4afd5e1aebd1c5cc7559b820c5
  llvm revision 7809b147fa52ca4afd5e1aebd1c5cc7559b820c5
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
Change dir to: /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/tools/lldb-dap/launch
runCmd: settings clear --all

output: 

runCmd: settings set symbols.enable-external-lookup false

output: 

runCmd: settings set target.inherit-tcc true

output: 

runCmd: settings set target.disable-aslr false

output: 

runCmd: settings set target.detach-on-error false

output: 

runCmd: settings set target.auto-apply-fixits false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants