Skip to content

Commit 42ea00b

Browse files
rniwatomtor
authored andcommitted
[alpha.webkit.UncheckedCallArgsChecker] Forwarding r-value reference should not result in a warning (llvm#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.
1 parent 977b555 commit 42ea00b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ bool tryToFindPtrOrigin(
119119
}
120120
}
121121

122+
if (call->isCallToStdMove() && call->getNumArgs() == 1) {
123+
E = call->getArg(0)->IgnoreParenCasts();
124+
continue;
125+
}
126+
122127
if (auto *callee = call->getDirectCallee()) {
123128
if (isCtorOfSafePtr(callee)) {
124129
if (StopAtFirstRefCountedObj)

clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
#include "mock-types.h"
44

5+
namespace std {
6+
7+
template <typename T> struct remove_reference {
8+
typedef T type;
9+
};
10+
11+
template <typename T> struct remove_reference<T&> {
12+
typedef T type;
13+
};
14+
15+
template<typename T> typename remove_reference<T>::type&& move(T&& t);
16+
17+
} // namespace std
18+
519
RefCountableAndCheckable* makeObj();
620
CheckedRef<RefCountableAndCheckable> makeObjChecked();
721
void someFunction(RefCountableAndCheckable*);
@@ -54,3 +68,12 @@ void foo() {
5468
}
5569

5670
}
71+
72+
namespace call_with_std_move {
73+
74+
void consume(CheckedObj&&);
75+
void foo(CheckedObj&& obj) {
76+
consume(std::move(obj));
77+
}
78+
79+
}

0 commit comments

Comments
 (0)