Skip to content

Commit e179bbe

Browse files
committed
Ignore assignment to Ref / RefPtr in alpha.webkit.UncountedCallArgsChecker.
1 parent a3c6875 commit e179bbe

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ class UncountedCallArgsChecker
126126
// of object on LHS.
127127
if (auto *MemberOp = dyn_cast<CXXOperatorCallExpr>(CE)) {
128128
// Note: assignemnt to built-in type isn't derived from CallExpr.
129+
if (MemberOp->getOperator() ==
130+
OO_Equal) { // Ignore assignment to Ref/RefPtr.
131+
auto *callee = MemberOp->getDirectCallee();
132+
if (auto *calleeDecl = dyn_cast<CXXMethodDecl>(callee)) {
133+
if (const CXXRecordDecl *classDecl = calleeDecl->getParent()) {
134+
if (isRefCounted(classDecl))
135+
return true;
136+
}
137+
}
138+
}
129139
if (MemberOp->isAssignmentOp())
130140
return false;
131141
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2+
// expected-no-diagnostics
3+
4+
template<typename T>
5+
class RefPtr {
6+
public:
7+
inline constexpr RefPtr() : m_ptr(nullptr) { }
8+
inline RefPtr(T* ptr)
9+
: m_ptr(ptr)
10+
{
11+
if (m_ptr)
12+
m_ptr->ref();
13+
}
14+
15+
inline RefPtr(const RefPtr& o)
16+
: m_ptr(o.m_ptr)
17+
{
18+
if (m_ptr)
19+
m_ptr->ref();
20+
}
21+
22+
inline ~RefPtr()
23+
{
24+
if (m_ptr)
25+
m_ptr->deref();
26+
}
27+
28+
inline T* operator->() const { return m_ptr; }
29+
explicit operator bool() const { return m_ptr; }
30+
31+
RefPtr& operator=(const RefPtr&);
32+
RefPtr& operator=(T*);
33+
34+
private:
35+
T* m_ptr;
36+
};
37+
38+
template<typename T>
39+
inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr& o)
40+
{
41+
if (m_ptr)
42+
m_ptr->deref();
43+
m_ptr = o.m_ptr;
44+
if (m_ptr)
45+
m_ptr->ref();
46+
return *this;
47+
}
48+
49+
template<typename T>
50+
inline RefPtr<T>& RefPtr<T>::operator=(T* optr)
51+
{
52+
if (m_ptr)
53+
m_ptr->deref();
54+
m_ptr = optr;
55+
if (m_ptr)
56+
m_ptr->ref();
57+
return *this;
58+
}
59+
60+
class Node {
61+
public:
62+
Node* nextSibling() const;
63+
64+
void ref() const;
65+
void deref() const;
66+
};
67+
68+
static void removeDetachedChildren(Node* firstChild)
69+
{
70+
for (RefPtr child = firstChild; child; child = child->nextSibling());
71+
}

0 commit comments

Comments
 (0)