Skip to content

Commit 6f50849

Browse files
authored
[webkit.UncountedLambdaCapturesChecker] Fix a regression that [[noescape]] on a member function no longer works. (#126016)
1 parent d8e0b13 commit 6f50849

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ 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+
static void ifAny(HashMap, [[clang::noescape]] const Function<bool(ValueType)>&);
74+
75+
private:
76+
ValueType* m_table { nullptr };
77+
};
78+
6679
} // namespace WTF
6780

6881
struct A {
@@ -268,6 +281,24 @@ struct RefCountableWithLambdaCapturingThis {
268281
nonTrivial();
269282
});
270283
}
284+
285+
static void callLambda([[clang::noescape]] const WTF::Function<RefPtr<RefCountable>()>&);
286+
void method_captures_this_in_template_method() {
287+
RefCountable* obj = make_obj();
288+
WTF::HashMap<int, RefPtr<RefCountable>> nextMap;
289+
nextMap.ensure(3, [&] {
290+
return obj->next();
291+
});
292+
nextMap+[&] {
293+
return obj->next();
294+
};
295+
WTF::HashMap<int, RefPtr<RefCountable>>::ifAny(nextMap, [&](auto& item) -> bool {
296+
return item->next() && obj->next();
297+
});
298+
callLambda([&]() -> RefPtr<RefCountable> {
299+
return obj->next();
300+
});
301+
}
271302
};
272303

273304
struct NonRefCountableWithLambdaCapturingThis {

0 commit comments

Comments
 (0)