Skip to content

[webkit.UncountedLambdaCapturesChecker] Fix a regression that [[noescape]] on a member function no longer works. #126016

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
Feb 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -109,9 +109,7 @@ class UncountedLambdaCapturesChecker
bool VisitCallExpr(CallExpr *CE) override {
checkCalleeLambda(CE);
if (auto *Callee = CE->getDirectCallee()) {
unsigned ArgIndex = 0;
if (auto *CXXCallee = dyn_cast<CXXMethodDecl>(Callee))
ArgIndex = CXXCallee->isInstance();
unsigned ArgIndex = isa<CXXOperatorCallExpr>(CE);
bool TreatAllArgsAsNoEscape = shouldTreatAllArgAsNoEscape(Callee);
for (auto *Param : Callee->parameters()) {
if (ArgIndex >= CE->getNumArgs())
31 changes: 31 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
Original file line number Diff line number Diff line change
@@ -63,6 +63,19 @@ template<typename Out, typename... In> Function<Out(In...)> adopt(Detail::Callab
return Function<Out(In...)>(impl, Function<Out(In...)>::Adopt);
}

template <typename KeyType, typename ValueType>
class HashMap {
public:
HashMap();
HashMap([[clang::noescape]] const Function<ValueType()>&);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also have a similar test case for a non-member function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A good point! Added a test case for static function & non-member function.

void ensure(const KeyType&, [[clang::noescape]] const Function<ValueType()>&);
bool operator+([[clang::noescape]] const Function<ValueType()>&) const;
static void ifAny(HashMap, [[clang::noescape]] const Function<bool(ValueType)>&);

private:
ValueType* m_table { nullptr };
};

} // namespace WTF

struct A {
@@ -268,6 +281,24 @@ struct RefCountableWithLambdaCapturingThis {
nonTrivial();
});
}

static void callLambda([[clang::noescape]] const WTF::Function<RefPtr<RefCountable>()>&);
void method_captures_this_in_template_method() {
RefCountable* obj = make_obj();
WTF::HashMap<int, RefPtr<RefCountable>> nextMap;
nextMap.ensure(3, [&] {
return obj->next();
});
nextMap+[&] {
return obj->next();
};
WTF::HashMap<int, RefPtr<RefCountable>>::ifAny(nextMap, [&](auto& item) -> bool {
return item->next() && obj->next();
});
callLambda([&]() -> RefPtr<RefCountable> {
return obj->next();
});
}
};

struct NonRefCountableWithLambdaCapturingThis {