Skip to content

[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

Merged
Merged
Show file tree
Hide file tree
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
Expand Up @@ -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;
}
}
Expand Down
18 changes: 14 additions & 4 deletions clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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 {

Expand All @@ -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() {
Expand All @@ -44,3 +44,13 @@ void foo() {
}

}

namespace call_args_checked_assignment {

CheckedObj* provide();
void foo() {
CheckedPtr<CheckedObj> ptr;
ptr = provide();
}

}
2 changes: 1 addition & 1 deletion clang/test/Analysis/Checkers/WebKit/mock-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};

Expand Down
6 changes: 1 addition & 5 deletions clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down