Skip to content

Commit 54a6bde

Browse files
rniwavar-const
authored andcommitted
[alpha.webkit.UnretainedCallArgsChecker] Don't emit a warning for RetainPtr::operator= (llvm#135526)
Generalize the check for operator= so that it works for RetainPtr and CheckedPtr instead of just RefPtr.
1 parent 0b4b0d9 commit 54a6bde

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class RawPtrRefCallArgsChecker
264264
auto *callee = MemberOp->getDirectCallee();
265265
if (auto *calleeDecl = dyn_cast<CXXMethodDecl>(callee)) {
266266
if (const CXXRecordDecl *classDecl = calleeDecl->getParent()) {
267-
if (isRefCounted(classDecl))
267+
if (isSafePtr(classDecl))
268268
return true;
269269
}
270270
}

clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncheckedCallArgsChecker -verify %s
22

33
#include "mock-types.h"
44

@@ -10,10 +10,10 @@ namespace call_args_unchecked_uncounted {
1010

1111
static void foo() {
1212
someFunction(makeObj());
13-
// expected-warning@-1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
13+
// expected-warning@-1{{Call argument is unchecked and unsafe [alpha.webkit.UncheckedCallArgsChecker]}}
1414
}
1515

16-
} // namespace call_args_checked
16+
} // namespace call_args_unchecked_uncounted
1717

1818
namespace call_args_checked {
1919

@@ -35,7 +35,7 @@ static void baz() {
3535
namespace call_args_default {
3636

3737
void someFunction(RefCountableAndCheckable* = makeObj());
38-
// expected-warning@-1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
38+
// expected-warning@-1{{Call argument is unchecked and unsafe [alpha.webkit.UncheckedCallArgsChecker]}}
3939
void otherFunction(RefCountableAndCheckable* = makeObjChecked().ptr());
4040

4141
void foo() {
@@ -44,3 +44,13 @@ void foo() {
4444
}
4545

4646
}
47+
48+
namespace call_args_checked_assignment {
49+
50+
CheckedObj* provide();
51+
void foo() {
52+
CheckedPtr<CheckedObj> ptr;
53+
ptr = provide();
54+
}
55+
56+
}

clang/test/Analysis/Checkers/WebKit/mock-types.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ template <typename T> struct CheckedPtr {
249249
T *get() const { return t; }
250250
T *operator->() const { return t; }
251251
T &operator*() const { return *t; }
252-
CheckedPtr &operator=(T *) { return *this; }
252+
CheckedPtr &operator=(T *);
253253
operator bool() const { return t; }
254254
};
255255

clang/test/Analysis/Checkers/WebKit/objc-mock-types.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,7 @@ template <typename T> struct RetainPtr {
216216
PtrType get() const { return t; }
217217
PtrType operator->() const { return t; }
218218
T &operator*() const { return *t; }
219-
RetainPtr &operator=(PtrType t) {
220-
RetainPtr o(t);
221-
swap(o);
222-
return *this;
223-
}
219+
RetainPtr &operator=(PtrType t);
224220
PtrType leakRef()
225221
{
226222
PtrType s = t;

clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm

+10
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ void foo() {
271271
}
272272
}
273273

274+
namespace cxx_assignment_op {
275+
276+
SomeObj* provide();
277+
void foo() {
278+
RetainPtr<SomeObj> ptr;
279+
ptr = provide();
280+
}
281+
282+
}
283+
274284
namespace call_with_ptr_on_ref {
275285
RetainPtr<SomeObj> provideProtected();
276286
RetainPtr<CFMutableArrayRef> provideProtectedCF();

0 commit comments

Comments
 (0)