-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[alpha.webkit.UnretainedCallArgsChecker] Don't emit a warning for RetainPtr::operator= #135526
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
[alpha.webkit.UnretainedCallArgsChecker] Don't emit a warning for RetainPtr::operator= #135526
Conversation
…ainPtr::operator= Generalize the check for operator= so that it works for RetainPtr and CheckedPtr instead of just RefPtr.
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesGeneralize the check for operator= so that it works for RetainPtr and CheckedPtr instead of just RefPtr. Full diff: https://github.com/llvm/llvm-project/pull/135526.diff 5 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
index 20f7e9703c67c..51353d5acbae2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
@@ -264,7 +264,7 @@ class RawPtrRefCallArgsChecker
auto *callee = MemberOp->getDirectCallee();
if (auto *calleeDecl = dyn_cast<CXXMethodDecl>(callee)) {
if (const CXXRecordDecl *classDecl = calleeDecl->getParent()) {
- if (isRefCounted(classDecl))
+ if (isSafePtr(classDecl))
return true;
}
}
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp b/clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp
index 49b6bfcd7cadf..e24b04dcd3cf9 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncheckedCallArgsChecker -verify %s
#include "mock-types.h"
@@ -10,10 +10,10 @@ namespace call_args_unchecked_uncounted {
static void foo() {
someFunction(makeObj());
- // expected-warning@-1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
+ // expected-warning@-1{{Call argument is unchecked and unsafe [alpha.webkit.UncheckedCallArgsChecker]}}
}
-} // namespace call_args_checked
+} // namespace call_args_unchecked_uncounted
namespace call_args_checked {
@@ -35,7 +35,7 @@ static void baz() {
namespace call_args_default {
void someFunction(RefCountableAndCheckable* = makeObj());
-// expected-warning@-1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
+// expected-warning@-1{{Call argument is unchecked and unsafe [alpha.webkit.UncheckedCallArgsChecker]}}
void otherFunction(RefCountableAndCheckable* = makeObjChecked().ptr());
void foo() {
@@ -44,3 +44,13 @@ void foo() {
}
}
+
+namespace call_args_checked_assignment {
+
+CheckedObj* provide();
+void foo() {
+ CheckedPtr<CheckedObj> ptr;
+ ptr = provide();
+}
+
+}
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h b/clang/test/Analysis/Checkers/WebKit/mock-types.h
index a1f0cc8b046b9..a03d31870ee0d 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h
@@ -249,7 +249,7 @@ template <typename T> struct CheckedPtr {
T *get() const { return t; }
T *operator->() const { return t; }
T &operator*() const { return *t; }
- CheckedPtr &operator=(T *) { return *this; }
+ CheckedPtr &operator=(T *);
operator bool() const { return t; }
};
diff --git a/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h b/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
index 3f075ca0a6e5b..51de81ac0f033 100644
--- a/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
@@ -216,11 +216,7 @@ template <typename T> struct RetainPtr {
PtrType get() const { return t; }
PtrType operator->() const { return t; }
T &operator*() const { return *t; }
- RetainPtr &operator=(PtrType t) {
- RetainPtr o(t);
- swap(o);
- return *this;
- }
+ RetainPtr &operator=(PtrType t);
PtrType leakRef()
{
PtrType s = t;
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
index dd21864300387..0667e4964f1a8 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
@@ -271,6 +271,16 @@ void foo() {
}
}
+namespace cxx_assignment_op {
+
+ SomeObj* provide();
+ void foo() {
+ RetainPtr<SomeObj> ptr;
+ ptr = provide();
+ }
+
+}
+
namespace call_with_ptr_on_ref {
RetainPtr<SomeObj> provideProtected();
RetainPtr<CFMutableArrayRef> provideProtectedCF();
|
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!
Thanks for the review! |
…ainPtr::operator= (llvm#135526) Generalize the check for operator= so that it works for RetainPtr and CheckedPtr instead of just RefPtr.
…ainPtr::operator= (llvm#135526) Generalize the check for operator= so that it works for RetainPtr and CheckedPtr instead of just RefPtr.
…ainPtr::operator= (llvm#135526) Generalize the check for operator= so that it works for RetainPtr and CheckedPtr instead of just RefPtr.
Generalize the check for operator= so that it works for RetainPtr and CheckedPtr instead of just RefPtr.