Skip to content

Commit b4c9048

Browse files
committed
[webkit.UncountedLambdaCapturesChecker] Fix a regression that [[noescape]] on a member function no longer works.
We should skip the first argument for CXXOperatorCallExpr, not other kinds of calls.
1 parent 137c378 commit b4c9048

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ class UncountedLambdaCapturesChecker
109109
bool VisitCallExpr(CallExpr *CE) override {
110110
checkCalleeLambda(CE);
111111
if (auto *Callee = CE->getDirectCallee()) {
112-
unsigned ArgIndex = 0;
113-
if (auto *CXXCallee = dyn_cast<CXXMethodDecl>(Callee))
114-
ArgIndex = CXXCallee->isInstance();
112+
unsigned ArgIndex = isa<CXXOperatorCallExpr>(CE);
115113
bool TreatAllArgsAsNoEscape = shouldTreatAllArgAsNoEscape(Callee);
116114
for (auto *Param : Callee->parameters()) {
117115
if (ArgIndex >= CE->getNumArgs())

clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ template<typename Out, typename... In> Function<Out(In...)> adopt(Detail::Callab
6363
return Function<Out(In...)>(impl, Function<Out(In...)>::Adopt);
6464
}
6565

66+
template <typename KeyType, typename ValueType>
67+
class HashMap {
68+
public:
69+
HashMap();
70+
HashMap([[clang::noescape]] const Function<ValueType()>&);
71+
void ensure(const KeyType&, [[clang::noescape]] const Function<ValueType()>&);
72+
bool operator+([[clang::noescape]] const Function<ValueType()>&) const;
73+
74+
private:
75+
ValueType* m_table { nullptr };
76+
};
77+
6678
} // namespace WTF
6779

6880
struct A {
@@ -268,6 +280,17 @@ struct RefCountableWithLambdaCapturingThis {
268280
nonTrivial();
269281
});
270282
}
283+
284+
void method_captures_this_in_template_method() {
285+
RefCountable* obj = make_obj();
286+
WTF::HashMap<int, RefPtr<RefCountable>> nextMap;
287+
nextMap.ensure(3, [&] {
288+
return obj->next();
289+
});
290+
nextMap+[&] {
291+
return obj->next();
292+
};
293+
}
271294
};
272295

273296
struct NonRefCountableWithLambdaCapturingThis {

0 commit comments

Comments
 (0)