Skip to content

Commit 35d8ed8

Browse files
committed
[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 94af371 commit 35d8ed8

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
@@ -120,6 +120,11 @@ bool tryToFindPtrOrigin(
120120
}
121121
}
122122

123+
if (call->isCallToStdMove() && call->getNumArgs() == 1) {
124+
E = call->getArg(0)->IgnoreParenCasts();
125+
continue;
126+
}
127+
123128
if (auto *callee = call->getDirectCallee()) {
124129
if (isCtorOfSafePtr(callee)) {
125130
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)