-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[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
Conversation
…ape]] on a member function no longer works. We should skip the first argument for CXXOperatorCallExpr, not other kinds of calls.
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesWe should skip the first argument for CXXOperatorCallExpr, not other kinds of calls. Full diff: https://github.com/llvm/llvm-project/pull/126016.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index 53ef423bd82e7e2..a56f48c83c660a9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -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())
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
index 2a1a164557cdbe7..b6e84769fdf7247 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
@@ -63,6 +63,18 @@ 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()>&);
+ void ensure(const KeyType&, [[clang::noescape]] const Function<ValueType()>&);
+ bool operator+([[clang::noescape]] const Function<ValueType()>&) const;
+
+private:
+ ValueType* m_table { nullptr };
+};
+
} // namespace WTF
struct A {
@@ -268,6 +280,17 @@ struct RefCountableWithLambdaCapturingThis {
nonTrivial();
});
}
+
+ 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();
+ };
+ }
};
struct NonRefCountableWithLambdaCapturingThis {
|
class HashMap { | ||
public: | ||
HashMap(); | ||
HashMap([[clang::noescape]] const Function<ValueType()>&); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…and a non-member function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/81/builds/4482 Here is the relevant piece of the build log for the reference
|
…ape]] on a member function no longer works. (llvm#126016)
…ape]] on a member function no longer works. (llvm#126016)
…ape]] on a member function no longer works. (llvm#126016)
We should skip the first argument for CXXOperatorCallExpr, not other kinds of calls.