Skip to content

Commit 31a1d77

Browse files
committed
[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 4b7d2d1 commit 31a1d77

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class RawPtrRefCallArgsChecker
267267
auto *callee = MemberOp->getDirectCallee();
268268
if (auto *calleeDecl = dyn_cast<CXXMethodDecl>(callee)) {
269269
if (const CXXRecordDecl *classDecl = calleeDecl->getParent()) {
270-
if (isRefCounted(classDecl))
270+
if (isSafePtr(classDecl))
271271
return true;
272272
}
273273
}

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

Lines changed: 14 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ void foo() {
270270
}
271271
}
272272

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

0 commit comments

Comments
 (0)